var maxRootmenuItems=8;
var bubble=0;
var numBubbleSteps=10;
var bubbleFast=2;
var bubbleClose=1;
var numMenuClosing=0;
var timer=new Array();
var timerIndex=0;
var finalOpacity=90;

bubble=getBrowserQuality();

function highlightRootItem(obj,num)
{
 var menuObjName="menu"+num;
 var hlpOffset=0;
 var visible=0;
 var hlpObj=document.getElementById(menuObjName);

 obj.className="mItemOver";
 hideMenu(num);
 if (hlpObj!=null)
 {
  if (hlpObj.style.display=="block") visible=1;
  hlpObj.style.display="block";
  numMenuClosing=0;
  hlpOffset=hlpObj.offsetWidth-obj.offsetWidth;
  if (hlpOffset<0) hlpObj.style.width=(obj.offsetWidth-1)+"px";
  if (obj.offsetLeft+obj.offsetWidth+hlpOffset<=document.getElementById("root").offsetWidth) hlpObj.style.left=obj.offsetLeft+"px";
  else hlpObj.style.left=obj.offsetLeft-hlpOffset+"px";
  hlpObj.style.top=document.getElementById("headImg").offsetHeight+document.getElementById("headImg").offsetTop+obj.offsetHeight+33+"px";
  hlpObj.style.clip="rect(auto auto auto auto)";
  hlpObj.style.filter="alpha(opacity="+finalOpacity+")";
  hlpObj.style.opacity=finalOpacity/100;
  if (bubble && !visible) bubbleMenu(menuObjName,0);
 }
}

function lowlightRootItem(obj,num)
{
 obj.className="mItem";  
}

function highlightItem(obj,numMenu)
{
 var menuObjName="rootItem"+numMenu;
 var hlpOffset=0;
 var hlpObj=document.getElementById(menuObjName);

 hlpOffset=obj.offsetWidth-hlpObj.offsetWidth;
 if (hlpOffset<0) obj.width=hlpObj.offsetWidth+"px";
 obj.className="itemOver";
}

function lowlightItem(obj)
{
 obj.className="item";
}

function hideObject(obj)
{
 obj.style.display="none";
}

function hideMenu(num)
{
 var i;
 var obj;
 var hlpStr;

 resetTimer();
 if (maxRootmenuItems>=num)
  for (i=1;i<=maxRootmenuItems;i++)
  {
   obj=document.getElementById("menu"+i);   
   if (i!=num && obj!=null)
    if (obj.style.display=="block")
     if (num==0 && numMenuClosing!=i && bubble && bubbleClose) closeMenu("menu"+i,i,obj.offsetHeight);
     else hideObject(obj);
  }
}

function bubbleMenu(menuObjName,y)
{
 var hlpStr, hlpStr2, hlpStr3;
 var opacity;
 var hlpObj=document.getElementById(menuObjName);
 var hlpHeight=0;
 var step=10;
 var opacityIncrement;

 if (hlpObj!=null)
 {
  hlpHeight=hlpObj.offsetHeight;
  step=Math.round(hlpHeight/numBubbleSteps+0.5);
  if (y<=hlpHeight+step)
  {
   hlpStr="rect(auto auto "+y+"px auto)";
   y+=step;   
   opacity=Math.round(100*y/hlpHeight);
   if (opacity>finalOpacity) opacity=finalOpacity;
   hlpStr2="alpha(opacity="+opacity+")";
   hlpStr3="bubbleMenu(\""+menuObjName+"\","+y+")";
   hlpObj.style.clip=hlpStr;
   hlpObj.style.filter=hlpStr2;
   hlpObj.style.opacity=opacity/100;
   timer[timerIndex]=window.setTimeout(hlpStr3,Math.round(bubbleFast*100/numBubbleSteps));
   timerIndex++;
  }
 }
}

function closeMenu(menuObjName,num,y)
{
 var hlpStr, hlpStr2, hlpStr3;
 var opacity;
 var hlpObj=document.getElementById(menuObjName);
 var hlpHeight=0;
 var step=10;
 var opacityIncrement;

 if (hlpObj!=null)
 {
  hlpHeight=hlpObj.offsetHeight;
  step=Math.round(hlpHeight/numBubbleSteps+0.5);
  if (y>=step)
  {
   hlpStr="rect(auto auto "+y+"px auto)";
   y-=step;   
   opacity=Math.round(200*y/hlpHeight);
   if (opacity<0) opacity=0;
   hlpStr2="alpha(opacity="+opacity+")";
   hlpStr3="closeMenu(\""+menuObjName+"\","+num+","+y+")";
   hlpObj.style.clip=hlpStr;
   hlpObj.style.filter=hlpStr2;
   hlpObj.style.opacity=opacity/100;
   numMenuClosing=num;
   timer[timerIndex]=window.setTimeout(hlpStr3,Math.round(bubbleFast*100/numBubbleSteps));
   timerIndex++;
  }
  else { resetTimer(); numMenuClosing=0; hideObject(hlpObj); }
 }
}

function resetTimer()
{
 var i;

 for (i=0;i<=timerIndex;i++)
  if (timer[i]!=null) clearTimeout(timer[i]);
 timerIndex=0;
}

function getBrowserQuality()
{
 var result=0;
 var browser=navigator.appName;
 var browserVersion=navigator.appVersion;
 var version=parseFloat(browserVersion);
 if ((browser=="Netscape" || browser=="Microsoft Internet Explorer") && (version>=5)) result=1;
 return(result);
}

function updateMenuPos(lang)
{
 if (document.formType.type.value==1 && lang!="en") document.formType.mid.value=44;
 else document.formType.mid.value=0;
}

function doItem(mid,anchor,wstyle,wnum)
{
 var hlpLocalDir=getMetaContent('contentdir');
 var hlpPath;
 var hlpStr;

 if (hlpLocalDir=="." || hlpLocalDir=="./") hlpLocalDir="";
 hlpPath="http://www.ahmp.cz/"+hlpLocalDir;
 hlpStr=hlpPath+"index.html?mid="+mid+"&wstyle="+wstyle+"&page='"+anchor+"'";

 if (wnum>0) parent.frames[wnum].location.href=hlpStr;
 else parent.location.href=hlpStr;

/*
 if (num==1) parent.location.href="index.html?t=1";
 else if (num==2) parent.location.href="index.html?t=2";
 else if (num==7) window.open("");
 else if (num==8) parent.location.href="index.html";
 else if (num==9) parent.frames[1].location.href="item1.html";
*/
}

function getMetaContent(element)
{
 var m=document.getElementsByTagName('meta');
 for(var i in m)
  if(m[i].name==element) return m[i].content;
}

function redirect(anchor)
{
 var hlpPath;

 if (anchor.search(/http/i)<0) hlpPath="http://www.ahmp.cz/";

 parent.location.href=hlpPath+anchor;
}

function showPage(anchor)
{
 window.open(anchor);
}
