addLoadEvent(function(){
	fadeInOut('heroHolder', 0, 'in');
	assignRollOver();
}
);

function assignRollOver(){
	var heroLinksDiv = document.getElementById('heroLinks');
	var linkList = heroLinksDiv.getElementsByTagName('a');
	
	for(var j=0; j<linkList.length; j++){
		var thisHero = linkList[j];
		thisHero.num = j + 1;
		thisHero.onmouseover = function(){
			var heros = getElementsByClassName(document, "div","hero");
			var thisFade = document.getElementById('hero'+this.num);
			//cancel the timed animation
			clearTimeout(tFader);
			// reset the zindexes
			resetZindex(heros);
			// set this zindex to the top
			thisFade.style.zIndex = 1;
			// fade in
			opacity(thisFade, 0, 100, 3, 120, 1);
		}
		thisHero.onmouseout = function(){
			// cancel the timed animation
			clearTimeout(tFader);
			var thisFade = document.getElementById('hero'+this.num);
			var thisFadeID = 'hero'+this.num;
			var heros = getElementsByClassName(document, "div","hero");
			//reset the opacity on any mouseout event except for the element itself that you moused out of
			resetOpacity(heros, thisFadeID);
			//fade out
			opacity(thisFade, 100, 0, 3, 120, 1);	
			//start the timed animation
			i = 0;
			tFader = setTimeout("fadeInOut('heroHolder', 0, 'in')", 0);
		}
		thisHero.onmousedown = this.blurLink;
	}
}

var i = 0;
function fadeInOut(containerId, waitTime, direction){
	if (!document.getElementById(containerId)) return;
	var container = document.getElementById(containerId);
	var heros = getElementsByClassName(container, "div","hero");
	resetZindex(heros);
	
	if (direction == 'in'){
		heros[i].style.zIndex = 1;
		opacity(heros[i], 0, 100, 3, 120, 1);	
		tFader = setTimeout("fadeInOut('"+containerId+"','"+waitTime+"','out')", 10000);
	}
	else if (direction == 'out'){
		opacity(heros[i], 100, 0, 8, 140, 1);
		heros[i].style.zIndex = 0;
		i = (i + 1) % heros.length;
		tFader = setTimeout("fadeInOut('"+containerId+"','"+waitTime+"','in')", waitTime);	
	}
	
}
	
function resetZindex(elements){
	for (var i=0; i<elements.length; i++){
		elements[i].style.zIndex = 0;
	}
}
//rests the opacity of elements in an array EXCEPT for notFadeID
function resetOpacity(elements, notFadeID){
	for (var i=0; i<elements.length; i++){
		if (elements[i].getAttribute('id') == notFadeID){
			continue;	
		}
		else{
			elements[i].style.opacity = 0;
			elements[i].style.filter = "alpha(opacity=0)";
		}
	}
}
function opacity(image, opacStart, opacEnd, steps, intervals, powr){
    if (image.fading) window.clearInterval(image.fading);
    var thisStep = 0;
    image.fading = setInterval(fade, intervals);
     function fade(){
            image.currentOpacity =  easeInOut( opacStart, opacEnd, steps, thisStep, powr);
            image.style.opacity = (image.currentOpacity / 100);
            image.style.MozOpacity = (image.currentOpacity / 100);
            image.style.KhtmlOpacity = (image.currentOpacity / 100);
            image.style.filter = "alpha(opacity=" + image.currentOpacity + ")";
            thisStep++;
            if (thisStep > steps) window.clearInterval(image.fading);
     }
     
}
//generic value churner by Hesido (wwww.hesido.com)
function easeInOut( opacStart, opacEnd, steps, thisStep, powr ){
     var NumDifference = opacEnd - opacStart;
     var increaseStepAmt = opacStart + (Math.pow((( 1 / steps ) * thisStep), powr ) * NumDifference );
     return Math.ceil(increaseStepAmt);
}
