var _menu 		= new Array();
var _menu_on 	= new Array();
var _menu_on_timer	= 0;
var _menu_active = null;
var _submenu_active = null;

// menu defaults
var _menu_timeout = 700;

// menu css options
var _item_pading_top='8';
var _item_pading_lft='1';

function getBrowser()
{
	this.dom	= (document.getElementById);
	this.op		= (navigator.userAgent.indexOf("Opera")>-1);
	this.konq	= (navigator.userAgent.indexOf("Konq")>-1);
	this.ie4	= (document.all && !this.dom && !this.op && !this.konq);
	this.ie5	= (document.all && this.dom && !this.op && !this.konq);
	this.ns4	= (document.layers && !this.dom && !this.konq);
	this.ns5	= (!document.all && this.dom && !this.op && !this.konq);
	this.ns6	= (this.ns5);
	this.bw		= (this.ie4 || this.ie5 || this.ns4 || this.ns6 || this.op || this.konq);
	return this;
}

bw = new getBrowser();

function findObj(n, d)
{ 
 var p,i,obj;  
 if(!d) d=document; 
 if ((p=n.indexOf("?")) > 0 && parent.frames.length) {
	 d=parent.frames[n.substring(p+1)].document; 
	 n=n.substring(0,p);
 }
 if(!(obj=d[n])&&d.all) obj=d.all[n]; 
 for (i=0; !obj && i < d.forms.length; i++) 
 	obj=d.forms[i][n];
 
 for(i=0;!obj && d.layers && i < d.layers.length; i++) 
 	obj=findObj(n,d.layers[i].document);
 if(!obj && d.getElementById) obj=d.getElementById(n); 
 
 return obj;
}
// NS - resize-fix
if(document.layers )
{
	var scrX = window.innerWidth; 
	var scrY = window.innerHeight;

    window.onresize = function()
    {
    	if(scrX!= window.innerWidth || scrY!= window.innerHeight)
    	{
    		window.location.reload();
    	} 
    };
}
function getObjProperties(obj)
{
	this.el= findObj(obj,document);	
	if (this.el)
	{
	   	this.css= bw.ns4 ? this.el : this.el.style;
		this.ref= bw.ns4 ? document : this.el ;		
		this.x_pos= (bw.ns4) ? this.ref.left : this.el.offsetLeft;
		this.y_pos= (bw.ns4) ? this.ref.top : this.el.offsetTop;
		this.height= (bw.ie4||bw.ie5||bw.ns6|| bw.op) ? this.el.offsetHeight : bw.ns4 ? this.ref.height : 0;
		this.width= (bw.ie4||bw.ie5||bw.ns6 || bw.op) ? this.el.offsetWidth : bw.ns4 ? this.ref.width : 0;

		return this;
	} else { 
		return null;
	}
}

function getObjCss(obj) {
	if (findObj(obj)) return bw.dom ? document.getElementById(obj).style : bw.ie4 ? document.all[obj].style : bw.ns4 ? document.layers[obj]:0;
};

function showMenu(m_itm,id) { 
	clearTimeout(_menu_on_timer);
	if (_submenu_active && _menu_on[m_itm] != id) {
		hideMenu(_submenu_active);
	}
	var parentObject=null;
	var TI_width=0; 
	var TI_height=0;
	if (getObjCss(id))	{
		_menu_on[m_itm] = getObjCss(id);
		
		parentObject  = getObjProperties(_menu[m_itm][id][0]);
		parent_height = parentObject.height;

		var anchor = getObjProperties(_menu[m_itm][id][2]);
		var menu_x = anchor.x_pos-_item_pading_lft;
		var menu_y = anchor.y_pos-_item_pading_top;
		Pos_x(id,menu_x );
		Pos_y(id,menu_y + parent_height);
		_menu_on[m_itm].visibility = "visible";
		_menu_active = m_itm;
		_submenu_active = id;
	}
}
function hideMenu(subid){
	if ((submenu = findObj(subid,document))) submenu.style.visibility="hidden";
}
function hideAllMenus(){
	if (_menu_active) {
		for (var subid in _menu[_menu_active]) { 
			hideMenu(subid);
		}
	}
}
function StartTimer() {
	if (_submenu_active) _menu_on_timer = setTimeout("hideAllMenus()",_menu_timeout);
}
function StopTimer(){ clearTimeout(_menu_on_timer); }

//////////// utils /////////////////////////////
function isDef(val)
{
    return (typeof(val) == 'undefined') ? false:true;
}
function isString(val)
{
  return (typeof(val)!='string') ? false:true;
}
function isNum(val)
{
  return (typeof(val)!='number') ? false:true;
}
function Pos_x(e,iX)
{
  if(!(e=findObj(e))) return 0;
  var css=isDef(e.style);
  if (css && isString(e.style.left))
  {
    if(isNum(iX)) e.style.left=iX+'px';
    else
    {
      iX=parseInt(e.style.left);
    }
  }
  else if(css && isDef(e.style.pixelLeft))
  {
    if(isNum(iX)) e.style.pixelLeft=iX;
    else iX=e.style.pixelLeft;
  }  
  return iX;
}

function Pos_y(e,iY)
{
  if(!(e=findObj(e))) return 0;
  var css=isDef(e.style);
  if(css && isString(e.style.top)) {
    if(isNum(iY)) e.style.top=iY+'px';
    else {
      iY=parseInt(e.style.top);
    }
  }
  else if(css && isDef(e.style.pixelTop)) {
    if(isNum(iY)) e.style.pixelTop=iY;
    else iY=e.style.pixelTop;
  }
  return iY;
}
/////////////////////////////////////////////////
