<!--
// init holder vars for rotating images
var holderOne = 0;
var holderTwo = 1;
var holderThree = 2;

// setup the first three rotating images
function initHomeImages() {

	if (document.getElementById("boxesContainer")) {
		// init images to first three in array
		document['product0'].src = img0.src;
		if (document['product1']) { document['product1'].src = img1.src; }
		if (document['product2']) { document['product2'].src = img2.src; }
		
		// init product links
		document.getElementById("link0").href = "./index.php?section=view_product&product_id=" + imgid0;
		if (document.getElementById("link1")) { document.getElementById("link1").href = "./index.php?section=view_product&product_id=" + imgid1; }
		if (document.getElementById("link2")) { document.getElementById("link2").href = "./index.php?section=view_product&product_id=" + imgid2; }
	}
	return true;
}

// function to rotate home images and switch boxes
function rotateHomeImages(numrows, time, words) {
	var rotateOne = time;
	var rotateTwo = time * 2;
	var rotateThree = time * 3;
	
	if (document.getElementById("boxesContainer")) {
		// change image 1 and switch box colors
		holderOne = checkRandomNumber(randomNumber(numrows), numrows);
		setTimeout('changeProduct(0, holderOne)', time);
		setTimeout('switchBoxColors()', time);
		if (isObject(words)) { setTimeout('switchBoxWords()', time); }
		
		// change image 2 and switch box colors
		holderTwo = checkRandomNumber(randomNumber(numrows), numrows);
		setTimeout('changeProduct(1, holderTwo)', rotateTwo);
		setTimeout('switchBoxColors()', rotateTwo);
		if (isObject(words)) { setTimeout('switchBoxWords()', rotateTwo); }
		
		// change image 3, switch box colors, and call function recusively
		holderThree = checkRandomNumber(randomNumber(numrows), numrows);
		setTimeout('changeProduct(2, holderThree)', rotateThree);
		setTimeout('switchBoxColors()', rotateThree);
		if (isObject(words)) { setTimeout('switchBoxWords()', rotateThree); }
		
		setTimeout("rotateHomeImages(" + numrows + ", " + time + ",words)", rotateThree);
	}
	return true;
}

// checks to see that the current random number is different that the rest
function checkRandomNumber(randNumber, maxNumber) {
	while(randNumber == holderOne || randNumber == holderTwo || randNumber == holderThree) {
		randNumber = randomNumber(maxNumber);
	}
	return randNumber;
}

// function to switch product to given image and link
function changeProduct(product, number) {
	var tmp = eval("imgid" + number);
	eval("document['product" + product + "'].src = img" + number + ".src");
	eval("document.getElementById('link" + product + "').href = './index.php?section=view_product&product_id=" + tmp + "'");
}

// function to take two different colored boxes and switch the colors
function switchBoxColors() {

	// get all boxes in box container
	var container = document.getElementById('boxesContainer');
	var boxes = container.getElementsByTagName("DIV");
	
	// init the two random numbers
	var first = randomNumber(boxes.length);
	var secnd = randomNumber(boxes.length);
	
	// make sure first number is NOT a product box
	while (boxes[first].className == "productBox") {
		first = randomNumber(boxes.length);
	}
	
	// loop until the second number is not equal to the first &&  the colors are different && it's NOT a product box
	while (first == secnd || boxes[first].className == boxes[secnd].className || boxes[secnd].className == "productBox") {
		secnd = randomNumber(boxes.length);
	}
	
	// finally do the switch
	var tmp = boxes[first].className;
	boxes[first].className = boxes[secnd].className;
	boxes[secnd].className = tmp;
}

function switchBoxWords() {

	// get all boxes in box container
	var container = document.getElementById('boxesContainer');
	var spans = container.getElementsByTagName("SPAN");

	for (var i = 0; i < spans.length; i++) {
		spans[i].innerHTML = '';
	}
	
	// init the random numbers 
	var first = randomNumber(5);
	var second = randomNumber(6);

	// finally do the switch
	spans[first].innerHTML = words[second];
}


// setup the first three rotating images
function initRealLiving(numrows) {

	if (document.getElementById("boxesContainer")) {
		// init images to first three in array
		var first = randomNumber(numrows);
		eval("document['product0'].src = img" + first + ".src");
		eval("document.getElementById(\"link0\").href = \"./index.php?section=view_product&product_id=imgid" + first + "\"");
	}
	return true;
}

function rotateRealLiving(numrows) {
	var first = randomNumber(numrows);
	setTimeout("changeProduct(0, " + first + ")", 2000);
	setTimeout("rotateRealLiving(" + numrows + ")", 2000);
}
//-->


