var arrAds=elm("header").getElementsByTagName("div")[0].getElementsByTagName("div");
var arrBullets=elm("header").getElementsByTagName("ul")[0].getElementsByTagName("a");
var elmBullet;
var elmLink=arrAds[0];
var intAd=0;
var intDown=elmLink.offsetHeight;
var intEnd=0;
var intSlide=1;
var intSpeed=49;
//var intUp=intDown-elm("featured").offsetHeight;
//elm("featured").style.top=intDown+"px";

function childindex(itm){
	var intIndex=0;
	while(itm.previousSibling){
		intIndex++;
		itm=itm.previousSibling;
	}
	return intIndex;
};
function slideshow(){
	var img;
	var bolStop=0;
	if(arguments.length>0){
		img=arguments[0];
		bolStop=1;
	}else{
		img=intAd+1;
		if(img==arrBullets.length)img=0;
	}
	if(img!=intAd){
		if(bolStop){
			clearInterval(objClock);
			objClock=0;
		}
		if(arrMoving[3]){
			clearInterval(arrTimers[3]);
			clearInterval(arrTimers[4]);
			clearInterval(arrTimers[5]);
		}
		intEnd=-343*img;
		if(intEnd<parseInt(arrAds[0].style.top))intSlide=-1;
		else intSlide=1;
		intSpeed=49*(intAd-img);
		if(intSpeed<0)intSpeed=-intSpeed;
		for(var x=0;x<arrBullets.length;x++){
			elmBullet=arrBullets[x];
			elmBullet.style.background="#000";
			elmBullet.style.color="#fff";
			move(arrAds[x].id,intSlide,intEnd+(343*x),intEnd+(343*x),3+x,49);
		}
		elmBullet=arrBullets[img];
		elmBullet.style.background="#f29100";
		elmBullet.style.color="#000";
		intAd=img;
		if(!objClock)objClock=setInterval("slideshow()",5000);
	}
	return false;
};

var objClock=setInterval("slideshow()",5000);
for(var x=0;x<arrBullets.length;x++){
	elmBullet=arrBullets[x];
	elmBullet.setAttribute("href","#himage"+(x+1));
	elmBullet.setAttribute("title",arrBullets[x].innerHTML);
	elmBullet.innerHTML=x+1;
	arrAds[x].style.top=x*343+"px";
	bolEvents?elmBullet.addEventListener("click",function(event){slideshow(childindex(this.parentNode));event.preventDefault();},false):elmBullet.onclick=function(){return slideshow(childindex(this.parentNode));};
};
//bolEvents?elmLink.addEventListener("mouseout",function(){move("featured",1,intDown,intUp,1,2)},false):elmLink.onmouseout=function(){move("featured",1,intDown,intUp,1,2);};
//bolEvents?elmLink.addEventListener("mouseover",function(){move("featured",-1,intDown,intUp,1,2)},false):elmLink.onmouseover=function(){move("featured",-1,intDown,intUp,1,2);};
