
var menus=new Array();
var tabs=new Array();
var subs=new Array();


/*	this function is called onLoad and creates layer objects
	of the tabs on the menu, and sets up tab object so that
	each tab knows its state (up or down), and the amount
	it should drop by. The tabsizes should be divisible by 2
	
	If another sub-tab is added, add an additional 12 to the array for the corresponding tab
	
*/
function menu() {
	tabsizes=new Array(0,68,68,52,52,146,38,148,0,0,0)
	menus[0]=new objLayer("outer")
	menus[0].clipTo(0,205,500,0)
	for (i=1;i<12;i++) {
		menus[i]=new objLayer("tab"+i)
		tabs[i]=new tab(tabsizes[i-1])
		menus[i].moveTo(0,(i*25)-25);
		menus[i].setZIndex(20+i);
	}
	subs[1]=new objLayer("sub1");
	subs[2]=new objLayer("sub2");
	subs[3]=new objLayer("sub3");
	subs[4]=new objLayer("sub4");
	subs[5]=new objLayer("sub5");
	subs[6]=new objLayer("sub6");
	subs[7]=new objLayer("sub7");
	subs[8]=new objLayer("sub8");
	subs[9]=new objLayer("sub9");
	locate=document.location.href
	if (locate.indexOf("market/")!=-1) {
		initab=2
	} else if (locate.indexOf("display/")!=-1) {
		initab=3
	} else if (locate.indexOf("classified/")!=-1) {
		initab=4
	} else if (locate.indexOf("recruitment/")!=-1) {
		initab=5
	} else if (locate.indexOf("rt/")!=-1) {
		initab=6
	} else if (locate.indexOf("event/")!=-1) {
		initab=7
	} else if (locate.indexOf("other/")!=-1) {
		initab=8
	} else {
		initab=0
	}
	if (initab>0) {
	for (i=initab+1;i<menus.length;i++) {
		menus[i].moveBy(0,tabs[initab].tabsize)
		tabs[initab].state="down"
		currentmenu=initab;
		document.getElementById("tab"+initab).style.backgroundColor="#FFFFFF";
		document.getElementById("navtab"+initab).className="tabOn";
	}
	}
	menus[0].show();
	runjobs()
}

/*	this function creates a new tab object
	giving each tab a state and a size
	*/
function tab(n) {
	this.state="up"
	this.tabsize=n
	return this
}

var jobs=new Array()
var temparray=new Array()
var active=false
var jobstimer
var slidetimer
var currentmenu=0

/*	this function is called when a tab is clicked on,
	it adds to the list of tab animation left to run
	*/
function nav(n) {
	if (currentmenu!=0 && currentmenu!=n) {
		jobs[0]=currentmenu;
		if (n!=12) {jobs[1]=n}
	} else {
		if (n!=12) {jobs[0]=n}
	}
}

/*	this function moves through the list of jobs to do,
	held the jobs array; it runs constantly to ensure
	all the jobs are completed
	*/
function runjobs() {
	if (!active && jobs.length>0) {
		active=true;
		toggle(jobs[0])
	}
	jobstimer=setTimeout("runjobs()",20)
}

/*	this is the first part of the tab animation,
	it tests whether the tab is up or down and
	calls the relevant move function
	*/
function toggle(n) {
	if (tabs[n].state=="up") {
		(tabs[n].state="down")
		document.getElementById("tab"+n).style.backgroundColor="#FFFFFF";
		document.getElementById("navtab"+n).className="tabOn";
		tabanim(n,0,2)
	} else {
		tabs[n].state="up"
		document.getElementById("tab"+n).style.backgroundColor="#FFFFFF";
		document.getElementById("navtab"+n).className="tab";
		tabanim(n,0,-2)
	}
}

/*	this function actually moves the tabs, it loops until the
	tab has moved through the number of pixels in its size, it moves all tabs
	below the active one as well. Once the animation has run, it removes the
	tab from the list of current jobs
	*/
function tabanim(n,s,d) {
	for (i=n+1;i<menus.length;i++) {
		menus[i].moveBy(0,d)
	}
	s+=2
	if (s!=tabs[n].tabsize) {
		slidetimer=setTimeout("tabanim("+n+","+s+","+d+")",10)
	} else {
		active=false
		d==2?currentmenu=n:currentmenu=0;
		temparray=new Array()
		for (i=1;i<jobs.length;i++) {
			temparray[temparray.length]=jobs[i]
		}
		jobs=temparray
	}
}

/* This is for the pop-out sub menus */
var linkTimer;

function showSub(n) {
	document.getElementById("subParent"+n).style.backgroundColor="#E0F0FF";
	subs[n].show();
}

function boxOff() {
	subs[1].hide();
	subs[2].hide();
	subs[3].hide();
	subs[4].hide();
	subs[5].hide();
	subs[6].hide();
	subs[7].hide();
	subs[8].hide();
	subs[9].hide();
	document.getElementById("subParent1").style.backgroundColor="";
	document.getElementById("subParent2").style.backgroundColor="";
	document.getElementById("subParent3").style.backgroundColor="";
	document.getElementById("subParent4").style.backgroundColor="";
	document.getElementById("subParent5").style.backgroundColor="";
	document.getElementById("subParent6").style.backgroundColor="";
	document.getElementById("subParent7").style.backgroundColor="";
	document.getElementById("subParent8").style.backgroundColor="";
	document.getElementById("subParent9").style.backgroundColor="";
}

function initOff() {
	linkTimer=setTimeout("boxOff()",50);
}