<!-- // setup onload
OnLoad += "initHomeBoxes();rotateHomeImages(1800);";
var imgSeq = 0;

function initHomeBoxes() {
	if ($('homeBoxes')) {
		
		var tdNodes = getElementsByClass('productBox', $('homeBoxes'), 'TD');
		for (var x = 0; x < tdNodes.length; x++) {
			
			var aNode = tdNodes[x].childNodes[0];
			var iNode = aNode.childNodes[0];
			changeProduct(aNode, iNode, x);
		}
	}
	
	// setup start shopping button if exists and there is a nav
	if ($('startShopping')) {
		if ($('sidenav')) {
			var baseURI = document.domain.toLowerCase();
			var aNodes = $('sidenav').getElementsByTagName('A');
			if (aNodes.length == 0) { $('startShopping').href = "/hotitems/"; }
			for (var x = 0; x < aNodes.length; x++) {
				var linkURL = aNodes[x].href.toLowerCase();
				if (linkURL.match(baseURI) && !linkURL.match(baseURI + "/home/") && !linkURL.match(baseURI + "/policies/") && !linkURL.match(baseURI + "/#")) {
					$('startShopping').href = aNodes[x].href;
					break;
				}
				
			}
		} else { $('startShopping').href = "/hotitems/"; }
	}
}
function rotateHomeImages(time) {
	if ($('homeBoxes')) {

		// get box nodes and pick random
		var tdNodes = getElementsByClass('productBox', $('homeBoxes'), 'TD');
		for (var x = 0; x < tdNodes.length; x++) {
			//switchBoxColors(); // switch with no delay
			setTimeout("switchBoxColors()", time * (x+1)); // switch with timed delay
			setTimeout("switchProductImage(" + x + ")", time * (x+1)); // switch with timed delay
		}
		setTimeout("rotateHomeImages(" + time + ")", time * tdNodes.length); // rerun function with max time
	}
	return true;
}
function changeProduct(aNode, iNode, x) {
	if (aNode.nodeName == "A") { aNode.href = "/product/" + eval("imgid" + x) + "/"; }
	if (iNode.nodeName == "IMG") { 
		iNode.src = eval("img" + x + ".src"); 
		iNode.width = eval("img" + x + ".width"); 
		iNode.height = eval("img" + x + ".height"); 
	}
}
function checkProduct(newImg) {
	var tdNodes = getElementsByClass('productBox', $('homeBoxes'), 'TD');
	for (var x = 0; x < tdNodes.length; x++) {
		var aNode = tdNodes[x].childNodes[0];
		if (aNode.href.match(newImg)) {	return false; }
	}
	return true;
}
function switchProductImage(x) {
	// get td node
	var tdNodes = getElementsByClass('productBox', $('homeBoxes'), 'TD');
	var randomBox = tdNodes[x];

	// select a random image
	var randomImg = randomNumber(boxImgs);
	var unique = false; 
	
	// make sure this is unique
	while (!unique) {
		var newImg = "/product/" + eval("imgid" + randomImg) + "/";
		if (!checkProduct(newImg)) { randomImg = randomNumber(boxImgs); } else { unique = true; }
	}
	
	var aNode = randomBox.childNodes[0];
	var iNode = aNode.childNodes[0];
	changeProduct(aNode, iNode, randomImg);
}
function switchBoxColors() {
	var testForBox = getElementsByClass('majorBox', $('homeBoxes'), 'TD');
	if (testForBox) {
		var tdNodes = $('homeBoxes').getElementsByTagName('TD');
		
		// init the first random box
		var first = randomNumber(tdNodes.length);
		while (tdNodes[first].className == "productBox") {
			first = randomNumber(tdNodes.length);
		}
		
		// init the second random box
		// loop until the second number is not equal to the first &&  the colors are different && it's NOT a product box
		var secnd = randomNumber(tdNodes.length);
		while (first == secnd || tdNodes[first].className == tdNodes[secnd].className || tdNodes[secnd].className == "productBox") {
			secnd = randomNumber(tdNodes.length);
		}
		
		// finally do the switch
		var tmp = tdNodes[first].className;
		tdNodes[first].className = tdNodes[secnd].className;
		tdNodes[secnd].className = tmp;
	}
}
function randomNumber(arrayLength) {
	return Math.round(Math.random()*(arrayLength - 1));
}
//-->
