
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() 
{
	// Return if required functions do not exist
	if (!d.getElementById || !d.createElement)
		return;
	
	css = d.createElement("link");
	css.setAttribute("href","fade.css");
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	d.getElementsByTagName("head")[0].appendChild(css);
	
	// make sure all images begin at the same position
	imgs = d.getElementById("imageContainer").getElementsByTagName("img");
	for(i=0; i<imgs.length; i++) {
		if (i==0) {
			// set first image to appear
			imgs[i].xOpacity = .99;
			imgs[i].style.display = "block";
		}
		else {
			// all other images
			imgs[i].xOpacity = 0.0;
			imgs[i].style.display = "none";
		}
		imgs[i].style.position = "absolute";
		imgs[i].style.top = "0px";
		imgs[i].style.left = "10px";
	}
        
        if (imgs.length > 0) {
	      setTimeout(so_xfade,1000);
        }
}

var Percent=0;

function so_xfade() 
{
//                  bt21    bt121  words
    var Top0   = [  0,      0,     200,   0        ];
    var Top1   = [  0,      0,     0,     0        ];
    var Top2   = [  45,     0,     0,     0        ];
    
    var Left0  = [  0,      0,     150,   0        ];
    var Left1  = [  0,      0,     0,     0        ];
    var Left2  = [  40,     0,     0,     0        ];
    
    var Width0 = [  280,    280,   5,     280      ];
    var Width1 = [  280,    280,   280,   280      ];
    var Width2 = [  50,     280,   280,   280      ];
    
	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1] ? current+1 : 0;
    
    Percent += .05;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = 1-Percent;
	imgs[nIndex].xOpacity = Percent;
    
    imgs[nIndex].style.top      = Top0[nIndex]      + (Top1[nIndex]  -Top0[nIndex])     * Percent;
    imgs[nIndex].style.left     = Left0[nIndex]     + (Left1[nIndex] -Left0[nIndex])    * Percent;
    imgs[nIndex].style.width    = Width0[nIndex]    + (Width1[nIndex]-Width0[nIndex])   * Percent;
    
    imgs[current].style.top     = Top1[current]     + (Top2[current]  -Top1[current])   * Percent;
    imgs[current].style.left    = Left1[current]    + (Left2[current] -Left1[current])  * Percent;
    imgs[current].style.width   = Width1[current]   + (Width2[current]-Width1[current]) * Percent;
	
	setOpacity(imgs[current]); 
	setOpacity(imgs[nIndex]);
	
	if(Percent>.99) {
		imgs[current].style.display = "none";
		current = nIndex;
		setTimeout(so_xfade,4000);
        Percent = 0;
	} else {
		setTimeout(so_xfade,50);
	}
}


	
function setOpacity(obj) 
{
	if(obj.xOpacity>.99) {
		obj.xOpacity = 1;
		return;
	}
	obj.style.opacity = obj.xOpacity;
	obj.style.MozOpacity = obj.xOpacity;
	obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
}
