/*********first order of business**********/
/* (fancy jiggery-pokery to set the width of the menu 
	using special loading events so that it is set 
	without having to wait for images to load */
/*****/
var preload = function(){
	var updateOthers = function(){if ($("product_content")){$("product_content").style.left = parseInt($("topnavbox").clientWidth)+parseInt($("navboxes").clientWidth)+"px"; $("product_content").style.width = parseInt((isIE) ? document.body.clientWidth : window.innerWidth)-parseInt($("product_content").style.left)+"px";}};
	if ($("topnavbox").style.width > 100){
		var topnavboxStatus = "open";	
	} else {
		var topnavboxStatus = "closed";	
	}
	if (topnavboxStatus != GetCookie("topnavboxstatus")){
		//Effect.Shrink2("topnavbox",{direction:"top-left",duration:2.5,scaleTo:scaleAmount,scaleMode: { originalWidth: startW },afterUpdate:updateOthers});
		$("topnavbox").style.width = "170px";
	} else {
		$("topnavbox").style.width = "18px";
	}
	updateOthers();	
}

// Dean Edwards/Matthias Miller/John Resig

function init() {
	// quit if this function has already been called
	if (arguments.callee.done) return;

	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;

	// kill the timer
	if (_timer) clearInterval(_timer);

	// do stuff
	preload();
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
			init(); // call the onload handler
		}
	};
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			init(); // call the onload handler
		}
	}, 10);
}

/* for other browsers */
Behaviour.addLoadEvent(init);
/***** end first order of business! *****/
function productsReset(){
		// link colours
		$("company_link").style.color = "#FFF";
		$("products_link").style.color = "#FDF47C";
		$("projects_link").style.color = "#FFF";	
		// nav boxes open and closed
		//$("company_navbox").style.width = "0px";
		$("products_navbox").style.width = "180px";
		//$("projects_navbox").style.width = "0px";	
		// text boxes open and closed
		
}
var pageNavDefaults = function(){
		productsReset();
}
Behaviour.addLoadEvent(function() {
	pageNavDefaults();
});
var initStateStatus = 0;
function initStateReset(){
	initStateStatus++;
}
function loadStateReset(){
	if (document.body){
		pageNavDefaults();
		/*$("topnavbox").style.width = "18px";
		$("products_navbox").style.width = "18px";
		$("product_content").style.left = parseInt($("topnavbox").style.width)+parseInt($("company_navbox").style.width)+parseInt($("products_navbox").style.width)+parseInt($("products_navbox").style.width)+"px";*/
		var startW = parseInt($("topnavbox").clientWidth);
		if(startW>99){
			var scaleAmount = (18/startW)*100;
// 			var updateOthers = function(){if ($("product_content")){$("product_content").style.left = parseInt($("topnavbox").clientWidth)+parseInt($("navboxes").clientWidth)+"px"; $("product_content").style.width = parseInt((isIE) ? document.body.clientWidth : window.innerWidth)-parseInt($("product_content").style.left)+"px";}};
// 			Effect.Shrink2("topnavbox",{direction:"top-left",duration:0.67,scaleTo:scaleAmount,scaleMode: { originalWidth: startW },afterUpdate:updateOthers});
			SetCookie("topnavboxstatus","closed");
                        $("topnavbox").style.width = (parseInt($("topnavbox").style.width) / scaleAmount) + 'px';
                        if ($("product_content")){$("product_content").style.left = parseInt($("topnavbox").style.width)+parseInt($("navboxes").clientWidth)+"px"; $("product_content").style.width = parseInt((isIE) ? document.body.clientWidth : window.innerWidth)-parseInt($("product_content").style.left)+"px";}
		}
		if(parseInt($("navboxes").style.width)>179){
// 			var updateOthers2 = function(){if ($("product_content")){$("product_content").style.left = parseInt($("topnavbox").clientWidth)+parseInt($("navboxes").clientWidth)+"px"; $("product_content").style.width = parseInt((isIE) ? document.body.clientWidth : window.innerWidth)-parseInt($("product_content").style.left)+"px";}};
// 			Effect.Shrink2("navboxes",{direction:"top-left",duration:0.67,scaleTo:((18/180)*100),scaleMode: { originalWidth: 180 },afterUpdate:updateOthers2});
                        $("navboxes").style.width = ((parseInt($("navboxes").style.width) || parseInt($("navboxes").clientWidth)) / 10) + 'px';
                        if ($("product_content")){$("product_content").style.left = parseInt($("topnavbox").style.width)+parseInt($("navboxes").clientWidth)+"px"; $("product_content").style.width = parseInt((isIE) ? document.body.clientWidth : window.innerWidth)-parseInt($("product_content").style.left)+"px";}
		} else if(parseInt($("navboxes").style.width)<1){
// 			var updateOthers2 = function(){if ($("product_content")){$("product_content").style.left = parseInt($("topnavbox").clientWidth)+parseInt($("navboxes").clientWidth)+"px"; $("product_content").style.width = parseInt((isIE) ? document.body.clientWidth : window.innerWidth)-parseInt($("product_content").style.left)+"px";}};
			$("company_navbox").style.width = "0px";
			$("projects_navbox").style.width = "0px";
			$("products_navbox").style.width = "180px";
// 			Effect.Shrink2("navboxes",{direction:"top-left",duration:0.67,scaleTo:((18/180)*100),scaleMode: { originalWidth: 180 },afterUpdate:updateOthers2});
                        $("navboxes").style.width = ((parseInt($("navboxes").style.width) || parseInt($("navboxes").clientWidth)) / 10) + 'px';
                        if ($("product_content")){$("product_content").style.left = parseInt($("topnavbox").style.width)+parseInt($("navboxes").clientWidth)+"px"; $("product_content").style.width = parseInt((isIE) ? document.body.clientWidth : window.innerWidth)-parseInt($("product_content").style.left)+"px";}
		}
		/*var startW = 170;
		var scaleAmount = (18/startW)*100;
		var updateOthers = function(){if ($("product_content")){$("product_content").style.left = parseInt($("topnavbox").style.width)+parseInt($("products_navbox").style.width)+"px";}};
		Effect.Shrink2("topnavbox",{direction:"top-left",duration:0.67,scaleTo:scaleAmount,scaleMode: { originalWidth: startW },afterUpdate:updateOthers});
		var updateOthers2 = function(){if ($("product_content")){$("product_content").style.left = parseInt($("topnavbox").style.width)+parseInt($("products_navbox").style.width)+"px";}};
		Effect.Shrink2("products_navbox",{direction:"top-left",duration:0.67,scaleTo:((18/180)*100),scaleMode: { originalWidth: 180 },afterUpdate:updateOthers2});
		*/
	}
}
///***///
Behaviour.addLoadEvent(function() {
	pageNavDefaults();	
	if (document.body){
		var startW = 170;
		var scaleAmount = (18/startW)*100;
		var updateOthers = function(){$("product_content").style.overflow = "auto";$("product_content").style.left = $("topnavbox").clientWidth+$("navboxes").clientWidth+"px";  $("product_content").style.width = parseInt((isIE) ? document.body.clientWidth : window.innerWidth)-parseInt($("product_content").style.left)+"px";};
		//Effect.Shrink2("navboxes",{direction:"top-left",duration:2.5,scaleTo:((18/180)*100),scaleMode: { originalWidth: 180 },afterFinish:initStateReset,afterUpdate:updateOthers});
		if ($("topnavbox").style.width > 100){
			topnavboxStatus = "open";	
		} else {
			topnavboxStatus = "closed";	
		}
		if (topnavboxStatus != GetCookie("topnavboxstatus")){
			//Effect.Shrink2("topnavbox",{direction:"top-left",duration:2.5,scaleTo:scaleAmount,scaleMode: { originalWidth: startW },afterUpdate:updateOthers});
			$("topnavbox").style.width = "170px";
		} else {
			$("topnavbox").style.width = "18px";
		}
		updateOthers();
		initStateReset();
	}
		//	
});
///***///
var prodrules = {
	'#product_textbox' : function(el){
		el.onmouseover = function(){
			loadStateReset();
		}
	}
};
Behaviour.register(prodrules);
winResize();
