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

var curimg=0;
function rotateimages()
{
  document.getElementById("slideshow").setAttribute("src", "mainslideshow/"+galleryarray[curimg]);
  curimg=(curimg<galleryarray.length-1)? curimg+1 : 0;
}

window.onload=function(){
  //setInterval("rotateimages()", 2500)
}

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

function so_init() 
{	
	if(!d.getElementById || !d.createElement)
		return;

	/*
	css = d.createElement("link");	
	css.setAttribute("href","js/xfade2.css");	
	css.setAttribute("rel","stylesheet");	
	css.setAttribute("type","text/css");
	d.getElementsByTagName("head")[0].appendChild(css);
	*/

    var container = d.getElementById("imageContainer");

    for(i=0;i<galleryarray.length;i++)
	{
      container.appendChild(galleryarray[i]);
    }

	gallery = d.getElementById("imageContainer").getElementsByTagName("img");

	for(i=1;i<gallery.length;i++)
		gallery[i].xOpacity = 0;
	gallery[0].style.display = "block";
	gallery[0].xOpacity = .99;	
	setTimeout(so_xfade,interval);
}

function so_xfade()
{	
	cOpacity = gallery[current].xOpacity;
	nIndex = gallery[current+1]?current+1:0;
	nOpacity = gallery[nIndex].xOpacity;
	cOpacity -=.05;
	nOpacity +=.05;
	gallery[nIndex].style.display = "block";	
	gallery[current].xOpacity = cOpacity;
	gallery[nIndex].xOpacity = nOpacity;
	setOpacity(gallery[current]);
	setOpacity(gallery[nIndex]);
	if(cOpacity<=0)
	{
		gallery[current].style.display = "none";
		current = nIndex;
		setTimeout(so_xfade,interval);
	} 
	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) + ")";
	}
    
}
