window.addEventListener?window.addEventListener("load",so_init2,false):window.attachEvent("onload",so_init2);

var d=document, imgs2 = new Array(), zInterval = null, current2=0, pause=false;

var counterValue2 = 0;
var bahTwo2 = true;
function so_init2() {
	if(!d.getElementById || !d.createElement)return;
	
	imgs2 = d.getElementById("cover_2").getElementsByTagName("img");
	for(i=1;i<imgs2.length;i++) imgs2[i].xOpacity2 = 0;
	imgs2[0].style.display = "block";
	imgs2[0].xOpacity2 = .99;
		
	checkHeights2(0);
	
	//setTimeout(so_xfade2,4000);
}

function so_xfade2() {
	cOpacity2 = imgs2[current2].xOpacity2;
	nIndex2 = imgs2[current2+1]?current2+1:0;
	nOpacity2 = imgs2[nIndex2].xOpacity2;
	
	cOpacity2-=.05; 
	nOpacity2+=.05;
	
	imgs2[nIndex2].style.display = "block";
	imgs2[current2].xOpacity2 = cOpacity2;
	imgs2[nIndex2].xOpacity2 = nOpacity2;
	
	setOpacity2(imgs2[current2]); 
	setOpacity2(imgs2[nIndex2]);
	//alert(bahTwo2);
	//alert(bahTwo2);
			
	if(cOpacity2<=0) {
		
		imgs2[current2].style.display = "none";
		current2 = nIndex2;
		
		// check height of image and if falls outside of div then move up.
		x=new Image;
		x.src=imgs2[current2].src;
		
		iw=x.width;
		ih2=x.height;
		ix=imgs2[current2].style.top;
		iy=imgs2[current2].style.left;
		//setTimeout(so_xfade2,4000);
		imgs2[previousImage2].style.top = "0px";
		checkHeights2(0);
		bahTwo2 = true;
		
	} else {
			setTimeout(so_xfade2,50);
			//checkHeights2(0);
	}
	
	function setOpacity2(obj) {
		if(obj.xOpacity2>.99) {
			obj.xOpacity2 = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity2;
		obj.style.MozOpacity = obj.xOpacity2;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity2*100) + ")";
	}
	
}

function checkHeights2(dodis2)
{
	ih2 = imgs2[current2].height;
	
	//alert (current2);
	//if (current2 != 0) {
	//	previous = current2 - 1;
	//	imgs2[previous].style.top = "0px";
	//} 
	if (ih2 > (107+20)) {
		ih2d = ih2 - 107;
	
		//alert(ih2d + ' ' + dodis2);
		if (dodis2 < ih2d) {
			topStr2 = imgs2[current2].style.top;
			pxStart2 = topStr2.indexOf("px");
			topVal2 = topStr2.substring(0,pxStart2);
			//alert(topStr2.substring(0,pxStart2))
			imgs2[current2].style.top = (topVal2 - 1) + "px";
			dodis2 += 1;
			bahTwo2 = false;
			the_timeout2 = setTimeout("checkHeights2("+ dodis2 +");", 50);
		} else {
			bahTwo2 = true;
			//alert("finished panning");
			//alert(current2);
			setTimeout(so_xfade2,4000);
			//checkHeights2(0);
		}
	}
	else {
		setTimeout(so_xfade2,4000);
	}
	previousImage2 = current2;
}

