/* ##### YAJSM 1.0 ##### */ 
var menubar;
var currentItem;
var allMenus = new Array();
var timeout
function Menu(){
	this.appendItem = appendItem;
}

function MainMenu(){
	this.level = 0;
	this.items = new Array();
	this.div = document.getElementById('menubar');
}
Menu.prototype.hideChilds = function () {
	//alert('curLvl'+this.level);
	for(var i=0; i<allMenus.length; i++){
	//alert(allMenus[i].level)
		if(allMenus[i].level > this.level){
		 allMenus[i].div.style.visibility='hidden';
		}
	}	
	
}

function hideAllChilds(){
	for(var i=0; i<allMenus.length; i++){
		 allMenus[i].div.style.visibility='hidden';
	}	
}

function DropDownMenu(){
	this.level = 0;
	this.items = new Array();
	this.div = document.createElement('div');
	this.div.style.position='absolute';
	this.div.style.visibility='hidden';
	document.body.insertBefore(this.div,document.getElementById('menubar'));

	this.parentMenu;
	
}
MainMenu.prototype = new Menu()
DropDownMenu.prototype = new Menu()

DropDownMenu.prototype.show = function () {
	this.div.style.visibility='visible';
}

Menu.prototype.createLink = function (item) {
	var a = document.createElement('a');
	a.innerHTML=item.label;
	a.item = item;
	if(this.level==0){
		a.className = "mainmenu_a";
	}else{
		a.className = "dropdownmenu_a";	
	}
	window.status = a.innerHTML
	a.onmouseover=function() {
//		window.clearTimeout(timeout);
		this.item.parentMenu.hideChilds();
		if (this.item.getMenu()) { 
			this.item.getMenu().show();
		}
		currentItem=this.item;
		if(this.className=="dropdownmenu_a"){
			this.className="dropdownmenu_a_hover";
		}
	}
	a.onmouseout=function() {
//		timeout = window.setTimeout("hideAllChilds()",2000);
		if(this.className=="dropdownmenu_a_hover"){
			this.className="dropdownmenu_a";
		}
	}
	item.a = a;
	a.href=item.link;
	this.div.appendChild(a);
	if(this.level!=0){
	var td_drop = document.createElement("TD");
	td_drop.className = "dropdownmenu_td";
	td_drop.onclick=function() {
		window.location = item.link
	}
	
	td_drop.onmouseover=function() {
	if(a.className=="dropdownmenu_a"){
			a.className="dropdownmenu_a_hover";
		}
	}
	td_drop.onmouseout=function() {
		if(a.className=="dropdownmenu_a_hover"){
			a.className="dropdownmenu_a";
		}
	}
	
	var nowrap = document.createAttribute("align");
	var nowrap = document.createAttribute("src");
		nowrap.nodeValue="nowrap";
		td_drop.setAttributeNode(nowrap)
	td_drop.appendChild(a);	
	}else{
		var td_drop = a;
	}
	return(td_drop)
}

DropDownMenu.prototype.display=function (){
	var div = this.div;


	var table = document.createElement("Table");
	table.border ="0"
	table.className = "dropdownmenu_table";
	table.cellPadding = "0"
	table.cellSpacing = "0"		
	var tablebody = document.createElement("TBODY");
  	table.appendChild(tablebody);
	this.div.appendChild(table);
	for(var i=0; i<this.items.length; i++){
		var a = this.createLink(this.items[i]);
		var tr_drop = document.createElement("TR");

		tr_drop.onmouseover=function() {
				window.clearTimeout(timeout);
				this.className = "dropdownmenu_td_hover";
		}
		tr_drop.onmouseout=function() {
				timeout = window.setTimeout("hideAllChilds()",2000);
				this.className = "dropdownmenu_td";
		}
		if (this.items[i].getMenu()!=null){
			this.items[i].getMenu().display();
		}
		tr_drop.appendChild(a);
		var td_dropx = document.createElement("TD");
			td_dropx.width = "1"
			td_dropx.className = "dropdownmenu_td";
			var img = document.createElement("img");
  			var src = document.createAttribute("src");
			var align = document.createAttribute("align");
			if (this.items[i].getMenu()!=null){
				src.nodeValue = "images/shaft.png";
			}else{
				src.nodeValue = "images/shim.png";			
			}
			align.nodeValue="absmiddle";
   			img.setAttributeNode(align);
   			img.setAttributeNode(src);
			td_dropx.appendChild(img)
			tr_drop.appendChild(td_dropx);				
		tablebody.appendChild(tr_drop, null);
	}
}
DropDownMenu.prototype.layout=function (){
	for(var i=0; i<this.items.length; i++){
		var left =this.div.offsetLeft+this.div.offsetWidth
		if (this.items[i].getMenu()!=null){
			var left =this.div.offsetLeft+this.div.offsetWidth
			this.items[i].getMenu().div.style.left = left;
			this.items[i].getMenu().div.style.top=(i*18) + 130
			this.items[i].getMenu().layout();
		}
	}
}
function Item(label,link){
	this.label=label;
	this.link=link;
	this.menue;
	this.parentMenu;
	this.setMenu = setMenu;
	this.getMenu = getMenu;
}
function getMenu(){
	return this.menue;
}
function setMenu(menu) {
	menu.level =  this.parentMenu.level + 1;
	allMenus.push(menu);
	menu.parentItem=this
	this.menue=menu;
	return menu;
}
MainMenu.prototype.display=function(){
	var labels = ""
	tbl = document.createElement("TABLE");
	tbl.className = "mainmenu_table";
	tbl.cellPadding = "0"
	tbl.cellSpacing = "0"	
	tbl.width = "774"	
	tbody = document.createElement("TBODY");
	tbl.insertBefore(tbody, null);
	this.div.appendChild(tbl);
	tr = document.createElement("TR");
//	td = document.createElement("TD");
//	tr.insertBefore(td, null);	
	var tds = new Array();
	
	for(var i=0; i<this.items.length; i++){
		var a = this.createLink(this.items[i]);
		td = document.createElement("TD");
		
		td.onmouseover=function() {
			window.clearTimeout(timeout);
			this.className = "mainmenu_td_hover";
		}
		td.onmouseout=function() {
			this.className = "mainmenu_td";
		}
		td.appendChild(a);
		td.width = "128px"
		tds[i] = td;
		tr.insertBefore(td, null);
		if (this.items[i].getMenu()!=null){
			this.items[i].getMenu().display();
		}
	}
	

	tbody.insertBefore(tr, null);	
	for (var i=0;i<tds.length;i++) { 
		if (this.items[i].getMenu()!=null){
			this.items[i].getMenu().div.style.left = tds[i].offsetLeft +1+"px";
			this.items[i].getMenu().div.style.top = '90px';
			this.items[i].getMenu().layout();
		}
	}
}

function appendItem(item){
	item.parentMenu = this;
	this.items.push(item);
	return item;
}