var menu_bg_color = "#AAAAAA";
var menu_hl_color = "#7B797A";
var menu_bd_color = "#000000";
var link_class    = "linkm_grey";
var menu_TimeOut  = 500; //in msec

var objArray = new Array();

ie = (document.all)? true : false;
nn = (document.getElementById && !ie)? true : false;

var isInMenu = 0;


function go(url)
{

   location.href=url;
}


function goto_loc(obj)
{

if (obj.indexOf("href=")>0)
{ 
	var pos_1 = obj.indexOf('http');
	var pos_2 = obj.indexOf(' name=');	
        loc = obj.substring(pos_1,pos_2-1);
location.href=loc;
}

//  if(obj.indexOf('"')>=0 alert(1);
//location.href=id.actions[cnt];
}

function dec2hex(dec_byte)
{ 
	var hb,lb,temp;
	if(dec_byte>15) {
		temp=parseInt(dec_byte/16);
		if (temp>9){
        	if (temp==10) hb='A'; if (temp==11) hb='B';
            if (temp==12) hb='C'; if (temp==13) hb='D';
            if (temp==14) hb='E'; if (temp==15) hb='F';
        } else hb = new String(temp);
 		
		temp=parseInt(dec_byte%16);
		if (temp>9){
        	if (temp==10) lb='A'; if (temp==11) lb='B';
            if (temp==12) lb='C'; if (temp==13) lb='D';
            if (temp==14) lb='E'; if (temp==15) lb='F';
        } else lb=new String(temp);
  return hb+lb;  }
   else {
          if(dec_byte>9){
                if (dec_byte==10) lb='A'; if (dec_byte==11) lb='B';
                if (dec_byte==12) lb='C'; if (dec_byte==13) lb='D';
                if (dec_byte==14) lb='E'; if (dec_byte==15) lb='F';
             return 0+lb;}
             else return '0'+dec_byte;
       }

}

 
function inverse(c)
{
 max_val=0xFF;
 c = new String(c);
 var r = c.substring(1,3);r='0x'+r;
 var g = c.substring(3,5);g='0x'+g;
 var b = c.substring(5,7);b='0x'+b;
// return '#'+dec2hex(max_val-eval(r))+dec2hex(max_val-eval(g))+dec2hex(max_val-eval(b));
return menu_hl_color;
}

function myHide()
{
if (isInMenu==0) setTimeout("hideElems()",menu_TimeOut);
}


function hideElems()
{
//isInMenu=0;

  if ((ie)&&(isInMenu==0)) 
    {
     var cnt;
      for (cnt=0;cnt<objArray.length;cnt++)
       document.all[objArray[cnt]].style.display="none";
    }
 else if ((nn)&&(isInMenu==0))
    { 
     var cnt;

      for (cnt=0;cnt<objArray.length;cnt++)
       document.getElementById(objArray[cnt]).style.display="none";
	}
}

function myPopUpOnMOver(t)
{
 isInMenu = 1;
// if (ie) document.all[t].style.backgroundColor=inverse(menu_bg_color);
//  else if (nn) document.getElementById(t).style.backgroundColor = inverse(menu_bg_color);
  return false;
}

function myPopUpOnMOut(t)
{
// if (ie) document.all[t].style.backgroundColor=menu_bg_color;
  //else if (nn) document.getElementById(t).style.backgroundColor = menu_bg_color;

 isInMenu = 0;
        return false;
}

function myPopUpShow(x,y)
{		
 isInMenu = 1;
	    if(nn)
          {
		   for (cnt=0;cnt<objArray.length;cnt++)
            document.getElementById(objArray[cnt]).style.display="none";
           var layerObj=document.getElementById(this.id);
//	       layerObj.style.top=y;
//           layerObj.style.left=x;
           this.myLayer.style.display="block";
          }
         else if(ie)
          {
			window.event.cancelBubble=true;
             for (cnt=0;cnt<objArray.length;cnt++)
              document.all[objArray[cnt]].style.display="none";
             var divObj=document.all[this.id];
// бля, долго искал document.body.scrollTop, без него при 
// скролиинге страницы баги
           //  divObj.style.top=y;
          //   divObj.style.left=x;
           //  this.myLayer.style.background=menu_bg_color;
			 this.myLayer.style.display="block";
          }
        return false;
}

function myPopUpWrite()
{
	var cnt, url;
	var HTMLstr='<DIV ID="'+this.id+'" STYLE="position:absolute;display:none;width:110px;"';
	HTMLstr+=' onmouseout=setTimeout("myHide()",250);>';
	HTMLstr+='<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" id="main2" style="border-left: 1px #29233F solid; border-right: 1px #29233F solid;">';
	for (cnt=0;cnt<this.elements.length;cnt++) 
		{
    	  HTMLstr+='<TR><TD ID="'+this.id+'_'+cnt+'" CLASS="td1" height="16" align="center"'; 
	  HTMLstr+='onmouseout=myPopUpOnMOut("'+this.id+'_'+cnt+'"); ';
// if (ie)  HTMLstr+='onclick="goto_loc(document.all[this.id].innerHTML);" ';
// else if(nn) HTMLstr+='onclick="goto_loc(document.getElementById(this.id).innerHTML);" ';
	      HTMLstr+='ONMOUSEOVER=myPopUpOnMOver("'+this.id+'_'+cnt+'");>';
          HTMLstr+='<A HREF="'+this.actions[cnt]+'" NAME="'+this.id+'link'+cnt+'"';
          HTMLstr+=' class="companynav">'+this.elements[cnt]+'</A>';
          HTMLstr+='</TD></TR>';
		}
	HTMLstr+='</TABLE>';
	HTMLstr+='</DIV>';
	document.write(HTMLstr);
	if (nn) this.myLayer=document.getElementById(this.id);
    else if (ie) this.myLayer=document.all[this.id]; 
//alert(HTMLstr);
	}

function myPopUpAddElem(elem,action)
{
        this.elements[this.elements.length]=elem;
        this.actions[this.actions.length]=action;
        return elem;
}


function myPopUp(id,width,height)
{
        this.id=id;
        this.elements=new Array();
        this.actions=new Array();
        this.width=width;
        this.height=height;
        this.addElem=myPopUpAddElem;
        this.write=myPopUpWrite;
        this.show=myPopUpShow;
        objArray[objArray.length++]=this.id;
        return this;
}

