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

var d=document, imgs = new Array(), zInterval = null, current=0, pause=false;

function so_init() {
	if(!d.getElementById || !d.createElement)return;
	
	imgs = d.getElementById("imageContainer").getElementsByTagName("img");
	for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
	imgs[0].style.display = "block";
	imgs[0].xOpacity = .99;
	
	setTimeout(so_xfade,1000);
}

function so_xfade() {
	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1]?current+1:0;
	nOpacity = imgs[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[current]); 
	setOpacity(imgs[nIndex]);
	
	if(cOpacity<=0) {
		imgs[current].style.display = "none";
		current = nIndex;
		setTimeout(so_xfade,2000);
	} else {
		setTimeout(so_xfade,50);
	}
	
	function setOpacity(obj) {
		if(obj.xOpacity>.99) {
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
	
}

// imgCount = 0;
// height = 250;
// function scrollImage(init) {
// 	
// 	if (imgCount == 0) {
// 		//Just fade in our image if its the first one
// 		Effect.Appear('gallery_image_wrap', {duration: 0.4});
// 		$('gallery_image_wrap').innerHTML = "<img src='/files_archive/"+imgList[imgCount]+"' />";
// 	} else { //Do the crossfade
// 		
// 		new Effect.Parallel(
// 		[ 
// 			new Effect.Fade('gallery_image_wrap', {duration: 0.4, to: 0.01, afterFinish: function(e) { imgCount++; $('gallery_image_crossfade').innerHTML = "<img src='/files_archive/"+imgList[imgCount]+"' />";  }}),
// 			Effect.Appear('gallery_image_crossfade', {duration: 0.4})
// 		]	
// 		)
// 		
// 		
// 	}
// 	
// 	// if (imgCount == imgList.length-1) {
// 	// 	imgCount = 0;
// 	// } else {
// 	// 	imgCount++;
// 	// }
// 	
// 	/* Set our crossfade div top/left dims */
// 	$('gallery_image_crossfade').style.left = $('gallery_image_wrap').offsetLeft+"px";
// 	$('gallery_image_crossfade').style.top = $('gallery_image_wrap').offsetTop+"px";
// 	
// }
// 
// function fade() {
// 	
// }

function setGallHeight(height) {
	
	height += "px";
	Element.setStyle('imageContainer', {height:height} );
	
	var fimg = document.getElementsByName("fimg");
	
	// for (i=0; i<fimg.length;i++) {
	// 	var otop = $('imageContainer').offsetTop;
	// 	var oleft = $('imageContainer').offsetLeft;
	// 	
	// 	
	// 	fimg[i].style.top = otop+"px";
	// 	fimg[i].style.left = oleft+"px";
	// }
	
}