	String.prototype.count=function(s){return this.replace((new RegExp(s,"g")),"").length}
	function menuHeaderOver(obj,e){
		var jsID = obj.id.replace(/[^\d]/g,"");			
		if(e.type=="mouseover"){
			oMenu.isOver=true;
			for(var i=0,oHTML;i<oMenu.opened.length;i++){
				oHTML=document.getElementById(oMenu.opened[i]);
				if(oHTML&&obj.id.count("_")<oHTML.id.count("_"))
					{oHTML.innerHTML="";oHTML.style.visibility="hidden";}
			}
			oMenu.opened=[obj.nextSibling.id];
			oMenu.headers[jsID].showChilds();
		}else{
			oMenu.isOver=false;
			setTimeout("if(!oMenu.isOver){oMenu.clean()}",1000);			
		}
	}
	function menuElementOver(obj,e){
		e=e||event;
		obj.style.backgroundColor=e.type=="mouseover"?"#00286B":"#EBE5DB";
		oLabel=obj.childNodes[0].childNodes[0];
		oLabel.style.color=e.type=="mouseover"?"#FFFFFF":"#00286B";
		for(var i=0,oHTML;i<oMenu.opened.length;i++){
			oHTML=document.getElementById(oMenu.opened[i]);
			if(oHTML&&obj.id.count("_")<oHTML.id.count("_"))
				if((oMenu.elements[obj.id].childs.groupID!=oHTML.id))
					{oHTML.style.visibility="hidden";oHTML.innerHTML="";}
		}
		if(e.type=="mouseover"){
			oMenu.isOver=true;
			if(oMenu.elements[obj.id].childs.length){
				oMenu.opened[oMenu.opened.length]=obj.nextSibling.id;
				oMenu.elements[obj.id].showChilds();
			}
		}else{
			oMenu.isOver=false;
			setTimeout("if(!oMenu.isOver){oMenu.clean()}",1000);			
		}
	}
	function elementGroup(sLabel,sLink,nID,sType,sFather){
		// METHODS
			function _addChild(sCLabel,sCLink){
				var newID=this.childs.length;
				this.childs[newID]=new elementGroup(sCLabel,sCLink,newID,"submenu",this.id);
				return this.childs[newID];
			}
			function _addChilds(){
				if(arguments.length%2!=0) return false;
				for(var i=0,newID;i<arguments.length;i+=2){
					newID=this.childs.length;
					this.childs[newID]=new elementGroup(arguments[i],arguments[i+1],newID,"submenu",this.id);
				}
				return true;
			}
			function _showChilds(){
				for(var i=0,s="";i<this.childs.length;i++)
					s+=	'<div class="menuElement" id="'+this.childs[i].id+'" onclick="window.location.href=\''+this.childs[i].href+'\'" onmouseover="menuElementOver(this,event)" onmouseout="menuElementOver(this,event)">'+
							'<div class="menuLabel"><span class="labelText">'+this.childs[i].label+'</span></div>'+
							'<div class="menuArrow"><img src="images/menu_'+(!this.childs[i].childs.length?"dot":"arrow")+'.gif" width="22" height="22" alt="" border="0"></div>'+
						'</div>'+
						'<div class="menuElementGroup" id="'+this.childs[i].childs.groupID+'"></div>';
				var obj=document.getElementById(this.childs.groupID);
				var father = document.getElementById(this.id);
				obj.innerHTML=s;
				if(this.type=="header"){
					obj.style.top=father.offsetTop+25;
					obj.style.left=father.offsetLeft;
				}else{
					obj.style.top=father.offsetTop-1;
					var n=0,o=obj.parentNode,w=document.body.clientWidth;
					if(document.all&&!window.createPopup) n=o.offsetLeft;
					else while(o){n+=o.offsetLeft>>0;o=o.parentNode;}
					obj.style.left=father.offsetLeft+(n+400<=w?185:-185);
				}
				if(i) obj.style.visibility="visible";
			}
		// PROPERTIES
			this.label=sLabel;
			this.href=sLink;
			this.type=sType;
			this.id=(sType=="header"?"menuHeader_":sFather+"subMenu_")+(nID>>0);
			this.childs=[];
			this.childs.groupID=this.id+"_group";
		// INTERFACES
			this.addChild=_addChild;
			this.addChilds=_addChilds;
			this.showChilds=_showChilds;
		return this;
	}
	function mainMenu(containerID){
		// METHODS
			function _buildElementList(arr){
				for(var i=0;i<arr.length;i++){
					this.elements[this.elements.length]=this.elements[arr[i].id]=arr[i];
					this.buildElementList(arr[i].childs);
				}			
			}
			function _addHeader(sLabel,sLink){
				var nID=this.headers.length;
				this.headers[nID]=new elementGroup(sLabel,sLink,nID,"header");
				return this.headers[nID];
			}
			function _addHeaders(){
				if(arguments.length%2!=0) return false;
				for(var i=0,newID;i<arguments.length;i+=2){
					newID=this.headers.length;
					this.headers[newID]=new elementGroup(arguments[i],arguments[i+1],newID,"header");
				}
				return true;
			}
			function _getHTML(){
				for(var i=0,s="";i<this.headers.length;i++)
					s+=	'<div class="menuHeader'+(this.headers.length==(i+1)?'End':'')+'" id="'+this.headers[i].id+'" onclick="window.location.href=\''+this.headers[i].href+'\'" onmouseover="menuHeaderOver(this,event)" onmouseout="menuHeaderOver(this,event)">'+
							'<div class="menuHeaderTop"><img src="images/menu_head_top.gif" width="183" height="2" alt="" border="0"></div>'+
							'<div class="menuHeaderLabel"><span class="labelText">'+this.headers[i].label+'</span></div>'+
							'<div class="menuArrow"><img src="images/menu_head_arrow.gif" width="22" height="22" alt="" border="0"></div>'+
						'</div>'+
						'<div class="menuElementGroup" id="'+this.headers[i].childs.groupID+'"></div>';
				return s;
			}
			function _write(){
				this.container.innerHTML=this.getHTML();
				this.buildElementList(this.headers);
			}
			function _clean(){
				var arr = this.container.childNodes;
				for(var i=0;i<arr.length;i++)
					if(arr[i].id.search(/\_group$/)!=-1)
						{arr[i].style.visibility="hidden";arr[i].innerHTML="";}
			}
		// PROPERTIES
			this.container=document.getElementById(containerID);
			this.headers=[];
			this.elements=[];
			this.opened=[];
		// INTERFACES
			this.buildElementList=_buildElementList;
			this.addHeader=_addHeader;
			this.addHeaders=_addHeaders;
			this.getHTML=_getHTML;
			this.write=_write;
			this.clean=_clean;
		return this;
	}