function Layout(){
	this.onLoadComplete=function(){
		var lMenuObj=$("lateral_menu");
		this.menu=new Menu();
		this.menu.menuObj=lMenuObj;
		this.menu.visibleLevels=1;
		this.menu.caller=this;
		this.menu.hideSubMenuLevels();
		this.replaceLinks($("main"));
	}
	
	this.onLoadItem=function(data){
		var arrResp=data.responseText.split("||@@");
		$("header").className=arrResp[0];
		$("main").innerHTML=arrResp[1];
		this.caller.replaceLinks($("main"));
	}
	
	this.replaceLinks=function(pObj){
		lLnks=pObj.getElementsByTagName("a");
		if (lLnks){
			for (var i=0;i<lLnks.length;i++){
				Event.observe(lLnks[i],"click",this.clickLink.bindAsEventListener(this));
			}
		}
	}
	this.clickLink=function(e){
		var pLnk=Event.element(e);
		while (pLnk.tagName!="A"){
			pLnk=pLnk.parentNode;
		}
		url=pLnk.href+"?ajax";
		if (pLnk){
			url=pLnk.href+"?ajax";
			var lOptions={
				caller:this,
				onSuccess:this.onLoadItem
			};
			new Ajax.Request(url,lOptions);
		}
		Event.stop(e);
		
	}
	
}

function Menu(){
	this.menuObj=null;
	this.visibleLevels=1;
	this.currentOpened=null;
	this.hideSubMenuLevels=function(){
		this._hideSubMenuLevels(this.menuObj,this.visibleLevels,0);
	}
	this._hideSubMenuLevels=function(pMenuObj,pShowLevels,pCurrentLevel){
		if (pMenuObj){
			if(pCurrentLevel>=pShowLevels){
				pMenuObj.style.display="none";
			}
			var lItems=pMenuObj.childNodes;
			if (lItems){
				for(var i=0;i<lItems.length;i++){
					if (lItems[i].tagName=="LI"){
						Event.observe(lItems[i].getElementsByTagName("a")[0],"click",this.openItem.bindAsEventListener(this));
						var lUl=lItems[i].getElementsByTagName("ul");
						if (lUl&&lUl.length>0){
							for (var j=0;j<lUl.length;j++){
								this._hideSubMenuLevels(lUl[j],pShowLevels,(pCurrentLevel+1));
							}
						}
					}
				}
			}
		}
	}
	
	this.closeOpenedMenu=function(){
		if (this.currentOpened&&$(this.currentOpened+"_submenu")){
			$(this.currentOpened+"_submenu").style.display="none";
		}
	}
	
	this.openItem=function(e){
		Event.stop(e);
		lMenuId=(Event.element(e).id);
		if($(lMenuId+"_submenu")){
			if($(lMenuId+"_submenu").style.display=="none"){
				$(lMenuId+"_submenu").style.display="block";
				this.closeOpenedMenu()
				this.currentOpened=lMenuId;
			}else{
				$(lMenuId+"_submenu").style.display="none";
				this.currentOpened=null;
			}
		}
		var pLnk=Event.element(e);
		while (pLnk.tagName!="A"){
			pLnk=pLnk.parentNode;
		}
		url=pLnk.href+"?ajax";
		var lOptions={
			caller:this.caller,
			onSuccess:this.caller.onLoadItem
		};
		new Ajax.Request(url,lOptions);
		
	}
	
}
var use_javascript=false;
if (use_javascript==true){
	var layout=new Layout();
	Event.observe(window,"load",layout.onLoadComplete.bindAsEventListener(layout));
}