//Default browsercheck, added to all scripts!
function checkBrowser(){
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie7=(this.ver.indexOf("MSIE 9")>-1 && this.dom)?1:0;
	this.ie7=(this.ver.indexOf("MSIE 8")>-1 && this.dom)?1:0;
	this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie7 || this.ie6 || this.ie4 || this.ns4 || this.ns5)
	return this
}
bw=new checkBrowser()

//General variables
mainmenus=0; submenus=new Array()

/********************************************************************************
Object constructor and object functions
********************************************************************************/
function makePageCoords(){
	this.x=0;this.x2=(bw.ns4 || bw.ns5)?innerWidth:document.body.offsetWidth-20;
	this.y=0;this.y2=(bw.ns4 || bw.ns5)?innerHeight:document.body.offsetHeight-5;
	this.x50=this.x2/2;	this.y50=this.y2/2;
	return this;
}
function makeMenu(obj,nest,type,num,subnum,subsubnum){
    nest=(!nest) ? '':'document.'+nest+'.'
   	this.css=bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+"document.layers." +obj):0;					
	this.evnt=bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+"document.layers." +obj):0;		
	this.height=bw.ns4?this.css.document.height:this.evnt.offsetHeight
	this.width=bw.ns4?this.css.document.width:this.evnt.offsetWidth
	this.moveIt=b_moveIt; this.bgChange=b_bgChange;	
	this.clipTo=b_clipTo;
	if(type==0){
		this.evnt.onmouseover=new Function("mmover("+num+")");
		this.evnt.onmouseout=new Function("mmout("+num+")");
	}else if(type==1){
		this.clipIn=b_clipIn;
		this.clipOut=b_clipOut;
		this.clipy=0
		if(bw.ns4 && menueventoff=="mouse"){
			this.evnt.onmouseout=new Function("setTimeout('if(!nssubover) hidemain(-1);',50)")
			this.evnt.onmouseover=new Function("nssubover=true")
		}
	}else if(type==2){
		this.evnt.onmouseover=new Function("submmover("+num+","+subnum+")");
		this.evnt.onmouseout=new Function("submmout("+num+","+subnum+")");
	}else if(type==3){
		this.evnt.onmouseover=new Function("subsubmmover("+num+","+subnum+","+subsubnum+")");
		this.evnt.onmouseout=new Function("subsubmmout("+num+","+subnum+","+subsubnum+")");
	}
	this.tim=100
    this.obj = obj + "Object"; 	eval(this.obj + "=this")	
}
function b_clipTo(t,r,b,l,h){if(bw.ns4){this.css.clip.top=t;this.css.clip.right=r
this.css.clip.bottom=b;this.css.clip.left=l
}else{this.css.clip="rect("+t+","+r+","+b+","+l+")";
if(h){ if(bw.ie4 || bw.ie6 || bw.ie7){ this.css.height=b; this.css.width=r}}}}
function b_moveIt(x,y){this.x=x; this.y=y; this.css.left=this.x;this.css.top=this.y}
function b_bgChange(color){if(bw.dom || bw.ie4) this.css.backgroundColor=color;
else if(bw.ns4) this.css.bgColor=color}
function b_clipIn(speed){
	if(this.clipy>0){
		this.clipy-=speed
		if(this.clipy<0) this.clipy=0
		this.clipTo(0,mainwidth,this.clipy,0,1)
		this.tim=setTimeout(this.obj+".clipIn("+speed+")",10)
	}else{this.clipy=0; this.clipTo(0,mainwidth,this.clipy,0,1)}	
}
function b_clipOut(speed){
	if(this.clipy<this.clipheight){
		this.clipy+=speed
		this.clipTo(0,mainwidth,this.clipy,0,1)
		this.tim=setTimeout(this.obj+".clipOut("+speed+")",10)
	}else{this.clipy=this.clipheight; this.clipTo(0,mainwidth,this.clipy,0,1)}
}
/********************************************************************************
Checking if the values are % or not.
********************************************************************************/
function checkp(num,lefttop){
	if(num.toString().indexOf("%")!=-1){
		if(!lefttop){
			if(menurows)num=(page.x2*parseFloat(num)/100)
			else num=(page.y2*parseFloat(num)/100)
		}else{
			if(!lefttop) num=(page.x2*parseFloat(num)/100)
			else num=(page.y2*parseFloat(num)/100)
		}
	}else num=parseInt(num)
	return num
}
/********************************************************************************
Making menuobjects, placing them and clips them
********************************************************************************/

function menuInit(){
	page=new makePageCoords()
	mainwidth=checkp(mainwidth,0)
	mainheight=checkp(mainheight,1)
	subheight=checkp(subheight,1)
	if(backgroundbar){ //Backgroundbar part
		oBackgroundbar=new makeMenu('divBackgroundbar','',-1)
		oBackgroundbar.moveIt(checkp(backgroundbarfromleft,0),checkp(backgroundbarfromtop,1))
		if(menurows) oBackgroundbar.clipTo(0,checkp(backgroundbarsize),mainheight,0,1)
		else oBackgroundbar.clipTo(0,mainwidth,checkp(backgroundbarsize),0,1)
		oBackgroundbar.bgChange(backgroundbarcolor)
	}
	oMenu=new Array()
	x=checkp(fromleft,0); y=checkp(fromtop,1);
	for(i=0;i<mainmenus;i++){
		oMenu[i]=new makeMenu('divMenuMain'+i,'',0,i)
		oMenu[i].clipTo(0,mainwidth,mainheight,0,1)
		if(menuplacement!=0){
			if(menurows) x=checkp(menuplacement[i])
			else y=checkp(menuplacement[i])
		}
		oMenu[i].moveIt(x,y)
		oMenu[i].bgChange(mainbgcoloroff)
		if(!menurows) y+=mainheight+checkp(pxbetween)
		else x+=mainwidth+checkp(pxbetween)
		if(submenus[i]!='nosub'){
			oMenu[i].subs=new makeMenu('divMenuSub'+i,'',1,i,-1)
			if(!menurows) oMenu[i].subs.moveIt(mainwidth+oMenu[i].x,oMenu[i].y)
			else oMenu[i].subs.moveIt(oMenu[i].x,oMenu[i].y+mainheight)
			suby=0;
			oMenu[i].sub=new Array()
			for(j=0;j<submenus[i]["main"];j++){
				oMenu[i].sub[j]=new makeMenu('divMenuSub'+i+'_'+j,'divMenuSub'+i,2,i,j)
				oMenu[i].sub[j].clipTo(0,mainwidth,subheight,0,1)
				oMenu[i].sub[j].moveIt(0,suby)
				oMenu[i].sub[j].bgChange(subbgcoloroff)
				suby+=subheight
				if(submenus[i]["submenus"][j]>0){
					subsuby=0
					oMenu[i].sub[j].subs=new makeMenu('divMenuSub'+i+'_'+j+'_sub','',1,i,j)
					oMenu[i].sub[j].subs.moveIt(oMenu[i].subs.x+mainwidth/2,oMenu[i].sub[j].y+oMenu[i].subs.y+10)
					oMenu[i].sub[j].sub=new Array()
					for(a=0;a<submenus[i]["submenus"][j];a++){
						oMenu[i].sub[j].sub[a]=new makeMenu('divMenuSub'+i+'_'+j+'_sub'+a,'divMenuSub'+i+'_'+j+'_sub',3,i,j,a)
						oMenu[i].sub[j].sub[a].clipTo(0,mainwidth,subheight,0,1)
						oMenu[i].sub[j].sub[a].moveIt(0,subsuby)
						oMenu[i].sub[j].sub[a].bgChange(subsubbgcoloroff)
						subsuby+=subheight
					}
					oMenu[i].sub[j].subs.clipTo(0,mainwidth,0,0,1)
					oMenu[i].sub[j].subs.clipheight=subsuby
				}else oMenu[i].sub[j].subs=0
			}
			oMenu[i].subs.clipTo(0,mainwidth,0,0,1)
			oMenu[i].subs.clipheight=suby
		}else oMenu[i].subs=0
	}
	setTimeout("window.onresize=resized;",500)
	if(menueventoff=="mouse") document.onmouseover=docover;
}
function resized(){
	page2=new makePageCoords()
	if(page2.x2!=page.x2 || page.y2!=page2.y2) location.reload()
}
/*********************************************************************************************
Mouseevents
*********************************************************************************************/
function docover(){hidemain(-1);}; var nssubover;
function mmover(num){
	oMenu[num].bgChange(mainbgcoloron)
	if(menueventon=="mouse") {menumain(num,1);}
	if(menueventoff=="mouse" || menueventon=="mouse"){if(bw.ie4 || bw.ie6 || bw.ie7) window.event.cancelBubble=true;}
}
function mmout(num){if(num>-1){ if(!stayoncolor || oMenu[num].subs==0 || menueventon=="click") oMenu[num].bgChange(mainbgcoloroff);} if(bw.ie4 || bw.ie6 || bw.ie7) window.event.cancelBubble=true;}
function submmover(num,subnum){
	oMenu[num].sub[subnum].bgChange(subbgcoloron)
	if(menueventon=="mouse") {menusub(num,subnum,1);}
	if(menueventoff=="mouse" || menueventon=="mouse"){if(bw.ie4 || bw.ie6 || bw.ie7) window.event.cancelBubble=true;}
}
function submmout(num,subnum){if(subnum>-1){nssubover=false; if(!stayoncolor || oMenu[num].sub[subnum].subs==0 || menueventon=="click") oMenu[num].sub[subnum].bgChange(subbgcoloroff)}}
function subsubmmover(num,subnum,subsubnum){
	oMenu[num].sub[subnum].sub[subsubnum].bgChange(subsubbgcoloron)
		if(menueventoff=="mouse" || menueventon=="mouse"){if(bw.ie4 || bw.ie6 || bw.ie7) window.event.cancelBubble=true;}
}
function subsubmmout(num,subnum,subsubnum){if(subnum>-1){nssubover=false; oMenu[num].sub[subnum].sub[subsubnum].bgChange(subsubbgcoloroff)}}
/*********************************************************************************************
Showing submenus
*********************************************************************************************/
function menumain(num,mouse){
	if(oMenu[num].subs!=0){
		clearTimeout(oMenu[num].subs.tim)
		if(oMenu[num].subs.clipy>=0 || mouse){
			hidemain(num); oMenu[num].subs.clipOut(menuspeed)
		}else if(oMenu[num].subs.clipy<=oMenu[num].subs.clipheight){
			hidemain(num); oMenu[num].subs.clipIn(menuspeed)
		}
	}
}
/*********************************************************************************************
Showing subsubmenus
*********************************************************************************************/
function menusub(num,sub,mouse){
	hidesubs(num,sub)
	if(oMenu[num].sub[sub].subs!=0){
		if(oMenu[num].sub[sub].subs.clipy==0 || mouse){
			oMenu[num].sub[sub].subs.clipOut(menusubspeed)
		}else if(oMenu[num].sub[sub].subs.clipy==oMenu[num].sub[sub].subs.clipy){
			oMenu[num].sub[sub].subs.clipIn(menusubspeed)
		}
	}
}
/*********************************************************************************************
Hides the other sub menuitems if any are shown. Also calls the hidesubs to hide any showing
submenus.
*********************************************************************************************/
function hidemain(num){
	for(i=0;i<oMenu.length;i++){
		if(oMenu[i].subs!=0){
			if(oMenu[i].subs.clipy<=oMenu[i].subs.clipheight){
				hidesubs(i,100)
				if(i!=num){
					clearTimeout(oMenu[i].subs.tim)
					if(stayoncolor) oMenu[i].bgChange(mainbgcoloroff)
					if(menurows)oMenu[i].subs.clipIn(menuspeed)
					else{oMenu[i].subs.clipy=0; oMenu[i].subs.clipTo(0,mainwidth,oMenu[i].subs.clipy,0,1)}
				}
			}
		}
	}
}
/*********************************************************************************************
Hides the other subsub menuitems if any are shown.
*********************************************************************************************/
function hidesubs(num,sub){
	for(j=0;j<oMenu[num].sub.length;j++){
		if(oMenu[num].sub[j].subs!=0 && j!=sub){
			if(oMenu[num].sub[j].subs.clipy<=oMenu[num].sub[j].subs.clipy
			|| oMenu[num].subs.clipy<oMenu[num].subs.clipheight){
				clearTimeout(oMenu[num].sub[j].subs.tim)
				if(stayoncolor) oMenu[num].sub[j].bgChange(subbgcoloroff)
				oMenu[num].sub[j].subs.clipy=0
				oMenu[num].sub[j].subs.clipTo(0,mainwidth,oMenu[num].sub[j].subs.clipy,0,1)
			}
		}
	}
}
/*********************************************************************************************
These are the functions that writes the menus to the page. 
*********************************************************************************************/
function makeMain(num,text,link){
	str=""
	if(backgroundbar && num==0){str+='\n<div id="divBackgroundbar"></div>\n'}
	str+='<div id="divMenuMain'+num+'" class="clMenuMain">'
	if(link){ str+='<a href="'+link+'" class="clAMenuMain">'; submenus[num]='nosub'
	}else str+='<a href="#" class="clAMenuMain" onclick="menumain('+num+')">'
	str+=text+'</a></div>\n'
	mainmenus++; 
	document.write(str)
}
function makeSub(num,subnum,text,link,total){
	str=""
	if(subnum==0) str='<div id="divMenuSub'+num+'" class="clMenuSub">\n'
	str+='\t<div id="divMenuSub'+num+'_'+subnum+'" class="clMenuSub1">'
	if(link) str+='<a href="'+link+'" class="clAMenuSub">'; else str+='<a href="#"  class="clAMenuSub" onclick="menusub('+num+','+subnum+')">'
	str+=text+'</a></div>\n'
	if(subnum==total-1){
		str+='</div>\n'; submenus[num]=new Array()
		submenus[num]["main"]=total; submenus[num]["submenus"]=new Array()
	}
	document.write(str)
}
function makeSubSub(num,subnum,subsubnum,text,link,total){
	str=""
	if(subsubnum==0) str='<div id="divMenuSub'+num+'_'+subnum+'_sub" class="clMenuSub">\n'
	str+='\t<div id="divMenuSub'+num+'_'+subnum+'_sub'+subsubnum+'" class="clMenuSub1">'
	if(link) str+='<a href="'+link+'" class="clAMenuSubSub">'; else str+='<a href="#"  class="clAMenuSubSub">'
	str+=text+'</a></div>\n'
	if(subsubnum==total-1){str+='</div>\n'; submenus[num]["submenus"][subnum]=total}
	document.write(str)
}
/*********************************************************************************************
END Menu script
*********************************************************************************************/
