window.onerror = handleErr;
function handleErr(){
found = true;
return found;
}
function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=new lib_bwcheck()

function lib_doc_size(){ 
	this.x=0;this.x2=bw.ie && document.body.offsetWidth-20||innerWidth||0;
	this.y=0;this.y2=bw.ie && document.body.offsetHeight-5||innerHeight||0;
	if(!this.x2||!this.y2) return message('Document has no width or height') 
	this.x50=this.x2/2;this.y50=this.y2/2;
	return this;
}

//Debug function ******************
function lib_message(txt){alert(txt); return false} 

//Lib objects  ********************
function lib_obj(obj,nest,o){ 
	if(!bw.bw) return lib_message('Old browser')
	nest=(!nest) ? '':'document.'+nest+'.'										
   	if(o&&bw.ns4) this.evnt=o; 
	else this.evnt=bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+"document.layers." +obj):0;	
	if(!this.evnt) return lib_message('The layer does not exist ('+obj+') - \nIf your using Netscape please check the nesting of your tags!')
	this.css=bw.dom||bw.ie4?this.evnt.style:this.evnt; this.ref=bw.dom||bw.ie4?document:this.css.document;
	this.x=this.css.left||this.css.pixelLeft||this.evnt.offsetLeft||0; this.y=this.css.top||this.css.pixelTop||this.evnt.offsetTop||0
	this.w=this.evnt.offsetWidth||this.css.clip.width||this.ref.width||this.css.pixelWidth||0; this.h=this.evnt.offsetHeight||this.css.clip.height||this.ref.height||this.css.pixelHeight||0
	this.c=0 //Clip values
	if((bw.dom || bw.ie4) && this.css.clip) {
		this.c=this.css.clip; this.c=this.c.slice(5,this.c.length-1); 
		this.c=this.c.split(' '); for(var i=0;i<4;i++){this.c[i]=parseInt(this.c[i])}
	}
	this.ct=this.css.clip.top||this.c[0]||0; this.cr=this.css.clip.right||this.c[1]||this.w||0
	this.cb=this.css.clip.bottom||this.c[2]||this.h||0; this.cl=this.css.clip.left||this.c[3]||0
	this.obj = obj + "Object"; 	eval(this.obj + "=this")
	return this
}
//Moving object to **************
lib_obj.prototype.moveIt = function(x,y){this.x=x;this.y=y; this.css.left=x;this.css.top=y} 

function resized(){
	page2=new lib_doc_size()
	if(page2.x2!=page.x2 || page2.y2!=page.y2){
		if(bw.ns4) location.reload() //If the width or height have changed we reload the page.
		else pageInit()
	}
}

// Mousemove detection
var mouseX=0,mouseY=0,setX=0,setY=0;
function getMousemove(e){
	mouseX= (bw.ns4||bw.ns6)? e.pageX: bw.ie&&bw.win&&!bw.ie4? (event.clientX-2)+document.body.scrollLeft : event.clientX+document.body.scrollLeft;
	mouseY= (bw.ns4||bw.ns6)? e.pageY: bw.ie&&bw.win&&!bw.ie4? (event.clientY-2)+document.body.scrollTop : event.clientY+document.body.scrollTop;
}


var tmr;
var activeMenu;
function setCurr_on(){
if (currMenu){
  eval(currMenu + ".css.visibility='visible'");  
  if ((currMenuItem) && (currImgOn)) swapImg(currMenuItem, currImgOn);
 }
}
function overActive(){
mouseX = mouseX - body.x;mouseY = mouseY - body.y;
leftDiv = eval(activeMenu + ".x"); // document.all[menu].offsetLeft + 1;
rightDiv = leftDiv + eval(activeMenu + ".w"); //document.all[menu].offsetLeft + document.all[menu].clientWidth - 1;
topDiv = eval(activeMenu + ".y"); //document.all[menu].offsetTop + 1;
bottomDiv = topDiv + eval(activeMenu + ".h"); //document.all[menu].offsetTop + document.all[menu].clientHeight  - 1;
if (mouseY > bottomDiv || mouseY < topDiv || mouseX < leftDiv || mouseX > rightDiv) return false;
else return true;
}
function closeAllMenus(){
menu1.css.visibility="hidden";menu2.css.visibility="hidden";menu3.css.visibility="hidden";menu4.css.visibility="hidden";menu5.css.visibility="hidden";
}
function closeActive(){
if (activeMenu){
 if (!overActive()){
  closeAllMenus();
  setCurr_on();
  activeMenu = null;
 }
}
}
function activateMenu(menu){
  activeMenu = menu;
  eval(activeMenu + ".css.visibility='visible'");
}
function openMenu(menu){
closeAllMenus();
activateMenu(menu);
}
function setTmr(time){
if (time == 0)clearTimeout(tmr);
else  tmr = setTimeout("closeActive()",time*1000);
}
function DeleteCookie (name) {  
var exp = new Date();  
exp.setTime (exp.getTime() - 1);  
var cval = GetCookie (name);  
alert(exp)
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function GetCookie (name) {  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen) {    
var j = i + alen;    
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j); 
i = document.cookie.indexOf(" ", i) + 1;    
if (i == 0) break;   
}  
return null;}
function getCookieVal (offset) {  
var endstr = document.cookie.indexOf (";", offset);  
if (endstr == -1)    
endstr = document.cookie.length;  
return unescape(document.cookie.substring(offset, endstr));}

function SetCookie (name, value,expires,path) {  
var argv = SetCookie.arguments;  
var argc = SetCookie.arguments.length;  
var expires = (argc > 2) ? argv[2] : null;  
var path = (argc > 3) ? argv[3] : null;  
var domain = (argc > 4) ? argv[4] : null;  
var secure = (argc > 5) ? argv[5] : false;  
document.cookie = name + "=" + escape(value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) +  
((domain == null) ? "" : ("; domain=" + domain)) +    
((secure == true) ? "; secure" : "");
}
function pageInit(){
if (bw.ns4) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove= getMousemove;
	//first me make a page object
	page=new lib_doc_size();
	//then we make the layer objects
	body = new lib_obj('bodyMain');	
	//now we place them	
	//The divs has a width of 7xx and height of 5xx, divide that with 2 to place it at center
if ((body.w < page.x2) && (body.h < page.y2)){
body.moveIt(page.x50 - (body.w/2),page.y50 - (body.h/2));
} else if(body.h < page.y2) {
body.moveIt(10,page.y50 - (body.h/2));
} else if(body.w < page.x2) {
body.moveIt(page.x50 - (body.w/2),10);
}
	//body.moveIt(page.x50-362,page.y50-262);
	body.css.visibility = "visible";

	menu0 = new lib_obj('nav','bodyMain');	
	menu1 = new lib_obj('Layer_3','bodyMain');
	menu2 = new lib_obj('Layer_4','bodyMain');
	menu3 = new lib_obj('Layer_1','bodyMain');
	menu4 = new lib_obj('Layer_5','bodyMain');
	menu5 = new lib_obj('Layer_2','bodyMain');
	menu0.css.visibility = "visible"
	//Takes care of the resizing.
	window.onresize=resized;
	
	setCurr_on();
}