// JavaScript Document
// Layout javascript - Sarah Reynolds
var windowWidth;
var windowHeight;

function getElementObj(id) {
	if (document.getElementById) {
		return document.getElementById(id);
	} else if (document.layers) {
		return document.layers[id];
	} else if (document.all) {
		return document.all[id];
	} else return;
}
function getStyleObj(id) {
	if (document.getElementById) {
		return document.getElementById(id).style;
	} else if (document.layers) {
		return document.layers[id];
	} else if (document.all) {
		return document.all[id].style;
	} else return;
}
function getStyle(id,styleProp) {
	if (getElementObj(id).currentStyle) {
		var styleVal = getElementObj(id).currentStyle[styleProp];
	} else if (window.getComputedStyle){
		var styleVal = document.defaultView.getComputedStyle(getElementObj(id),null).getPropertyValue(styleProp);
	}
	return styleVal;
}
function getWindowSize() {
	if (self.innerWidth) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientWidth;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	} else return;
	return windowWidth;
	return windowHeight;
}
function centerBannerWithLogo(logoDiv,bannerDiv,textDiv) {
		logoWidth = getElementObj(logoDiv).offsetWidth;
		textWidth = getElementObj(textDiv).offsetWidth;
		getStyleObj(bannerDiv).width = (windowWidth - logoWidth) + "px";
		getStyleObj(bannerDiv).leftMargin = (Math.round((windowWidth - textWidth)/2) >= 0) ? Math.round((windowWidth - textWidth)/2) + "px" : "0px";
}
var fade = 0;
var pos = 0;
var leftText = new Array("Serviettes","Nappes","Linge de Salle de Bain","Tissu De Visage","Serviette De Main","Serviette De Bain","Feuille De Bain","Serviette D'Invité","Tapis de bain","Linge de Table");
var rightText = new Array("Drap Plat","Taie d’Oreiller","Housse de Couette","Draps-housse","Cache Sommier","Linge de Cuisine","Tissu de Verre","Torchons","Tissu de Serveurs","Manique","Torchon &Eacute;ponge &agrave; Carreaux","Linge de Salle de Bain");
var leftTextPos = 0;
var rightTextPos = 0;
var currDiv = "moveright";
var currDir = "right";
function hildenMove(leftDiv,rightDiv) {
	if (fade < 237) { // to background grey
		fade += 2;
		document.getElementById(currDiv).style.color="rgb("+ fade +","+ fade + "," + fade +")";
		pos += 1;
		if (pos < 1000) {
			if (currDir == "right") {
				document.getElementById(currDiv).style.left = pos + "px";
			} else {
				document.getElementById(currDiv).style.right = pos + "px";
			}
		}
		window.setTimeout("hildenMove('"+leftDiv+"','"+rightDiv+"')",17);
		if (fade >= 237) {
			pos = 0;
			if (currDir == "right") {
				if (rightTextPos < rightText.length - 1) {
					rightTextPos++;
				} else {
					rightTextPos = 0;
				}
				document.getElementById(currDiv).innerHTML = rightText[rightTextPos];
				document.getElementById(currDiv).style.left = pos + "px";
			} else {
				if (leftTextPos < leftText.length - 1) {
					leftTextPos++;
				} else {
					leftTextPos = 0;
				}
				document.getElementById(currDiv).innerHTML = leftText[leftTextPos];
				document.getElementById(currDiv).style.right = pos + "px";
			}
			if (currDiv == leftDiv) {
				currDiv = rightDiv;
			} else {
				currDiv = leftDiv;
			}
			if (currDir == "left") {
				currDir = "right";
			} else {
				currDir = "left";
			}
			fade = 0;
			/*window.alert("Div: " + currDiv);
			window.alert("Pos: " + pos);*/
		}
	}
}
function reloadPage(init) {  //reloads the window if resized
	getWindowSize();
  if (init==true) {
		with (navigator) {
			document.pageWidth=windowWidth;
			document.pageHeight=windowHeight;
			onresize=reloadPage; 
		}
	} else if (windowWidth!=document.pageWidth || windowHeight!=document.pageHeight) {
		location.reload();
	}
}
function setNav(contentDiv,innerNavDiv) {
	/*window.alert("content height: " + getElementObj(contentDiv).offsetHeight);
	window.alert("inner nav height: " + getElementObj(innerNavDiv).offsetHeight);*/
	if (getElementObj(contentDiv).offsetHeight > getElementObj(innerNavDiv).offsetHeight) {
		getStyleObj(innerNavDiv).height = (getElementObj(contentDiv).offsetHeight - 190) + "px";
		//window.alert("new inner nav height: " + getElementObj(innerNavDiv).offsetHeight);
	}
	reloadPage(true);
}
