var nowMenu = "";
var firstOne = "";
function loadMenu(categ){
	firstOne = categ;
	Builder.dump();
	var menuArea = DIV({id:"menuArea"});
	if(categ=="allitems"){
		$('main').appendChild(menuArea);	
	}
	else if(categ == "help"){
		$('menuArea2').appendChild(menuArea);	
	}
	else{
		$("menuArea2").appendChild(menuArea);
	}
	$("menuArea").hide();
	$("menuArea").style.zIndex = "0";
	$("menuArea").style.left= 0+"px";
	$("menuArea").style.top = 69 +"px";
	$('menuArea').innerHTML = "<img src='/img/common/loading.gif' />";
	
	$("menuArea").show();
	if(categ=="allitems"){
		$("menuArea").style.position = "absolute";
		new Ajax.Request("./menu.php?categ=all",{ method: 'get',  onComplete: menuLoaded });
	}
	else{
		$("menuArea").style.position = "static";
		new Ajax.Request("./menu.php",{ method: 'get',  onComplete: menuLoaded });	
	}
}
function menuLoaded(res){
	$('menuArea').hide();
	var responce = res.responseText;
	if(responce != "ERROR"){
		$('menuArea').innerHTML = responce;
		hideAll();
		if(firstOne == "allitems"){
			menuFloat = true;
		}
		$('menuArea').appear({afterFinish:showFirst});
	}
}
function showFirst(e){
	if(firstOne&&firstOne!="allitems"&&firstOne!="help"){
		getItems(firstOne);
	}
}
function showItem(categ){
	if(nowMenu == categ){
		hideOne();
		nowMenu="";
	}
	else{
		hideOne();
		getItems(categ);
	}
}
function hideOne(){
	if(nowMenu){
		Effect.Fade($('items_'+nowMenu),{duration:0.5});
		$('menu_'+nowMenu).style.background="#BAAD84";
	}
}
function hideAll(){
	$$('#menu div ul').each(function(item){
		item.hide();
		//Effect.Fade(item,{duration:0.2,afterfinish:function(){}});
	});
	$$('#menu div').each(function(item){
		item.style.background="#BAAD84";
	});
	nowMenu = "";
}
function getItems(categ){
	if(firstOne!="help"){
		new Ajax.Request("./getItems.php?categ="+categ,{ method: 'get',  onComplete: setItems });	
		$('items_'+categ).innerHTML = "<img src='/img/common/loading.gif' />";
	}
	//$('items_'+categ).appear({duration:0.5});
	//Effect.SlideDown($('items_'+categ),{duration:0.5});
	$('items_'+categ).show();
	$('menu_'+categ).style.background = "#ffffff";
	nowMenu = categ;
}
function setItems(res){
	var responce = res.responseText;
	$('items_'+nowMenu).hide();
	if(responce != "ERROR"){
		$('items_'+nowMenu).innerHTML = responce;
		
		$$('#menu div ul li').each(function(e){
		
		if(e.id!=""){
			e.observe('mouseover',function(f){
				if($('popWin')){
					$('popWin').remove();
				}
				Builder.dump();
				popObj = DIV({id:"popWin"},[IMG({src:"http://www.pants-ya.com"+e.id})]);
				//,style:"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+e.id+"', sizingMethod=scale)"
				$('popWin1').appendChild(popObj);
				$('popWin').hide();
				$('popWin').style.padding = "0px";
				$('popWin').style.background = "none";
				$('popWin').style.textAlign = "center";
				$('popWin').style.width = "64px";
				$('popWin').style.height = "64px";
				$('popWin').style.margin = "0 60px 0 0";
				$('popWin').style.position = "absolute";
				$('popWin').style.zIndex = "100";
				$$('#popWin img')[0].style.border = "0px";
				$$('#popWin img')[0].style.margin = "0px";
				$('popWin').show();
				
				var X = Event.pointerX(f);
				var Y = Event.pointerY(f);
				$('popWin').style.left = X+10+"px";
				$('popWin').style.top = Y-95+"px";
				//Rico.Corner.round("popWin", {compact:true} );
				
				e.observe('mousemove',function(evt){
					var X = Event.pointerX(evt);
					var Y = Event.pointerY(evt);
					if($('popWin')){
						$('popWin').style.left = X+10+"px";
						$('popWin').style.top = Y-95+"px";
					}
				});
				
			});
			e.observe('mouseout',function(){
				e.stopObserving('mousemove');
				if(Prototype.Browser.IE) $('popWin').hide();
				else Effect.Fade('popWin',{duration:0.5});
			});
		}
	});
		Effect.BlindDown($('items_'+nowMenu),{duration:0.5});
	}
}
