	var delay = 100;
	var curSelected;
	var curSelectedItem;
	


// Menu
	function menu(boton, submenu, url, marca) {
		
		this.name=boton;
		this.thebtn=findObj(boton);
		this.thesbtn=findObj(submenu);
		this.thebtn.parentMenu=this;
		this.themrk=findObj(marca);
		this.theurl=url;
		
		var pic = 'images/' + this.name + '/' + this.name
		this.picA= pic + 'a.jpg';
		this.picB= pic + 'b.jpg';
		
		this.itemCount=0
		this.items=[]
		
		this.thebtn.onmouseover =btnOnMouseOver; 
		this.thebtn.onmouseout= btnOnMouseOut;
		this.thebtn.onclick = btnClick;
		this.addItem=btnAddItem;
		
		if (this.thesbtn != null) {
			this.thesbtn.parentMenu=this;
			this.thesbtn.onmouseover=btnSubOnMouseOver;
			this.thesbtn.onmouseout=btnSubOnMouseOut;
		}
		
		this.hideMe=function () {
			//alert(!this.selected)
			if (!this.selected) {
				this.timer = setTimeout('hideSubNavigation(' + this.name + ')', delay);		
			}
		}
		
		this.cancelHide = function () {
			clearTimeout(this.timer)
		}
	}
		
	function btnOnMouseOver(event) {
		//primero confirmar que no se esta mostrando otro
		
		//if (curMenu!=this.parentMenu && curMenu!=null) {curMenu.hideMe();} else { this.parentMenu.cancelHide();}
		
		// asingar a menu actual
		curMenu=this.parentMenu
		
		//resaltar boton
		curMenu.thebtn.src=curMenu.picB;
		
		//mostrar submenu
		var subm=curMenu.thesbtn
		if (subm) {
			subm.style.visibility='visible';
		}
			
	}
	
	function btnOnMouseOut(event) {
		this.parentMenu.hideMe();
	}
	
	function btnSubOnMouseOver(event) {
		this.parentMenu.cancelHide();
	}
	
	function btnSubOnMouseOut(event) {
		this.parentMenu.hideMe();
	}
	
	
	function btnAddItem(newItem) {
		//alert(this.name);
		//this.items[this.itemCount]=newItem;
		this.itemCount +=1;
		newItem.parent=this;
		var pic = 'images/' + this.name + '/' + newItem.name
		newItem.picA = pic + 'a.jpg'
		newItem.picB = pic + 'b.jpg'
	}
	
	function btnClick(event) {
		// si el boton tiene sub menu, entonces no hacer nada
		// si no tiene: hacer de este el elegido, cargar la página 
		var tMenu = this.parentMenu
		
		if (tMenu.thesbtn == null ) {
			setMenuSelected (tMenu)
			doMenuAction(tMenu)
			
			//evalM.selected=true;
		}
			
	}	

	function setMenuSelected(theMenu) {
		if (curSelected && curSelected!=theMenu) {
			curSelected.selected=false; 
			curSelected.hideMe();
			if (curSelected.themrk) {curSelected.themrk.style.visibility='hidden';}
		}
		curSelected=theMenu;
		theMenu.selected=true;
	}
			
// menu Item
	function menuItem(boton, url) {
		this.name=boton;
		this.thebtn=findObj(boton);
		this.thebtn.parentMenu=this;
		this.url = url;
		this.picA=boton + 'a.jpg';
		this.picB=boton + 'b.jpg';
		this.parent=null;
		this.thebtn.onmouseover = itemOnMouseOver;
		this.thebtn.onmouseout = itemOnMouseOut;
		this.thebtn.onclick = itemClick;
		this.selected=false;
	}
	
	function itemOnMouseOver(event) {
		if (!this.selected) {this.src=this.parentMenu.picB; }
	}
	
	function itemOnMouseOut(event) {
		if (!this.selected) {this.src=this.parentMenu.picA;}
	}
	
	function itemClick(event) {
		var theItem = this.parentMenu
		//alert(theItem.name)
		setItemSelected(theItem)
		//navegar
		navigate(theItem.url)
	}
	
	function setItemSelected(theItem) {
		if (curSelectedItem && curSelectedItem!=theItem) {
			curSelectedItem.selected=false;
			curSelectedItem.parent.themrk.style.visibility='hidden'; 
		}		
		setMenuSelected(theItem.parent)
		 
		curSelectedItem=theItem;
		theItem.selected=true;
		theItem.parent.themrk.style.top=cssValue(theItem.thebtn, 'top')
		theItem.parent.themrk.style.visibility='visible';

		//mostrar flechita
	}

	
	
	function hideSubNavigation(theMenu){
		if( theMenu != null ){
			var subm=theMenu.thesbtn
			if (subm) {
				theMenu.thesbtn.style.visibility='hidden'
			}
			theMenu.thebtn.src=theMenu.picA;
		}
	}

