var dropped=null;

function link(url,text){
		this.url=url;
		this.text=text;
		this.next=null;
		
		this.addLink=function(url,text){
			if(this.next==null)
				this.next=new link(url,text);
			else this.next.addLink(url,text);
		}
		this.printLink=function(){
			//var c='<li><a class="menuitems" href="'+this.url+'">'+this.text+'</a></li>';
			var c='<li><a class="menuitems" href="'+this.url+'"><img onmouseover="changeImages(this, \'/images/'+this.text+'_on.jpg\')" onMouseOut="changeImages(this, \'/images/'+this.text+'.jpg\');" src="/images/'+this.text+'.jpg" alt="'+this.text+'"/></a></li>';
			if(this.next!=null)
				c+=this.next.printLink();
			return c;
			
		}
	
	
	}
	function menuStruct(catnameid,subcatname){
		
		this.todrop=catnameid;
		this.i=0;
		//alert('menu init');
		this.hash=new Object();
		this.nodes=new Object();
		
		this.addNewSubNode=function(nodename,subnodeurl,subnodename){
			//alert('adding '+nodename+ ' subnode: '+subnodename);
			//alert(nodename);
			if(this.nodes[nodename]==null){
				this.nodes[nodename]=new link(subnodeurl,subnodename);
				//alert('addin new node: '+nodename);
				this.hash[nodename]=nodename;
				this.i+=1;
				//alert(this.i);		
			}else
				this.nodes[nodename].addLink(subnodeurl,subnodename);
			//alert('addin new subnode: '+subnodename);
		}
	this.printSubMenu=function (node){
		var c='';
		//alert(node);
		if(this.nodes[node]!=null) 
				c+=this.nodes[node].printLink();
		//alert (this.nodes);
		return c;
	}
	this.printMenu=function(){
		var c='';
		c+='<ul class="category">';
		
		for(var key in this.nodes){
		//alert(key+" ");
		//if(catnameid==this.hash[key])
			//c+='<li><a unselectable="on"  class="menuheader-expandable"  id="'+this.hash[key] +'" onClick="rollBack(this.id)">'+key+'</a>';
		//else
			
			c+='<li><a unselectable="on"  class="menuheader-expandable"  id="'+this.hash[key] +'"  onClick="dropDown(this)"><img  style="border: solid 1px #571434;" src="/images/'+key+'.jpg"/></a>';
			c+='<ul class="categoryitems">';
			//if(catnameid==this.hash[key]){
					//alert(key);
				
				//c+=this.printSubMenu(key);
				//dropped=catnameid;
				
				
				//}
			c+='</ul>';
			
			c+='</li>';
			//if(this.nodes[key]!=null) 
				//c+=this.nodes[key].printLink();
		
		}
		c+='</ul>';
		return c;
		}
		this.drop=function(){
			//alert(this.todrop);
			if(this.todrop){
				obj=document.getElementById(this.todrop);
				dropDown(obj);
				
				this.todrop=null;
			}
		
		}
	}
		
	
	
	function dropDown(id){
		//obj.style.background="yellow";
	//alert(id.id);
		var obj;
		//obj=document.getElementById(id);
		//alert(id.id );
		var atext;
		atext=id.innerHTML;
		
		//alert(dropped+' '+obj.innerHTML);
		
			
		
		
		arrChildren =id.parentNode.childNodes;
		//obj.attributes["onclick"].value = "rollBack(this.id)";
		
		//alert(obj.onclick);//obj.onclick = "rollBack";
		
		//obj.onclick=rollBack;
		ul=arrChildren[1];
		
		//alert(ul.innerHTML);
		if(ul.className=="categoryitems"){
			//alert(atext);
			ul.innerHTML='';
			ul.innerHTML+=menu.printSubMenu(id.id);
		}
		//alert (obj.id);
		
		
		//	alert(obj.onclick);
		/*div=obj.parentNode.parentNode.
		div.innerHTML='<a href="#" onClick="rollBack(this)">'+atext+'</a><br/>'
		div.innerHTML+='<div class="subMenuLinks">'+menu.printSubMenu(atext)+'</div>';//musimy wiedziec skad brac submenu wiec tu dajemy nazwe obiektu ktory stworzylismy*/
		var tmp=dropped;
		//alert(dropped);
		if(dropped!=null&&dropped!=''){
			//var tmp=dropped;
			//alert(dropped);
			
			
			rollBack(dropped);
			//alert(atext);
			
			//if(tmp==atext.toLowerCase())
				//alert(tmp);
			//	return 0;
			}
		
		if(tmp!=id.id)
				dropped=id.id;	
		
			
		return 0
	}
	function rollBack(id){
	//alert(id.innerHTML);
		if(id==''||id==null) return;
		var obj;
		
		obj=document.getElementById(id);
		//alert(dropped+' '+obj.innerHTML);
		
		var atext;
		atext=obj.innerHTML;
		//obj.style.background="";
		//alert(obj.innerHTML+' '+obj.onClick)
		//alert('ok');
		
		arrChildren =obj.parentNode.childNodes;
		//obj.attributes["onclick"].value = "dropDown(this.id)";
		//obj.onclick = "dropDown";
		//alert(arrChildren[0].tagName+" "+arrChildren[0].className);
		ul=arrChildren[1];
		
		ul.innerHTML='';
		
		dropped=null;
		return 0
	}
	

function hidepromo(){
	obj=document.getElementById('popup')
	//alert(obj.style)
	obj.style.visibility='hidden'
}