

// global vars //
var ie=(document.all);
var ns=(document.layers);
var dom=(document.getElementById&&!document.all);
var mouseX,mouseY;
var separ1=null;
var separ2=null;
var loaded=false;

// config section //
var imagePath='';
//var imagePath='';
var menuTopOffset=120;
var menuLeftOffset=0;
var entryHeight=20;
var entryWidth=190;
var fontFamily='Century Gothic,sans-serif';
var fontSize='small';
var defaultBgCol='#ffffff';

// holder object for all submenus //
function Menu() {
	this.subs=new Array;
	this.buttonOver=false;
	
	this.output = function() {
		var styles='';
		styles+='<STYLE TYPE="text/css">' +
			   '.entry {' +
			   		'position: absolute;' +
			   		'top: 0px;' +
			   		'left: 0px;' +
			   		'height: ' + entryHeight + 'px;' +
			   		'width: ' + entryWidth + 'px;' +
			   		'visibility: hidden;' +
					'cursor : hand;' +
			   '}';
	 	styles+='.entryText {' +
					'font-family:' + fontFamily + ';' +
					'font-weight:normal;' +
					'font-size:' + fontSize + ';' +
					'text-decoration:none;' +
					'color:#666666;' +
					'}';
		styles+='.entryTextOver {' +
					'font-family:' + fontFamily + ';' +
					'font-weight:normal;' +
					'font-size:' + fontSize + ';' +
					'text-decoration:none;' +
					'color:' + defaultBgCol + ';' +
					'}' +
					'</STYLE>';
		var menuHtml='';
		for (eachMenu in this.subs) {
			menuHtml+=this.subs[eachMenu].output();
		}
		document.write(styles + menuHtml);
	}
	
	this.buildRefs = function() {
		for (eachMenu in this.subs) {
			for (eachEntry in this.subs[eachMenu].entries) {
				this.subs[eachMenu].entries[eachEntry].ref=eval(this.subs[eachMenu].entries[eachEntry].getRef(''));
				this.subs[eachMenu].entries[eachEntry].overRef=eval(this.subs[eachMenu].entries[eachEntry].getRef('over'));
				this.subs[eachMenu].entries[eachEntry].absLeft=menuLeftOffset + this.subs[eachMenu].left;
				this.subs[eachMenu].entries[eachEntry].absTop=menuTopOffset + this.subs[eachMenu].top + (this.subs[eachMenu].entries[eachEntry].number*(entryHeight));
				this.subs[eachMenu].entries[eachEntry].absBottom=this.subs[eachMenu].entries[eachEntry].absTop + entryHeight;
				this.subs[eachMenu].entries[eachEntry].absRight=this.subs[eachMenu].entries[eachEntry].absLeft + entryWidth + 1;
				if (ie||ns) {
					if (ns) {
						this.subs[eachMenu].entries[eachEntry].ref.captureEvents(Event.MOUSEOVER|Event.MOUSEDOWN);
						this.subs[eachMenu].entries[eachEntry].overRef.captureEvents(Event.MOUSEOVER|Event.MOUSEDOWN);
					}
					this.subs[eachMenu].entries[eachEntry].ref.onmouseover=this.rollover;
					this.subs[eachMenu].entries[eachEntry].overRef.onmousedown=this.goLink;
				} else {
					this.subs[eachMenu].entries[eachEntry].ref.addEventListener("mouseover",this.rollover,false);
					this.subs[eachMenu].entries[eachEntry].overRef.addEventListener("mousedown",this.goLink,false);
				}
			}
		}
		} 
	
	this.position = function() {
		for (eachMenu in this.subs) {
			this.subs[eachMenu].position();
		}
	} 
	
	this.addMenu = function(menuname, left, color, sep1, sep2) {
		this.subs[menuname]=new SubMenu(menuname, left, color,0, sep1, sep2);
	}
	
	this.addSubMenu = function(parent, number, menuname) {
		var top = (number-1) * (entryHeight);
		this.subs[menuname]=new SubMenu(menuname, this.subs[parent].left + entryWidth, this.subs[parent].color, top);
	}
	
	this.addEntry = function(menuname, text, href) {
		this.subs[menuname].entries[this.subs[menuname].entries.length]=new Entry(text, href, this.subs[menuname], this.subs[menuname].entryCount, '');
		this.subs[menuname].entryCount++;
	}
	
	this.addSubEntry = function(menuname, text, href, submenu) {
		this.subs[menuname].entries[this.subs[menuname].entries.length]=new Entry(text, href, this.subs[menuname], this.subs[menuname].entryCount, submenu);
		this.subs[menuname].entryCount++;
	}
	
	this.findEntry = function(left, top) {
		for (eachMenu in this.subs) {
			for (eachEntry in this.subs[eachMenu].entries) {
				if (this.subs[eachMenu].active==true) {
					if (left>=this.subs[eachMenu].entries[eachEntry].absLeft&&left<=this.subs[eachMenu].entries[eachEntry].absRight&&top>=this.subs[eachMenu].entries[eachEntry].absTop&&top<=this.subs[eachMenu].entries[eachEntry].absBottom) {
							return this.subs[eachMenu].entries[eachEntry];
					}
				}
			}
		}
		return null;
	}
	
	this.mousemove = function(e) {
		if (ie) {
			mouseX = window.event.clientX + document.body.scrollLeft;
    		mouseY = window.event.clientY + document.body.scrollTop;
		} else {
			mouseX = e.pageX;
			mouseY = e.pageY;
		}
	}
	
	this.rollover = function() {
		if (navBar.findEntry(mouseX,mouseY)) {
			var objRef=navBar.findEntry(mouseX,mouseY);
			objRef.parent.openMenu();
			if (ie||dom) objRef.ref.style.visibility='hidden';
			else objRef.ref.visibility='hidden';
			if (ie||dom) objRef.overRef.style.visibility='visible';
			else objRef.overRef.visibility='visible';
			if (objRef.submenu!='') navBar.subs[objRef.submenu].openMenu();
		}
	}
	
	this.goLink = function() {
		if (navBar.findEntry(mouseX,mouseY)) {
			window.top.location.href=navBar.findEntry(mouseX,mouseY).href;
		}
	}
	
	
	this.reset = function() {
		for (eachMenu in this.subs) {
		if (this.subs[eachMenu].active==true)
			this.subs[eachMenu].closeMenu(eachMenu);
		}
	}
	
	this.initMenu = function() {
		if (dom||ie||ns) {
			this.buildRefs();
			this.position();
			if (ie||ns) {
				if (ns) document.captureEvents(Event.MOUSEMOVE);
				document.onmousemove=this.mousemove;
			} else {
				document.addEventListener("mousemove",this.mousemove,false);
			}
			setInterval('navBar.mainControl()',300);
		}
		loaded=true;
	}
	
	this.mainControl = function() {
		navBar.rollover();
		if (!navBar.findEntry(mouseX,mouseY)&&!navBar.buttonOver) {
			navBar.reset();
		}
	}
	
}

// object for a single menu //
function SubMenu(name,left,color,top, sep1, sep2) {
	this.active=false;
	this.name=name;
	this.entries=new Array;
	this.left=left;
	this.top=top;
	this.color=color;
	this.entryCount=0;
	this.sep1=sep1;
	this.sep2=sep2;
	
	this.output = function() {
		var entryHtml='';
		entryHtml+='<DIV ID="nav_top_' + this.name + '" CLASS="entry">';
		entryHtml+='<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0" WIDTH="' + entryWidth + '" HEIGHT="1" BGCOLOR="white">';
		entryHtml+='<TR>';
		entryHtml+='	<TD BGCOLOR="' + this.color + '" COLSPAN="3" WIDTH="1"><IMG SRC="/images/spacer.gif" BORDER="0" WIDTH="' + entryWidth + '" HEIGHT="1"></TD>';
		entryHtml+='	<TD BGCOLOR="' + this.color + '"><IMG SRC="/images/spacer.gif" BORDER="0" WIDTH="1" HEIGHT="1"></TD>';
		entryHtml+='</TR>';
		entryHtml+='</TABLE>';
		entryHtml+='</DIV>';
		for (eachEntry in this.entries) {
			entryHtml+='<DIV ID="nav_' + this.name + this.entries[eachEntry].number + '" CLASS="entry">';
			entryHtml+=this.entries[eachEntry].output();
			entryHtml+='</DIV>';
			entryHtml+='<DIV ID="overnav_' + this.name + this.entries[eachEntry].number + '" CLASS="entry">';
			entryHtml+=this.entries[eachEntry].overOutput();
			entryHtml+='</DIV>';
		}
		return entryHtml;
	}
	
	this.openMenu = function() {
		if (ie) topRef = eval('document.all.nav_top_' + this.name);
		if (ns) topRef = eval('document.layers.nav_top_' + this.name);
		if (dom) topRef = eval('document.getElementById("nav_top_' + this.name + '")');
		if (ie||dom) topRef.style.visibility='visible';
			else topRef.visibility='visible';
		this.active=true;
			for (eachEntry in this.entries) {
				this.entries[eachEntry].show();
				if (this.entries[eachEntry].submenu!='') navBar.subs[this.entries[eachEntry].submenu].closeMenu();
			}
	}
	
	this.closeMenu = function(name) {
		if (ie) topRef = eval('document.all.nav_top_' + this.name);
		if (ns) topRef = eval('document.layers.nav_top_' + this.name);
		if (dom) topRef = eval('document.getElementById("nav_top_' + this.name + '")');
		if (ie||dom) topRef.style.visibility='hidden';
		else topRef.visibility='hidden';
		this.active=false;
		if (eval('document.images.nav_' + this.name)) {
			eval('document.images.nav_' + this.name).src=imagePath + 'nav_' + this.name + '.gif';
		}
		// hide em all
		if (this.sep1) eval('document.images.nav_sep_' + this.sep1).src = imagePath + 'nav_separator.gif';
	    if (this.sep2) eval('document.images.nav_sep_' + this.sep2).src = imagePath + 'nav_separator.gif';
		for (eachEntry in this.entries) {
			this.entries[eachEntry].hide();
		}
	}
	
	this.position = function() {
	if (ie) topRef = eval('document.all.nav_top_' + this.name);
	if (ns) topRef = eval('document.layers.nav_top_' + this.name);
	if (dom) topRef = eval('document.getElementById("nav_top_' + this.name + '")');
	if (ie||dom) {
				topRef.style.left=(menuLeftOffset + this.left) + 'px';
				topRef.style.top=(menuTopOffset + this.top - 1) + 'px';
			} else {
				topRef.moveTo(menuLeftOffset + this.left, menuTopOffset + this.top -1);
	}
		for (eachEntry in this.entries) {
			this.entries[eachEntry].position();
		}
	}
	
}

// object for a single entry //
function Entry(text, href, parent, number, submenu) {
	this.parent=parent;
	this.number=number;
	this.text=text;
	this.href=href;
	this.ref=null;
	this.overRef=null;
	this.submenu=submenu;
	this.absLeft=0;
	this.absRight=0;
	this.absTop=0;
	this.absBottom=0;
	
	this.overOutput = function() {
		var entryHtml='';
		entryHtml+='<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0" WIDTH="' + (entryWidth + 1) + '" HEIGHT="' + entryHeight + '" BGCOLOR="' + this.parent.color + '">';
		entryHtml+='<TR>';
		entryHtml+='	<TD CLASS="entryTextOver">&nbsp;' + this.text + '</TD>';
		entryHtml+='</TR>';
		entryHtml+='</TABLE>';
		return entryHtml;
	}
	
	
	this.output = function() {
		var entryHtml='';
		var widthStr=(ns)?'WIDTH="100%"':'';
		entryHtml+='<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0" WIDTH="' + entryWidth + '" HEIGHT="' + entryHeight + '" BGCOLOR="white">';
		entryHtml+='<TR>';
		entryHtml+='	<TD BGCOLOR="' + this.parent.color + '" WIDTH="1"><IMG SRC="/images/spacer.gif" BORDER="0" WIDTH="1" HEIGHT="' + (entryHeight-1) + '"></TD>';
		if (this.submenu=='') {
			entryHtml+='	<TD WIDTH="' + (entryWidth-2) + '" CLASS="entryText">&nbsp;' + this.text + '</TD>';
			entryHtml+='	<TD ' + widthStr + '>&nbsp;</TD>';
		} else {
			entryHtml+='	<TD WIDTH="' + (entryWidth-12) + '" CLASS="entryText">&nbsp;' + this.text + '</TD>';
			entryHtml+='	<TD WIDTH="10" ALIGN="right"><IMG SRC="' + imagePath + 'arrow_small.gif" WIDTH="10" HEIGHT="10" BORDER="0"></TD>';
		}
		entryHtml+='	<TD BGCOLOR="' + this.parent.color + '" WIDTH="1"><IMG SRC="clear.gif" BORDER="0" WIDTH="1" HEIGHT="' + (entryHeight-1) + '"></TD>';
		entryHtml+='</TR>';
		entryHtml+='<TR>';
		entryHtml+='	<TD BGCOLOR="' + this.parent.color + '" COLSPAN="3" WIDTH="1"><IMG SRC="clear.gif" BORDER="0" WIDTH="' + entryWidth + '" HEIGHT="1"></TD>';
		entryHtml+='	<TD BGCOLOR="' + this.parent.color + '"><IMG SRC="/images/spacer.gif" BORDER="0" WIDTH="1" HEIGHT="1"></TD>';
		entryHtml+='</TR>';
		entryHtml+='</TABLE>';
		return entryHtml;
	}
	
	this.getRef = function(which) {
		if (ie) return 'document.all.' + which + 'nav_' + this.parent.name + this.number;
		if (ns) return 'document.layers.' + which + 'nav_' + this.parent.name + this.number;
		if (dom) return 'document.getElementById("' + which + 'nav_' + this.parent.name + this.number + '")';
	}
	
	this.position = function() {
			var top=this.absTop;
			var left=this.absLeft;
			if (ie||dom) {
				this.ref.style.left=left + 'px';
				this.ref.style.top=top + 'px';
			} else {
				this.ref.moveTo(left,top);
			}
			if (ie||dom) {
				this.overRef.style.left=left + 'px';
				this.overRef.style.top=top + 'px';
			} else {
				this.overRef.moveTo(left,top);
			}
	}
	
	this.show = function() {
		if (ie||dom) this.ref.style.visibility='visible';
		else this.ref.visibility='visible';
		if (ie||dom) this.overRef.style.visibility='hidden';
		else this.overRef.visibility='hidden';
	}
	
	this.hide = function() {
		if (ie||dom) this.ref.style.visibility='hidden';
		else this.ref.visibility='hidden';
		if (ie||dom) this.overRef.style.visibility='hidden';
		else this.overRef.visibility='hidden';
	}
}

// preload nav images //
arrImages=new Array
for (i=0;i<document.images.length; i++) {
	if (document.images[i].name.indexOf('nav')!=-1) {
		arrImages[arrImages.length]=new Image;
		arrImages[arrImages.length].src=imagePath + document.images[i].name + '-over.gif';
	}
}

// rollover / rollout functions //
function on(img,sep1,sep2) {
	navBar.reset();
	eval('document.images.nav_' + img).src=imagePath + 'nav_' + img + '.gif';
	//if (sep1) {
	//	eval('document.images.nav_sep_' + sep1).src = '/images/nav_sep.gif';
	//}
	//if (sep2) {
	//	eval('document.images.nav_sep_' + sep2).src = '/images/nav_sep.gif';
	//}
	if (loaded==true&&navBar.subs[img]) {
		navBar.buttonOver=true;
		navBar.subs[img].openMenu();
	}
}

function off(img,sep1,sep2) {
	if (!navBar.subs[img]) {
		eval('document.images.nav_' + img).src=imagePath + 'nav_' + img + '.gif';
		if (sep1) eval('document.images.nav_sep_' + sep1).src = imagePath + 'nav_separator.gif';
	    if (sep2) eval('document.images.nav_sep_' + sep2).src = imagePath + 'nav_separator.gif';
	} else {
		navBar.buttonOver=false;
	}
}

var navBar=new Menu();
populateMenu();
