var parentX=4;
var parentY=-17;
var menuX=0;
var menuY=0;

if (!document.all)
{  parentX=1; parentY=-18; }
window.highlight=new Array();
window.comboboxen=new Array();
window.activeMenu=null;

document.onmouseup=hideAll;


function sMiE2(menuname, event, menuid, parentmenu, imgpath) {	
	var m=findMenu(menuname + menuid);
	
	if (m) {
		m.showMenu(event, menuid, 0, m)
		
		// prikaz puščice v primeru podmenijev
		var img=document.getElementById("meni_item"+ menuid);
		if (img && document.images)
		{
			var sl1 = new Image();
			sl1.src=imgpath;
		    img.src=sl1.src;
		}
		// konec puščice
	} else {
		var p=findMenu(menuname + parentmenu);
		if (p) {
			
			p.hideSubmenus();
		} else {
			//hideAll();
		}
	}
}

function getStyle(x,styleProp)
{
	var y=null;

	if (document.defaultView && document.defaultView.getComputedStyle)
		y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	else if (x.currentStyle)
		y = eval('x.currentStyle.' + styleProp);
	
	return y;
}

function showMenu(event, A, B, m) {
	if (!this) return;
	showComboBoxen('hidden');
	window.activeMenu=this;

	if (this.visible) return;
	this.hideSisters();
	
	var o=document.getElementById("menu_"+ A);

	//if (!this.pos) this.pos=getXYcoord(o);
	if(!this.pos)
	{
		if(o)
		{
			this.pos=getXYcoord(o);
			this.pos.x +=o.offsetWidth;
		}
		else
		{
			o=document.getElementById(m.menuid);
			var os=document.getElementById(m.menuid);
			this.pos = { x:0 ,y:0 };
			this.pos.x=o.offsetWidth;
			
			this.pos.y=os.offsetTop - parseInt(getStyle(o,"height").replace(/[^\d]+/ig,""));
		}
	}
	
	
	
	
	
	if (document.all || document.getElementById)
	{
   	  if (this.parentMenu && this.parentMenu.menu) {
	    this.menu.style.left = this.pos.x + parentX;
	    this.menu.style.top = this.pos.y + parentY;
		} else {
	    this.menu.style.left = this.pos.x;
	    this.menu.style.top = this.pos.y;
		}
	  this.menu.style.visibility="visible";
	  this.visible=true;
	}
}

function findMenu(menu) {	
	if (window.menus) return menus[menu];
	return null;
}

function hideAll(event) {
	var p=window.activeMenu;
	while (p) {
		p.hideMenu();
		p=p.parentMenu;
	}
	showComboBoxen('visible');
}


function showParents(visibility) {
	if (this.parentMenu) {
		if (document.layers)
			this.parentMenu.menu.visibility=visibility;
		else
			this.parentMenu.menu.style.visibility=visibility;
		this.parentMenu.showParents(visibility);
	}
}

function getXYcoord ( el ) {
   
     if ( document.layers ) 
		return el;
     var xy = { x:0 ,y:0 };
     
     do { 
     	xy.x += parseInt( el.offsetLeft );
		xy.y += parseInt( el.offsetTop );
		
        el = el.offsetParent;
        
     } while ( el );
   return xy;
}


function hideMenu() {
	if (!this.menu) return;
	if (!this.visible) return;
	
	//alert("tu");
	
	this.hideSubmenus();
	this.menu.style.visibility="hidden";

	this.visible=false;
}

function hideSubmenus() {
	if (this.children) {
		for (var i=0; i<this.children.length; i++)
			this.children[i].hideMenu();
	}
}

function hideSisters() {
	
	if (this.parentMenu && this.parentMenu.children) {
		for (var i=0; i<this.parentMenu.children.length; i++) {
			this.parentMenu.children[i].hideMenu();
			
		}
	}
}

function Menu(menuid) {
	this.menuid=menuid;
	this.menu=null;
	this.parentMenu=null;
	this.visibility=false;
	this.level=0;

	this.registerMenu=registerMenu;
	this.showParents=showParents;
	this.hideMenu=hideMenu;
	this.hideSubmenus=hideSubmenus;
	this.hideSisters=hideSisters;
	this.registerChild=registerChild;
	this.showMenu=showMenu;

	this.children=null;
}

function registerMenu(parentid) {
	if (!window.menus) window.menus=new Array();

	var menu=window.menus[parentid];
	this.parentMenu=menu;

	if (document.all) {
		menu=document.all[this.menuid];
	} else if (document.getElementById) {
		menu=document.getElementById(this.menuid);
	}
	this.menu=menu;

	window.menus[window.menus.length]=this;
	window.menus[this.menuid]=this;

    if (this.parentMenu) {
		this.parentMenu.registerChild(this);
	} 
}

function registerChild(menu) {
	if (!this.children) this.children=new Array();
	this.children[this.children.length]=menu;
	menu.level=this.level+1;
}

function findComboBoxen() {
    var COMBOBOX=0;
    if ((document.getElementsByTagName("SPAN"))) {
      var el = document.getElementsByTagName("SPAN");
      var sName;
      for (var i=0; i<el.length; i++) {
        sName=el[i].id;
        if (el[i].id=="hideme") {
		window.comboboxen[COMBOBOX++]=el[i];
	}
      }
    }
}

function showComboBoxen(x) {
	if (!document.layers && document.all) {
		for (var i=0; i<window.comboboxen.length; i++) {
			window.comboboxen[i].style.visibility=x;
		}
	}
}

var id=null;
function setTimeout_(checkTime, mid, imgpath){
	if (checkTime)
	{
	  // skrijem puščico
	  if (mid)
	  {
	    var img=document.getElementById("meni_item"+ mid);
		if (img && document.images)
		{
			var sl1 = new Image();
			sl1.src=imgpath;
		    img.src=sl1.src;
		}
	  }
	  
	    
	  if (id!=null)
	   clearTimeout(id);
	  id=window.setTimeout("hidell();",600);
	}
	else
   {
	  if (id!=null)
	    clearTimeout(id);
	  id=null;
	}
}

function hidell() {
 var p=window.activeMenu;
 
 while (p) {
  p.hideMenu();
  p=p.parentMenu;
  
 }
 showComboBoxen('visible');
}



