// JScript File

var element;
var theImages;
var theStart=0;
var theNextAnchor;
var upOpacity = 0;
var downOpacity = 100;
var fadeInc = 20;
var fadeTimer;
var nextHeroTimer;

function showThisHero(theAnchor){
 window.clearTimeout(nextHeroTimer);
 var theContainer=theAnchor.parentNode.parentNode.parentNode;
 var theAnchors=theAnchor.parentNode.getElementsByTagName('a');
 theImages=theContainer.getElementsByTagName('img');
 var theTitles=theContainer.getElementsByTagName('h4');
 var theTexts=theContainer.getElementsByTagName('p');
 var theLearnMores=theAnchor.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('a');
 if (theAnchor.className.indexOf('on')==-1 && fadeTimer==null){
 for (x=0; x<theAnchors.length; x++){
 if (theAnchor != theAnchors[x]){
 theAnchors[x].className=theAnchors[x].className.replace(/on/, "");
 theTitles[x].style.display="none";
 theTexts[x].style.display="none";
 theLearnMores[x].style.display="none";

 } else {
 theAnchors[x].className=theAnchors[x].className+"on";
 theTitles[x].style.display="block";
 theTexts[x].style.display="block";
 theLearnMores[x].style.display="block";
 element=theImages[x];
 if (x==theAnchors.length-1){
 theNextAnchor=theAnchors[0];
 } else {
 theNextAnchor=theAnchors[x+1];
 }
 }
 }
 fadeImages();
 }
}

function fadeImages(){
 if (fadeTimer) {
 window.clearTimeout(fadeTimer);
 }
 if (nextHeroTimer) {
 window.clearTimeout(fadeTimer);
 }
 if (upOpacity <= 100){
 for (x=0; x<theImages.length; x++){
 if (theImages[x]==element){
 element.style.display="block";
 if (navigator.appName.indexOf("Microsoft")!= -1 && parseInt(navigator.appVersion)>=4) {
 element.filters.alpha.opacity=upOpacity;
 } else {
 element.style.opacity=upOpacity/100;
 }
 } else if (theImages[x].src!=""){
 if (navigator.appName.indexOf("Microsoft")!= -1 && parseInt(navigator.appVersion)>=4 && theImages[x].filters.alpha.opacity!=0) {
 theImages[x].filters.alpha.opacity=downOpacity;
 } else if (theImages[x].style.opacity!=0){
 theImages[x].style.opacity=downOpacity/100;
 }
 if (downOpacity==0){
 theImages[x].style.display="none";
 }
 }
 }
 upOpacity=upOpacity + fadeInc;
 downOpacity=downOpacity - fadeInc;
 fadeTimer=window.setTimeout("fadeImages()", 100);
 } else {
 upOpacity = 0;
 downOpacity = 100;
 window.clearTimeout(fadeTimer);
 fadeTimer=null;
 nextHeroTimer=window.setTimeout("showNextHero()", 8000);
 }
}

function clearPage(){
 window.clearTimeout(fadeTimer);
 window.clearTimeout(nextHeroTimer);
}

function showNextHero(){
 showThisHero(theNextAnchor)
}

function initHero(){
 theNextAnchor=document.getElementById('heroContainer').getElementsByTagName('a')[1];
 nextHeroTimer=window.setTimeout("showNextHero()", 8000);
}

window.unload=clearPage;
window.onload=initHero; 
