//creates the menubar object
function menubar(top)
{
	this.top		= top
	this.name		= "menubar"
	this.visibility = 'inherit'
	this.zIndex		= null
	this.obj		= this.name+"Object"
	eval(this.obj + "=this")
	//items - each drop-down
	this.items		= new Array()
	//subitems - each menu item
	this.subitems	= new Array()
	//itemH - size of each item
	this.itemH		= 12
	//itemSpacing - spacing between each item
	this.itemSpacing = 1
	//w - width of the menu
	this.w			= menuWidth
	this.indent 	= 5
}

{
var p=menubar.prototype
	//all functions that are called on the menubar object
	p.add = MenuAdd
	p.build = MenuBuild
	p.activate = menubarActivate
	p.subadd = SubMenuAdd
	//mouseout, mouseover & mousedown in netscape 4 - functions are below
	p.out=menuOut
	p.over=menuOver
	p.down=menuDown
}


// these three functions only used by netscape 4 ************
function menuOver(i)
{
	if (!this.subitems[i].selected)
	{
		this.subitems[i].lyr.setbg(menuOverBgColor)
		this.subitems[i].lyr.write(this.subitems[i].textSelected)
	}
}

function menuOut(i)
{
	if (!this.subitems[i].selected)
	{
		this.subitems[i].lyr.setbg(menuBgColor)
		this.subitems[i].lyr.write(this.subitems[i].textNormal)
	}
}

function menuDown(i)
{
	if (!this.subitems[i].selected)
	{
		doGo(this.subitems[i].link)
	}
}

function DivLayerSetbg(color)
{
	this.doc.bgColor = color
}
// **********************************************************


// this is run after you've loaded all the items and subitems - runs from the toolbarScript page
// it's run by all browsers, but it only does stuff for netscape 4
function menubarActivate() {

	if (!this.activated)
	{
		if (is.ns4 )
		{
			//loops through each menu and makes a layer object that gets hidden (hideV function)
			//when the mouse is moved out
			for (var i=0;i<this.items.length;i++)
			{   
				this.items[i].lyr = new DivLayer('menu'+i)
				if (is.ns) this.items[i].lyr.event.onmouseout = new Function('hideV();')
			}
			
			//makes a layer object for each subitem and controls the mouseover, out and down events for those layers
			for (var i=0;i<this.subitems.length;i++)
			{
				this.subitems[i].lyr = new DivLayer('submenu'+i,this.subitems[i].parentname)
				this.subitems[i].lyr.setbg = DivLayerSetbg
				this.subitems[i].lyre = new DivLayer('submenuC'+i,this.subitems[i].parentname)
				if (is.ns) this.subitems[i].lyre.event.captureEvents(Event.MOUSEDOWN)
				this.subitems[i].lyre.event.onmouseover = new Function(this.obj+'.over('+i+'); return false;')
				this.subitems[i].lyre.event.onmouseout = new Function(this.obj+'.out('+i+'); return false;')
				this.subitems[i].lyre.event.onmousedown = new Function(this.obj+'.down('+i+'); return false;')
			} 
			
			this.activated=true
		} 
		else if ( is.ie || is.ns5) 
		{
			for (var j=0;j<this.items.length;j++)
			{   
				//this.items[j].lyr = new DivLayer('menu'+j)
				//	this.items[j].lyr.event.onmouseout = new Function('hideV();')
			}
			this.activated=true
		}
	}
}

function MenuAdd(title,link)
{
	var i = this.items.length
	this.items[i] = new Array()
	this.items[i].title = title
	this.items[i].link = link
	this.items[i].titlelength = title.length
	this.items[i].h = 2
	this.items[i].top=3	
}

var menuCount

function SubMenuAdd(menutext,link,title)
{
	var i = this.subitems.length
	var subcount = 0
	this.subitems[i] = new Array()
	this.subitems[i].menutext = menutext
	this.subitems[i].parentname = this.items.length - 1
	this.subitems[i].parentname = 'menu'+this.subitems[i].parentname
	this.subitems[i].link = link
	this.subitems[i].extraLines = 0
	this.subitems[i].h = 0	

	//counts all the subitems for that menu
	for (var j=0;j<this.subitems.length;j++)
	{
		if ( menutext == this.subitems[j].menutext )
		{
			subcount++
		}
	}
	
	subcount = subcount - 1

	//if the text is too long for a menu item, you need to separate with commas so there is an extra argument
	if (arguments.length>3)
	{
		this.subitems[i].textNormal = '<div class="'+this.name+'TextNormal"><font face="'+font+'" color="'+menuFontColor+'" >'
		this.subitems[i].textSelected = '<div class="'+this.name+'TextSelected"><font face="'+font+'" color="'+menuOverFontColor+'">'
		this.subitems[i].title = arguments[2]
		this.subitems[i].textNormal += arguments[2]
		this.subitems[i].textSelected += arguments[2]
		
		//adds a <br> for every extra argument
		for (var j=3;j<arguments.length;j++)
		{
			this.subitems[i].extraLines = this.subitems[i].extraLines + 1
			this.subitems[i].title += '&nbsp;'+arguments[j]
			this.subitems[i].textNormal += '<BR>'+arguments[j]
			this.subitems[i].textSelected += '<BR>'+arguments[j]
		}
		
		this.subitems[i].textNormal += '</font></div>'
		this.subitems[i].textSelected += '</font></div>'
		
		//loop through all the menus, find the right one, and set co-ordinates
		for (var j=0;j<this.items.length;j++)
		{
			if ( menutext == this.items[j].title )
			{
				this.subitems[i].y = this.items[j].top
				this.subitems[i].h = ((this.itemH)*(this.subitems[i].extraLines+1))
				this.items[j].h += (this.subitems[i].h)+2
				this.items[j].top = (this.items[j].h)+this.itemSpacing
			}
		}
	
	}
	else
	{
		this.subitems[i].title = title
		this.subitems[i].textNormal = '<div class="'+this.name+'TextNormal"><font face="'+font+'"  color="'+menuFontColor+'" >'+title+'</font></div>'
		this.subitems[i].textSelected = '<div class="'+this.name+'TextSelected"><font face="'+font+'" color="'+menuOverFontColor+'">'+title+'</font></div>'
 		this.subitems[i].extraLines = 0
 		
 		for (var j=0;j<this.items.length;j++)
 		{
 			if ( menutext == this.items[j].title )
 			{
				this.subitems[i].y = this.items[j].top
				this.subitems[i].h = (this.itemH)
				this.items[j].h += this.subitems[i].h+2
				this.items[j].top = (this.items[j].h+this.itemSpacing)
			}
		}
	}
}

var char34 = String.fromCharCode(34);

function MenuBuild()
{
	var divleft = 0
 	var nowDiv = 0
	var hassubs=false
	menuCount = this.items.length - 1
	this.div = "<style>.s{font-family:verdana;font-size:12px;font-weight:bold;color:#ffffff;cursor:default}</style>\n"
	if (is.ie || is.ns5)
	{
		this.div += "<style>.mxz{font-family:"+font+";font-size:"+fontSize+";color:"+menuFontColor+";font-weight:"+fontWeight+";background:"+menuBgColor+";padding:"+cellPadding+";cursor:default}</style>\n<style>.s{font-family:"+topfont+";font-size:"+topfontSize+";font-weight:"+topfontWeight+";cursor:default}</style>";
		if (!is.ns5)
		{
			this.div +="<SCRIPT event=onclick() for=document>hideV();</SCRIPT>"
		}
		
		//loops through all menus
		for (var i=0;i<this.items.length;i++)
		{
			//sets hassubs to true if it has subitems
			for (var j=0;j<this.subitems.length;j++) 
			{
				if ( this.subitems[j].menutext == this.items[i].title ) 
				{
					hassubs=true
				}
			}
			
			//if there are no subs it makes a div with no style - you have to make a layer otherwise the functions will crash
			if ( hassubs==true )
			{
				this.div += "<div style="+char34+"position:absolute;left:0;top:23;z-index:3;display:none;"+char34+" id="+char34+"menu"+i+""+char34+" ><table width="+char34+""+menuWidth+""+char34+" cellspacing="+char34+""+frameBorderWidth+""+char34+" border=0 ><tr><td colspan=3 height=1></td></tr><tr><td width=100 onmouseover=hideV()></td><td bgcolor="+char34+""+menuFrameColor+""+char34+"><table width="+char34+""+menuWidth+""+char34+" cellspacing="+char34+""+frameBorderWidth+""+char34+" border=0>\n";
			} 
			else
			{
				this.div += "<div id="+char34+"menu"+i+""+char34+">"
			}
			
			//foreach subitem it makes a new table row
			for (var j=0;j<this.subitems.length;j++) 
			{
				if ( this.subitems[j].menutext == this.items[i].title ) 
				{
					this.div += "<tr><td class=mxz onclick=doGo('"+this.subitems[j].link+"') onmouseover=ov(this) onmouseout=ou(this)>"+this.subitems[j].title+"</td></tr>\n";
 				}
			}
			
			// if there's no sub items, it closes the div, if there are subitems it closes the table
			if ( hassubs==true ) 
			{
				this.div += "</table></td><td width=100 onmouseover=hideV()></td></tr><tr><td colspan=3 height=200 onmouseover=hideV()></td></tr></table></div>";
			} 
			else 
			{
				this.div += "</div>";
			}
		}

		document.write(this.div)
	} 
	else if (is.ns4) 
	{
		var currenttop;
		var currentwidth;
		//stylesheet for the whole menubar (not really effective)
		this.css = '<STYLE type="text/css">\n'
		this.css += '.'+this.name+'TextNormal {font-family:"'+font+'"; fontsize:'+fontSize+'pt; color:'+menuFontColor+'; background-color:'+menuBgColor+'; margin-left:'+this.indent+'px;}\n'+
		'.'+this.name+'TextSelected {font-family:"'+font+'"; fontsize:'+fontSize+'pt; color:'+menuOverFontColor+'; background-color:'+menuOverBgColor+'; margin-left:'+this.indent+'px;}\n'
		this.css += '#'+this.name+' {position:absolute; left:0px; top:'+this.top+'px; visibility:show;}\n'
		this.div='<div id="'+this.name+'">\n'
		this.div += "</div>"
		
		//makes a stylesheet and div for each menu
		for (var i=0;i<this.items.length;i++)
		{
			this.css += '#menu'+i+' {position:absolute; left:23px; top:'+this.top+15+'px; width:'+this.w+'px; height:'+this.items[i].h+'px; clip:rect(0px '+this.w+'px '+this.items[i].h+'px 0px); layer-background-color:'+menuFrameColor+'; visibility:hide;}\n';
			this.div += "<div id="+char34+"menu"+i+""+char34+">\n";
			//makes a div and stylesheet for each subitem
			for (var j=0;j<this.subitems.length;j++) 
			{
				if ( this.subitems[j].menutext == this.items[i].title ) 
				{
					currenttop = this.subitems[j].y-1;
					currentwidth = this.w-4;
					this.css += '#submenu'+j+' {position:absolute; left:2px; top:'+currenttop+'px; width:'+currentwidth+'px; height:'+this.subitems[j].h+'px; clip:rect(0px '+currentwidth+'px '+this.subitems[j].h+'px 0px); layer-background-color:'+menuBgColor+';}\n'
					this.css += '#submenuC'+j+' {position:absolute; left:2px; top:'+currenttop+'px; width:'+currentwidth+'px; height:'+this.subitems[j].h+'px; clip:rect(0px '+currentwidth+'px '+this.subitems[j].h+'px 0px);}\n'
					this.div += '<div id="submenu'+j+'">'+this.subitems[j].textNormal+'</div>\n'
					this.div += '<div id="submenuC'+j+'"></div>\n'
				 }
			}
			this.div += "</div>";
		}
		this.css += '</STYLE>'
		document.write(this.css);
		document.write(this.div);
	}
}

//closes the open menu
function hideV()
{
	var z = openmenu
	if ( z >= 0 ) 
	{
		if(is.ie)
		{
  			eval("menu"+z+"").style.display='none';
  			clearTimeout(myTimer);
		} 
		else if (is.ns5) 
		{
			var menu = document.getElementById('menu'+z);
			clearTimeout(myTimer);
			menu.style.display="none";
		} 
		else if (is.ns4) 
		{
			eval('document.menu'+z+'.visibility="hide"');
		}
	}
}

var myTimer
var hidemenu = true


// change the background(highlight) color of menu items when there is a mouseover (over and out)
function ov(ok) 
{
	ok.style.background=menuOverBgColor;
	ok.style.color=menuOverFontColor;
	hidemenu = false
	clearTimeout(myTimer)
}
function ou(ok) 
{
	
	hideTimer();
	hidemenu = true
	ok.style.background=menuBgColor;
	ok.style.color=menuFontColor;
}


//hides menu after interval 
function hideTimer() 
{
   
   if ( hidemenu == true ) 
   {
		hideV();
	}
  
   myTimer = setTimeout("hideTimer()",1000)
}

// sends you to the link
function doGo(ok) 
{
	if ( ok.length > 0 ) 
	{ 
		var tgt=target;
		if(tgt=='newWindow')
		{
    		hideV();
			window.open(ok)
		} 
		else 
		{
			hideV();
			document.location.href=ok
		}
	}
}

// point object used to find the coordinates of the images on the top menu
function Point(iX, iY) 
{
	this.x = iX;
	this.y = iY;
}

// function that gets those coordinates - aTag is the ID of the image
function fGetXY(aTag) 
{
  	var oTmp = aTag;
  	var pt = new Point(0,0);
  	if ( is.ie ) 
  	{
	   	do
	   	{
			pt.x += oTmp.offsetLeft;
			pt.y += oTmp.offsetTop;
			oTmp = oTmp.offsetParent;
		} while(oTmp.tagName!="BODY");
	} 
	else if ( is.ns4 ) 
	{
		pt.x =  oTmp.pageX;
		pt.y = oTmp.pageY // + oTmp.document.height; 
  	} 
  	else if ( is.ns5) 
  	{
		//pt.x = oTmp.offsetLeft;
  		//pt.y = oTmp.offsetTop;

		//New Code
	   	do
	   	{
			pt.x += oTmp.offsetLeft;
			pt.y += oTmp.offsetTop;
			oTmp = oTmp.offsetParent;
		} while(oTmp.tagName!="BODY");
	}
	else
  	{
  		pt.x = oTmp.offsetLeft;
  		pt.y = oTmp.offsetTop;
	}
  	return pt;
}

// the big one
// z= number of the menu to be dropped
// span= ID of the span of the image
function show(z,span)
{
		hidemenu 	= false

		// if the user didn't put in the values for droplength or drop left, but in the default values
		if (typeof droplength == 'undefined')
		{
			droplength = 14
		}
		if (typeof dropleft == 'undefined') 
		{
			dropleft = 15
		}

		if(is.ie) 
		{
			if (is.ie4)
			{
				//ie 4 wont pull down the variable for the span string so use
				// arguments[1] to get it.
				
				var span = eval('document.all.'+arguments[1]);
				var point = fGetXY(span);
			} 
			else 
			{
				// find the point for the span
				var span = document.all[span];
				var point = fGetXY(span);
			}
			
			var thisdropleft 	= dropleft
			var thisdroplength 	= droplength
			var size 			= eval(point.x+parseInt(menuWidth))
			// if the menu is off the screen, bring it back
			// scrollLeft = amount that the bottom scrollbar is open
			if (size >= document.body.clientWidth)
			{
				point.x = point.x - (size - document.body.clientWidth) + document.body.scrollLeft - 8;
			}
			
			point.y = point.y + thisdroplength
			point.x = point.x + thisdropleft
			
			eval("menu"+z+"").style.left=point.x; // window.event.clientX-150+document.body.scrollLeft;
			eval("menu"+z+"").style.top=point.y; // window.event.clientX-150+document.body.scrollLeft;
			eval("menu"+z+"").style.display="block";
		} 
		else if (is.ns4)
		{
			var span = document.layers[span];
			var point = fGetXY(span); 
			var size = eval(point.x+parseInt(menuWidth))
			if (size >= window.innerWidth) 
			{
				point.x = point.x - (size - window.innerWidth) - 20 + pageXOffset;
			}
		
			var thisdropleft = dropleft + 4
			var thisdroplength = droplength + 3
		
			var thisleft = point.x-thisdropleft;
			var thistop = point.y + thisdroplength;
			eval('document.menu'+z+'.left="'+thisleft+'"');
  			eval('document.menu'+z+'.top="'+thistop+'"');
 			eval('document.menu'+z+'.visibility="show"');	
 		
 			//the spantwo variable is highest layer button (about us)  all the dropdowns must be put above this layer.
			var droplayer = eval('document.menu'+z+'');
			var spantwo = document.layers['menuspan6'];
			droplayer.moveAbove(spantwo); //move this dropdown above that highest layer
		} 
		else if (is.ns5) 
		{
			// Original code
			var elm =  eval(document.getElementById(span));
			var point = fGetXY(elm); 

			var size = eval(point.x+parseInt(menuWidth))

			if (size >= window.innerWidth)
			{
				point.x = point.x - (size - window.innerWidth) - 26 + window.scrollX;
    		}
		
			var thisdropleft = dropleft
			var thisdroplength = droplength - 1
		
			point.y = point.y + thisdroplength
			point.x = point.x + thisdropleft
			
			var menu = document.getElementById('menu'+z);

			menu.style.left=point.x+"px";
			menu.style.top=point.y+"px";
			menu.style.display="";
		}
		
		openmenu=z
}

var openmenu = 0

function BrowserCheck() 
{
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.version = navigator.appVersion
	this.v = parseInt(this.version)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ns6 = (this.b=="ns" && this.v==6)
	this.ns7 = (this.b=="ns" && this.v==7)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie5gr = (this.b=="ie" && this.v>=5)
	this.ie4 = (this.version.indexOf('MSIE 4')>0)
	this.ie5 = (this.version.indexOf('MSIE 5')>0)
    this.min = (this.ns||this.ie)

}

is = new BrowserCheck()

// creates a netscape layer object for each menu and each menu item
// id = ID of the div/layer
function DivLayer(id,menuname) 
{
	if (is.ns4) 
	{
		// funky IF statement - if menuname exists ? do this : else do that
 		this.css = (menuname)? eval("document."+menuname+".document."+id) : document.layers[id]
		this.elm = this.event = this.css
		this.doc = this.css.document
		this.zindex = this.css.zIndex
	} else if ( is.ie ) 
	{
	   var menulayer = document.all[id]
	   this.css = menulayer.style
	   this.elm = this.event = menulayer
	   this.doc = document
	}
}

// Write Method
// replaces the text in a layer - in netscape on mouseover the text 
// has to be replaced with text of a different color.
function DivLayerWrite(html) 
{
	if (is.ns4) 
	{
		this.doc.open()
		this.doc.write(html)
		this.doc.close()
	}	
}

DivLayer.prototype.write = DivLayerWrite

function handleResize() 
{
	location.reload()
	return false;
}

if ( is.ns4 ) 
{
	window.captureEvents(Event.RESIZE);
 	window.onresize = handleResize
}

// the big one
// z= number of the side menu to be dropped
// span= ID of the span of the image
function showSide(z,span)
{
		hidemenu = false

		// if the user didn't put in the values for droplengthSide or drop left, but in the default values
		if (typeof droplengthSide == 'undefined')
		{
			droplengthSide = 14
		}
		if (typeof dropleftSide == 'undefined') 
		{
			dropleftSide = 15
		}

		if(is.ie) 
		{
			if (is.ie4)
			{
				//ie 4 wont pull down the variable for the span string so use
				// arguments[1] to get it.
				
				var span = eval('document.all.'+arguments[1]);
				var point = fGetXY(span);
			} 
			else 
			{
				// find the point for the span
				var span = document.all[span];
				var point = fGetXY(span);
			}
			
			var thisdropleftSide 	= dropleftSide
			var thisdroplengthSide	= droplengthSide
			var size 				= eval(point.x+parseInt(menuWidth))
			// if the menu is off the screen, bring it back
			// scrollLeft = amount that the bottom scrollbar is open
			if (size >= document.body.clientWidth)
			{
				point.x = point.x - (size - document.body.clientWidth) + document.body.scrollLeft - 8;
			}
			
			point.y = point.y + thisdroplengthSide
//			point.x = point.x + thisdropleftSide
			point.x = thisdropleftSide
			
			eval("menu"+z+"").style.left=point.x; // window.event.clientX-150+document.body.scrollLeft;
			eval("menu"+z+"").style.top=point.y; // window.event.clientX-150+document.body.scrollLeft;
			eval("menu"+z+"").style.display="block";
		} 
		else if (is.ns4)
		{
			var span = document.layers[span];
			var point = fGetXY(span); 
			var size = eval(point.x+parseInt(menuWidth))
			if (size >= window.innerWidth) 
			{
				point.x = point.x - (size - window.innerWidth) - 20 + pageXOffset;
			}
		
			var thisdropleftSide = dropleftSide + 4
			var thisdroplengthSide = droplengthSide + 3
		
			var thistop = point.y + thisdroplengthSide;
//			var thisleft = point.x-thisdropleftSide;
			var thisleft = thisdropleftSide;

			eval('document.menu'+z+'.left="'+thisleft+'"');
  			eval('document.menu'+z+'.top="'+thistop+'"');
 			eval('document.menu'+z+'.visibility="show"');	
 		
 			//the spantwo variable is highest layer button (about us)  all the dropdowns must be put above this layer.
			var droplayer = eval('document.menu'+z+'');
			var spantwo = document.layers['menuspan6'];
			droplayer.moveAbove(spantwo); //move this dropdown above that highest layer
		} 
		else if (is.ns5) 
		{
			// Original code
			var elm =  eval(document.getElementById(span));
			var point = fGetXY(elm); 

			var size = eval(point.x+parseInt(menuWidth))

			if (size >= window.innerWidth)
			{
				point.x = point.x - (size - window.innerWidth) - 26 + window.scrollX;
    		}
		
			var thisdropleftSide = dropleftSide
			var thisdroplengthSide = droplengthSide - 1
		
			point.y = point.y + thisdroplengthSide
//			point.x = point.x + thisdropleftSide
			point.x = thisdropleftSide + 16 ;
			
			var menu = document.getElementById('menu'+z);

			menu.style.left=point.x+"px";
			menu.style.top=point.y+"px";
			menu.style.display="";
		}
		
		openmenu=z
}