// SM 26.02.02 Copyright Enzyme Design Ltd

onload = init

var hidem;
var lagon,lagoff;
var lag = 600;
var showing = 0;
var buttonShowing = 0;
var showScroller = false;
var menuActivate;

if (strPage == "home") menuActivate = false;
else menuActivate = true;

function getLayerObj(lyr,parent){
	if (document.getElementById) {
		lyrObj = document.getElementById(lyr)
	}
	else if (document.all) {
		lyrObj = document.all[lyr]
	}
	else if (document.layers) {
		lyrObj = document.layers[lyr]
	}
	else {
		lyrObj = null;
	}
	return lyrObj
}

function showLayer(lyr,action) {
	objRef = getLayerObj(lyr,null)
	if (objRef != null) { 
		if (document.layers) objRef.visibility = action
		else {
			if (action=="show") objRef.style.visibility = "visible"
			else objRef.style.visibility = "hidden"
		}
	}	
}

function changeImage(layer,imgName,imgObj) { 
	if (document.layers && layer!=null) eval('document.'+layer+'.document.images["'+imgName+'"].src = '+imgObj+'.src');
	else document.images[imgName].src = eval(imgObj+".src");
}

function preload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()')
		eval(imgObj+'.src = "'+imgSrc+'"')
	}
}

count = 0;

function imageLoaded() { 
	count++;
	if (count==4) menuActivate = true; 
}

preload('menu1_off',strRoot + '/images/buttons/menu1_off.gif')
preload('menu2_off',strRoot + '/images/buttons/menu2_off.gif')
preload('menu3_off',strRoot + '/images/buttons/menu3_off.gif')

preload('menu1_on',strRoot + '/images/buttons/menu1_on.gif')
preload('menu2_on',strRoot + '/images/buttons/menu2_on.gif')
preload('menu3_on',strRoot + '/images/buttons/menu3_on.gif')	

preload('button1_off',strRoot + '/images/buttons/button1_off.gif')
preload('button2_off',strRoot + '/images/buttons/button2_off.gif')
preload('button3_off',strRoot + '/images/buttons/button3_off.gif')

preload('button1_on',strRoot + '/images/buttons/button1_on.gif')
preload('button2_on',strRoot + '/images/buttons/button2_on.gif')
preload('button3_on',strRoot + '/images/buttons/button3_on.gif')
	
function init() {	
	objRef = getLayerObj("menu1",null)
	initMouseEvents(objRef)
	objRef = getLayerObj("menu2",null)
	initMouseEvents(objRef)
	objRef = getLayerObj("menu3",null)
	initMouseEvents(objRef)
	
	// starts the scroller
	if (showScroller) eventLoaderCaller()			
}

function initMouseEvents(objRef) { 
	if (objRef != null) { 
		if (document.layers) {
			objRef.captureEvents(Event.MOUSEOVER)
			objRef.captureEvents(Event.MOUSEOUT)
		}	
		objRef.onmouseover = menuOn
		objRef.onmouseout = menuOff
	} 
}

function menuOn(e) {
	window.clearTimeout(lagoff)
	return true;
}

function menuOff(e) {
	if(!e) e = window.event
	offX = (document.layers)?e.pageX:e.clientX;
	offY = (document.layers)?e.pageY-33:e.clientY;
		
	var menuleft = "472";
	var menuright = "708";
	
	if (showing==1) {
		menutop = 108;
		menubottom = menutop + menu1Height;
	}
	else if (showing==2) {
		menutop = 143;
		menubottom = menutop + menu2Height;
	}
	else if (showing==3) {
		menutop = 178;
		menubottom = menutop + menu3Height;
	}
	
	if (!(offY <= menutop)) {
		if ((offY <= menutop) || (offX <= menuleft) || (offX >= menuright) || (offY >= menubottom)) {
			window.clearTimeout(hidem)
			hidem = setTimeout('hideMenu(\'' + this.id + '\')',4)
		}
	}	
	
	return true
}

function hideMenu(what) { 
	which = what.substr(4,5)

	showLayer(what,'hide')
	if (sectionOn!=which) {
		changeImage("button" + which,"img" + which,"button" + which + "_off")
	}
	if (strPage == "home") showLayer('b'+ which +'rollover','hide');
	showing=0;
	buttonShowing = 0;
}

function navOver(){
	what = this.id
	which = what.substr(4,5)
	toShow = which;
}

function buttonOn(which) {  
if (menuActivate) { 
	buttonShowing=which;
	if (showing == which) {
		window.clearTimeout(hidem)
		window.clearTimeout(lagoff)
	}
	else {
		toShow=which
		if (sectionOn!=which) changeImage("button" + which,"img" + which,"button" + which + "_on")		
		lagon = setTimeout('afterOnLag('+which+')',lag)
	}
	if (strPage == "home") showLayer('b'+ which +'rollover','show');
}
}

function buttonOff(which) { 
if (menuActivate) {
	if (showing==which) {
		lagoff = setTimeout('afterOffLag('+which+')',lag-10)
	} 
	else {
		if (sectionOn!=which) {
			if (strPage == "home") showLayer('b'+ which +'rollover','hide');
			changeImage("button" + which,"img" + which,"button" + which + "_off")	
		}
		if (lagon) window.clearTimeout(lagon)
	}
}
}

function afterOnLag(which) { 
	if (showing != 0) {
		if (sectionOn!=which) changeImage("button" + showing,"img" + showing,"button" + showing + "_off")		
		showLayer('menu' + showing,'hide');
		showing = 0;
	}
	changeImage("button" + which,"img" + which,"button" + which + "_on")
	showLayer('menu' + which,'show');
	showing = which;
}

function afterOffLag(which) { 
	if (sectionOn!=which) {
		changeImage("button" + which,"img" + which,"button" + which + "_off")
		if (strPage == "home") showLayer('b'+ which +'rollover','hide');
	}
	temp = "menu" + which
	showLayer(temp,'hide')
	showing = 0;
	buttonShowing=0;
}