
var d=document, imgs = new Array(), zInterval = null, current=0, nIndex=0, pause=true;

window.addEventListener?window.addEventListener("load",so_init,false):window.attachEvent("onload",so_init);

function so_init() {

    imgs = d.getElementById("project").getElementsByTagName("div");
    
	for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
	if(imgs.length > 0)
	{
	    imgs[0].style.display = "block";
	    imgs[0].xOpacity = .99;
    	
	    if(!pause)
	        setTimeout(so_xfade,1000);
	}
}
function toggleMap()
{
    var project = d.getElementById("project");
    var map = d.getElementById("map");
    
    if(project != null && map != null)
    {
        if(map.style.display == "block") 
        {
            map.style.display = "none";
            GUnload();
        }
        else
        {
            map.style.display = "block";
            load();
         }
    }
}
function increment()
{
    nIndex = imgs[current+1]?current+1:0;
    doTransition(nIndex);
}
function decrement()
{
    //alert(current);
    nIndex = (current==0)?imgs.length-1:current-1;
    //alert(nIndex);
    doTransition(nIndex);
}

function doTransition(nIndex)
{
    var map = d.getElementById("map");
    if(map != null)
    {
        map.style.display = "none";
    }
    cOpacity = imgs[current].xOpacity;
	

	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;
		if(!pause)
		{
		    nIndex = imgs[current+1]?current+1:0;
		    setTimeout(so_xfade,1000);
		 }
	} 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) + ")";
	}
}
		

function so_xfade() {
	
	//
	doTransition(nIndex);
}