var first="";
var storageHash = new Object();
var loc="";
var ie = navigator.appName == "Microsoft Internet Explorer";

function $(e){if(typeof e=='string')e=document.getElementById(e);return e};
function collect(a,f){var n=[];for(var i=0;i<a.length;i++){var v=f(a[i]);if(v!=null)n.push(v)}return n};

ajax={};
ajax.x=function(){try{return new ActiveXObject('Msxml2.XMLHTTP')}catch(e){try{return new ActiveXObject('Microsoft.XMLHTTP')}catch(e){return new XMLHttpRequest()}}};
ajax.serialize=function(f){var g=function(n){return f.getElementsByTagName(n)};var nv=function(e){if(e.name)return encodeURIComponent(e.name)+'='+encodeURIComponent(e.value);else return ''};var i=collect(g('input'),function(i){if((i.type!='radio'&&i.type!='checkbox')||i.checked)return nv(i)});var s=collect(g('select'),nv);var t=collect(g('textarea'),nv);return i.concat(s).concat(t).join('&');};
ajax.send=function(u,f,m,a){var x=ajax.x();x.open(m,u,true);x.onreadystatechange=function(){if(x.readyState==4)f(x.responseText)};if(m=='POST')x.setRequestHeader('Content-type','application/x-www-form-urlencoded');x.send(a)};
ajax.get=function(url,func){ajax.send(url,func,'GET')};
ajax.gets=function(url){var x=ajax.x();x.open('GET',url,false);x.send(null);return x.responseText};
ajax.post=function(url,func,args){ajax.send(url,func,'POST',args)};
ajax.update=function(url,elm){var e=$(elm);var f=function(r){e.innerHTML=r};ajax.get(url,f)};
ajax.submit=function(url,elm,frm){var e=$(elm);var f=function(r){e.innerHTML=r};ajax.post(url,f,ajax.serialize(frm))};

function show() 
{
	var objThis = this;	
	showSubMenu(objThis);
}

function showSubMenu(SubMenu)
{
	var objThis = this;	

	for(var i = 0; i  < objThis.childNodes.length; i++)
	{
		if(objThis.childNodes.item(i).nodeName == "UL")			
		{							
			objThis.childNodes.item(i).style.display = "block";
		}		
	}	
}

function hide() 
{
	var objThis = this;	
	hideSubMenu(objThis);
}

function hideSubMenu()
{			
	var objThis = this;	
	
	for(var i = 0; i  < objThis.childNodes.length; i++)			
	{
		if(objThis.childNodes.item(i).nodeName == "UL")
		{				
			objThis.childNodes.item(i).style.display = "none";			
			return;
		}			
	}	
}			

function initialiseMenu()
{
/*	
	document.getElementById('hladaj').focus();
	first=document.getElementById('prod').innerHTML;
	if ( document.location.hash.substr(1,2) == "id" ) {
		ajax.post("prod.php?"+document.location.hash.substr(1),after_prod,"") };
	if ( document.location.hash.substr(1,2) == "pi" ) {
		ajax.post("detail.php?"+document.location.hash.substr(1),after_detail,"")};
*/		
    var objLICollection = document.body.getElementsByTagName("LI");		
	for(var i = 0; i < objLICollection.length; i++)
	{		
		var objLI = objLICollection[i];										
		for(var j = 0; j  < objLI.childNodes.length; j++)
		{
			if(objLI.childNodes.item(j).nodeName == "UL")
			{
				objLI.onmouseover=showSubMenu;
				objLI.onmouseout=hideSubMenu;
				
				for(var j = 0; j  < objLI.childNodes.length; j++)
				{
					if(objLI.childNodes.item(j).nodeName == "A")
					{					
						objLI.childNodes.item(j).className = "hassubmenu";								
					}
				}
			}
		}
	}
}

function prod(inp,pg)
{
	var pp='x'+inp
	id=pp.substr(1,pp.length-2);
	level=pp.substr(pp.length-1);
	if(!pg) {pg=0;}
	loc = "id="+id+"&level="+level+"&pg="+pg;
//	ajax.post("prod.php?"+loc,after_prod,"");
	setHash(loc);
}
function after_prod(inp)
{
	document.getElementById('prod').innerHTML=inp;
	document.getElementById('menubar_l').innerHTML=document.getElementById('menubar2').innerHTML;
	storageHash[document.location.hash] = document.getElementById("prod").innerHTML;
}

function detail(inp)
{
	var pp='x'+inp
	id=pp.substr(1,pp.length-2);
	level=pp.substr(pp.length-1);
	loc = "pid="+encodeURIComponent(inp)
//	ajax.post("detail.php?"+loc,after_detail,"");
	setHash(loc);
}

function after_detail(inp)
{
	document.getElementById('prod').innerHTML=inp;
	storageHash[document.location.hash] = document.getElementById("prod").innerHTML;
}

function img_in(inp,event)
{
	if (ie)
	x=event.clientX-250;
	y=event.clientY-100;
	if ( ( navigator.appName == "Microsoft Internet Explorer" ) &&
	(navigator.appVersion == "4.0 (compatible; MSIE 6.0; Windows NT 5.1)" ) )
	{document.getElementById(inp).style.position="absolute";}
	else {document.getElementById(inp).style.position="absolute";}
	document.getElementById(inp).style.top=y+"px";
	document.getElementById(inp).style.left=x+"px";
	document.getElementById(inp).style.display='block';
}

function img_out(inp)
{
	document.getElementById(inp).style.display='none';
}

function setHash(h) {
	hashListener.setHash(h);
}

hashListener.onHashChanged = function () {
	if (( document.location.hash == "#" ) || ( document.location.hash == "" ) )
		{ document.getElementById("prod").innerHTML = first ; }
	else 
		if ( storageHash[document.location.hash] != undefined ) 
		 { 
		 	document.getElementById("prod").innerHTML = storageHash[document.location.hash]; 
			document.getElementById('menubar_l').innerHTML=document.getElementById('menubar2').innerHTML;
			} else { 
				if ( document.location.hash.substr(1,2) == "id" ) {
					ajax.post("prod.php?"+document.location.hash.substr(1),after_prod,"") };
				if ( document.location.hash.substr(1,2) == "pi" ) {
					ajax.post("detail.php?"+document.location.hash.substr(1),after_detail,"")};
			}
};
