/*****

Image Cross Fade Redux
Version 1.0
Last revision: 02.15.2006
steve@slayeroffice.com

Please leave this notice intact. 

Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html


*****/
  function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }



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,first=false;

function so_init() {
	if(!d.getElementById || !d.createElement) return;
	/*
	css = d.createElement("link");
	css.setAttribute("href",xfade_name);
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	d.getElementsByTagName("head")[0].appendChild(css);
	*/
	
	imgs = d.getElementById("XimageContainer").getElementsByTagName("img");

	xinitial=0;
	yinitial=0;

	for(i=0;i<imgs.length-1;i++) {
		x=(findPosY(imgs[i]));
		if (x<0) {
			var iLen=document.images.length; 
			for(var i=0; i < iLen; i++) {
				var x_src=document.images[i].src;
				if (x_src.indexOf("bigheader-shinylogo-1.png")!=-1) {
					x_src=x_src.replace(/bigheader-shinylogo-1.png/,"bigheader-shinylogo-2.png");
					x=(findPosX(d.getElementById("XimageContainer")));

					document.images[i].src=x_src;
					return;

				}
					
			
			}
			
			}
		pic1=new Image();
		pic1.src=imgs[i].src;

		imgs[i].xOpacity = .01;
                imgs[i].style.opacity = imgs[i].xOpacity;
                imgs[i].style.MozOpacity = imgs[i].xOpacity;
                imgs[i].style.filter = "alpha(opacity=" + (imgs[i].xOpacity*100) + ")";
		}
	$res=(imgs.length)-1;

	current=$res;

	imgs[$res].style.display = "block";
	imgs[$res].xOpacity = .99;
	
	setTimeout(so_xfade,50);
}

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;
		if (first==false) {
		setTimeout(so_xfade,2000);
		}
		else {
		setTimeout(so_xfade,5000);
		}
	} else {
		if (first==false) {
			first=true;
		}
		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) + ")";
	}
	
}
