
/********** BEGIN HOMEPAGE RANDOMIZATION ********/
// Initalize Homepage Set
var mainIdx = 0;
var promoXML = new Array;
var XMLIndex = 0;
//var whatsNewXML = "/promo/xml/homePageLandingPromo.xml";
var rotTotalWeight = 0;

var startLink="";
var endLink="";

function getElementsByName_ie(tag, name) {
     
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}


/********** END HOMEPAGE RANDOMIZATION ********/
function setHomeTheme () {
var rotArray = getElementsByName_ie("div","vcRot");
//alert(rotArray.length);

for (i=0; i < rotArray.length; i++) // figure out our total weighting, just in case it doesn't add up to 100. 
	{
	//alert(rotTotalWeight);
	rotTotalWeight += +rotArray[i].getAttribute("weight");
	}


// Initialize Random Co-efficient
var randomIdx = Math.random();

// Assign Resulting Value to mainIdx
 mainIdx = Math.floor(randomIdx * rotTotalWeight); // calc up to our total weight
//alert(mainIdx);


/*
above, we random'd a number between 0 and (total weight).
this will loop through and figure out where the randomization landed, and then kick off that image load.
*/

var done = 0;

for (i=0; i < rotArray.length; i++) // figure out our total weighting, just in case it doesn't add up to 100. 
	{
	if ((+$('rot' + i).getAttribute("weight") >= mainIdx) && !done) // it is this one
		{
		if ( $('rot' + i).getAttribute("xmlURL") != "") {
			// whatsNewXML = $('rot' + i).getAttribute("xmlURL");
		}
		/*
		if (AC_FL_RunContent == 0) {
			alert("This page requires AC_RunActiveContent.js. In Flash, run \"Apply Active Content Update\" in the Commands menu to copy AC_RunActiveContent.js to the HTML output folder.");
		}else{
			$("whatsNewDIV").innerHTML= '<!-- // -->';
		}
		*/
		
		$('vcArea').style.backgroundImage = "url('" + $('rot' + i).getAttribute("src") + "')";
		$('mainImageLink').innerHTML = '<a href="' + $('rot' + i).getAttribute("href") + '"><img src="/public/frontend/images/spacer.gif" width="1000" height="445" alt=""></a>';
		document.getElementById("vcArea").style.display="block";
		
		var gifOverlaySRC    = $('rot' + i).getAttribute("givOverlaySRC");
		var gifOverlayURL    = $('rot' + i).getAttribute("gifOverlayURL");
		var gifOverlayTop    = $('rot' + i).getAttribute("gifOverlayTop");
		var gifOverlayLeft   = $('rot' + i).getAttribute("gifOverlayLeft");
		var gifOverlayHeight = $('rot' + i).getAttribute("gifOverlayHeight");
		var gifOverlayWidth  = $('rot' + i).getAttribute("gifOverlayWidth");
		
		if (gifOverlaySRC != "") {
			$('overlayGif').style.top=gifOverlayTop+"px";
			$('overlayGif').style.left=gifOverlayLeft+"px";
			if (gifOverlayURL != ""){
				startLink = "<a href="+gifOverlayURL+">"
				endLink="</a>";
				$('overlayGif').style.zIndex="2020";
			}
			$('overlayGif').style.display="block";
			$('overlayGif').innerHTML=startLink+"<img src=\""+gifOverlaySRC+"\" width=\""+gifOverlayWidth+"\" height=\""+gifOverlayHeight+"\" border=\"0\" />"+endLink;
		}
		
			//Deprecated - sets footer disclaimers to visible
			//if (i != 2){$('ftDisclaimers').style.display="block";}
		
		done = 1;
		
		}
	else // not this one, truncate our idx and loop
		{
		//alert("nomatch");
		mainIdx -= +$('rot' + i).getAttribute("weight");
		}	
	}
	if(!done) // something went wonky, grab the first one
		{
		$('vcArea').style.backgroundImage = "url('" + $('rot0').getAttribute("src") + "')"; 
		$('mainImageLink').innerHTML = '<a href="' + $('rot0').getAttribute("href") + '"><img src="/public/frontend/images/spacer.gif" width="1000" height="445" alt=""></a>'; 
		document.getElementById("vcArea").style.display="block";
	}
}