// JavaScript Document
var pages = new Array("default.htm", "cook.html","nest.html","grow.html");
var menus = new Array("MainMenu1","MainMenu2","MainMenu3","MainMenu4");
var colors = new Array("#DC8028","#559BCC","#AC2024","#659b22","#be620a");
var subNavSelected;
var oldSubNavSelected;
var firstIn;

function doPageInit() {

	var i;
	var maxLoop = menus.length;
	for(i=0;i<maxLoop;i++) {
		if (i!=livePage) {
			document.getElementById("MM" + String(i+1) + "_image").style.cursor = "pointer";
		}
	}
	document.getElementById("MM" + String(livePage+1) + "_image").onmouseover=null;
	document.getElementById("MM" + String(livePage+1) + "_image").onmouseout=null;
	document.getElementById("MM" + String(livePage+1) + "_image").onclick=null;
	document.getElementById("MM" + String(livePage+1) + "_image").style.zIndex = 1;

	subNavSelected = 0;
	doInit = true;

	doSubNavLinkStyleToArrow('sn1');

	if (window.location.hash) {
		doSubNavLinkStyleToArrow( window.location.hash.substr(1,window.location.hash.length) );
	}
	fixMask();
}
function fixMask() {
	var pos = (document.body.offsetWidth - 960)/2;
	if (pos < 0) pos = 0;
	document.getElementById("mask").style.width = String(pos) + "px";

}

// MAIN MENU FUNCTIONS
function doMainMenuMouseOver(obj,isR) {
	var variant = "_up";
	if (isR) variant = "_rl";
	document.getElementById("MM" + String(obj+1) + "_image").src = imagePath + menus[obj] + variant + ".gif";
}
function doMainMenuClick(obj) {
	location.href = pages[obj];
}
// SUBNAV MENU FUNCTIONS
function doSubNavLinkStyle(obj,isU) {
	if (navNum(obj)!= subNavSelected) {
		if (isU) {
			document.getElementById(obj).style.textDecoration = "underline";
			document.getElementById(obj).style.color = colors[livePage];
		} else {
			document.getElementById(obj).style.textDecoration = "none";
			document.getElementById(obj).style.color = colors[4];
		}
	}
}
function doSubNavLinkStyleToArrow(obj) {
	var test4SubNavSelected = navNum(obj);
	if (test4SubNavSelected!= subNavSelected) {
		document.getElementById(obj).innerHTML = "\u25ba" + document.getElementById(obj).innerHTML;
		document.getElementById(obj).style.textDecoration = "none";
		document.getElementById(obj).style.cursor = "default";
		document.getElementById(obj).style.color = colors[livePage];
		oldSubNavSelected = subNavSelected;
		subNavSelected = test4SubNavSelected;
		var maxLoop = subNavNames.length;
		for(i=0;i<maxLoop;i++) {
			if (obj != ("sn" + String(i+1))) {
				var matchedObj = "sn" + String(i+1);
				document.getElementById(matchedObj).innerHTML = subNavNames[i];
				document.getElementById(matchedObj).style.textDecoration = "none";
				document.getElementById(matchedObj).style.cursor = "pointer";
				document.getElementById(matchedObj).style.color = colors[4];
			}
		}
		(!doInit) ? doTransition(): (doInit = false);
	}

}
function navNum(aNum) {
	return parseInt(aNum.substr(2,1));
}

function doTransition() {
	var obj1 = 'Page_' + oldSubNavSelected;
	var obj2 = 'Page_' + subNavSelected;

	var t1A = new Tween(document.getElementById(obj1).style,'left',Tween.regularEaseInOut,0,-1300,0.5,'px');
	var t1B = new Tween(document.getElementById(obj2).style,'left',Tween.regularEaseInOut,-1300,0,0.5,'px');

	t1A.onMotionFinished = function(){
		t1B.start();
	};
	t1B.onMotionFinished = function(){
		//alert('motion done --> ' + document.getElementById('MeetKatie_Page_2_ContentTextBlock').style.left);
	};
	t1A.start();
}
