var cElement;
var sMenuArea;
var sMenuTable;
var menuPic=new Array(4);
var output;
var windowWidth;
var menuPosLeft;
var cursorHot=0;
var timerID="notSet";
var item;
var link;
var href;
var cHeight;
var aHeight;
var functionExecuted;
var cMenu;
var menuBuilding=0;
var menuBuild=0;
var nMenu="notSet";
var nID="notSet";
var alreadyDeleting=0;
var rollSpeed=50;
var removeAnyway=0;
var IE=0;
var Opera=0;
var Netscape=0;
var AppVersion=window.navigator.appVersion;
var pos=0;
var fitPageToBrowser=0;
var flashTimer="notSet";
var currentColor;
var previousColor;
var tLength=0;
var maxMenuLength=10;

if(window.navigator.appName=='Netscape')	{

 Netscape=1;

}

if(window.navigator.appName=='Microsoft Internet Explorer')	{

 if(window.navigator.userAgent.indexOf('Opera')!=-1)	{

  Opera=1;  

 }

 else	{

  pos=AppVersion.indexOf('MSIE ');

  AppVersion=parseFloat(AppVersion.substring(pos+5, pos+8));

  if(AppVersion>=5)	{

   IE=1; 

  }

 }

}


function createMenu(id, menu)	{

 if(mainItems[menu].length>1 && !menuBuilding && !menuBuild)	 {

  cursorHot=1;

  cElement=document.getElementById(id);
  sMenuArea=document.getElementById("subMenuArea");
  menuPic[0]=document.getElementById("menuEndLeft");
  menuPic[1]=document.getElementById("menuEndCenter");
  menuPic[2]=document.getElementById("menuEndRight");
  menuPic[3]=document.getElementById("menuEnd");

  if(!menuPic[0])	{

   menuPic[0]=menuPic[3];

  }

  if(!menuPic[1])	{

   menuPic[1]=menuPic[3];

  }

  if(!menuPic[2])	{

   menuPic[2]=menuPic[3];

  }
 
  if(!menuPic[3])	{

   menuPic[3]=menuPic[0];

  }

  if(mainItems[menu].length>maxMenuLength)	{

   output="<table id=\"subMenuTable\" cellpadding=0 cellspacing=2 onmouseover=\"cursorHot=1\" onmouseout=\"cursorHot=0, menuUseless()\">";

  }

  else	{

   output="<table id=\"subMenuTable\" cellpadding=0 cellspacing=2 onmouseover=\"cursorHot=1\" onmouseout=\"cursorHot=0, menuUseless()\">";

  }

  for(var i=1; i<mainItems[menu].length; i++)	{

   output+="<tr>";

   for(var x=1; x<=Math.ceil(mainItems[menu].length/maxMenuLength); x++)	{

    if((i+((x-1)*maxMenuLength))<mainItems[menu].length)	{

     item=mainItems[menu][(i+((x-1)*maxMenuLength))];
     link=item.substring(0, item.indexOf("=>"));
     href=item.substring(item.indexOf("=>")+2, item.length);

     output+="<td class=\"subMenuTD\" id=\""+menu+i+x+"\" onmouseover=\"hLMenu(this.id)\" onmouseout=\"dLMenu(this.id)\" ";
     output+="onclick=\"goTo('"+href+"')\">&nbsp; &nbsp;"+link+"</td>";

    }

   }

   output+="</tr>";

   if(i==maxMenuLength)	{

    break;

   }
 
  }

  output+="</table>";

  tLength=mainItems[menu].length;
 
  windowWidth=document.body.clientWidth;

  sMenuArea.innerHTML=output;

  sMenuTable=document.getElementById("subMenuTable");

  sMenuArea.style.top=150;

  if(mainItems[menu].length>maxMenuLength)	{

   menuPic[0].style.top=150+((maxMenuLength)*24)+2;
   menuPic[1].style.top=150+((maxMenuLength)*24)+2;
   menuPic[2].style.top=150+((maxMenuLength)*24)+2;
   menuPic[3].style.top=150+((maxMenuLength)*24)+2;

  }

  else	{

   menuPic[0].style.top=150+((mainItems[menu].length-1)*24)+2;
   menuPic[1].style.top=150+((mainItems[menu].length-1)*24)+2;
   menuPic[2].style.top=150+((mainItems[menu].length-1)*24)+2;
   menuPic[3].style.top=150+((mainItems[menu].length-1)*24)+2;

  }

  menuPosLeft=document.getElementById("bodyTable").offsetLeft+cElement.offsetLeft-7;

  if((menuPosLeft+200)>windowWidth)	{

   menuPosLeft=windowWidth-210;

  }

  sMenuArea.style.left=menuPosLeft;
  menuPic[0].style.left=menuPosLeft;
  menuPic[1].style.left=menuPosLeft+8;
  menuPic[2].style.left=menuPosLeft+(Math.ceil(tLength/maxMenuLength)*150)-8;

  if(menuPic[0]==menuPic[1] && menuPic[1]==menuPic[2])	{
 
   menuPic[3].style.left=menuPosLeft;

  }

  functionExecuted=0;
  cHeight=0;
  cMenu=menu;
  menuBuilding=1;
  removeAnyway=0;

  if(mainItems[menu].length>maxMenuLength)	{

   timerID=setTimeout("openMenu("+maxMenuLength+");", 100); 

  }

  else	{

   timerID=setTimeout("openMenu("+mainItems[menu].length+");", 100); 

  } 

 }

 else	{

  if(menu!=cMenu && cMenu!="notSet")	{

   functionExecuted=0;
   clearTimeout(timerID);
   nMenu=menu;
   nID=id;
   menuBuilding=1;
   deleteMenu();

  }  

 }

}


function openMenu(nrItems)	{

 aHeight=(5*Math.pow(1.8,functionExecuted));

 if(timerID!="notSet")	{

  clearTimeout(timerID);

 }

 if((cHeight+aHeight)<(((nrItems-1)*26)+12))	{

  cHeight+=aHeight;
  sMenuArea.style.height=cHeight;
  sMenuTable.style.visibility="visible";

  if(tLength>maxMenuLength)	{

   sMenuTable.style.width=Math.ceil(tLength/maxMenuLength)*150;

  }

  functionExecuted++;
  timerID=setTimeout("openMenu("+nrItems+");", rollSpeed);  
  
 }

 else	{

  cHeight=((nrItems-1)*26)+12;
  sMenuArea.style.height=cHeight;

  if(menuPic[0]!=menuPic[1] && menuPic[1]!=menuPic[2])	{

   menuPic[0].style.visibility="visible";
   menuPic[1].style.visibility="visible";
   menuPic[2].style.visibility="visible";

  }

  else	{

   menuPic[3].style.visibility="visible";

  }

  if(tLength>maxMenuLength)	{

   sMenuTable.style.width=Math.ceil(tLength/maxMenuLength)*150;

   if(menuPic[0]!=menuPic[1] && menuPic[1]!=menuPic[2])	{

    menuPic[1].style.width=Math.ceil(tLength/maxMenuLength)*150-16;
    menuPic[1].style.height=8;

   }

   else	{

    menuPic[3].style.width=Math.ceil(tLength/maxMenuLength)*150;

   }

  }

  else	{

   if(menuPic[0]!=menuPic[1] && menuPic[1]!=menuPic[2])	{

    menuPic[1].style.width=150-16;

   }

   else	{

    menuPic[3].style.width=150;

   }

  }

  menuBuilding=0;
  menuBuild=1;
  
  if(removeAnyway && !cursorHot)	{

   menuUseless();

  }
  
 }

}


function menuUseless()	{

 if(!menuBuilding && menuBuild)	 {

  if(timerID!="notSet")	  {

   clearTimeout(timerID);

  }

  functionExecuted=0;
  timerID=setTimeout("deleteMenu();", 800);

 }

 if(menuBuilding && !menuBuild)	{
 
  setTimeout("delayStop()", 500); 

 }

}


function delayStop()	{

 if(!cursorHot && menuBuild)	{

  if(timerID!="notSet")	  {

   clearTimeout(timerID);

  }

  functionExecuted=0;
  timerID=setTimeout("deleteMenu();", 400)

 }

 if(!cursorHot && !menuBuild)	{

  removeAnyway=1;

 }

}


function deleteMenu()	{

 if(!cursorHot || alreadyDeleting)	{

  if(menuPic[3])	{

   menuPic[0].style.visibility="hidden";
   menuPic[1].style.visibility="hidden";
   menuPic[2].style.visibility="hidden";
   menuPic[3].style.visibility="hidden";

  }

  menuBuilding=1;

  alreadyDeleting=1;

  aHeight=(25*Math.pow(1.6,functionExecuted));

  if(timerID!="notSet")	{

   clearTimeout(timerID);

  }

  if((cHeight-aHeight)>0)	{

   cHeight-=aHeight;
   sMenuArea.style.height=cHeight;
   functionExecuted++;
   menuBuilding=1;
   timerID=setTimeout("deleteMenu();", rollSpeed);  
   
  }

  else	{

   if(sMenuTable)	{

    sMenuTable.style.visibility="hidden"; 

   }

   menuBuilding=0;
   menuBuild=0;
   cMenu="notSet";
   alreadyDeleting=0;

   if(nMenu!="notSet" && nID!="notSet")	{

    createMenu(nID, nMenu);
    nMenu="notSet";
    nID="notSet";

   }

  }

 }

}


function hLMenu(id)	{

 if(!menuBuilding)	{

  document.getElementById(id).style.background="#e3b426";
  document.getElementById(id).style.color="white";
  document.getElementById(id).style.border="solid 1px #e39126";

 }

}


function dLMenu(id)	{

 document.getElementById(id).style.background="#e39f26";
 document.getElementById(id).style.color="white";
 document.getElementById(id).style.border="solid 1px #e39f26";

}


function goTo(link)	{

 if(link!="")	{

  if( link.indexOf( "?" ) != -1 )  {

   location.href=navString+link+"&userID="+session_id; 

  }

  else  {

   location.href=navString+link+"?userID="+session_id; 

  }

 }

}

function setSizes(width, height)	{

 if(document.body.offsetWidth<(width+60))	{

  window.resizeBy(((width+60)-document.body.offsetWidth), 0);

 }

 if(document.body.offsetHeight<(height+100))	{

  window.resizeBy(0,((height+100)-document.body.offsetHeight));   

 }

}

function extendPage(id)	{

 var originalHeight=(document.getElementById("centerTD").offsetHeight);
 var picHeight=158;

 if(originalHeight>466)	{

  var newHeight=((Math.ceil((originalHeight/picHeight)))*picHeight)-8;

  if((Math.ceil(originalHeight/picHeight)-(originalHeight/picHeight))<(8/picHeight))	{

   newHeight+=picHeight;
  
  }

  document.getElementById("leftDiv").style.height=newHeight;
  document.getElementById("rightDiv").style.height=newHeight;

 }

 if(id=="short")	{

  document.getElementById("leftDiv").style.height=308;
  document.getElementById("rightDiv").style.height=308;

 }

 if(flashNews)	{

  flashButton("mLink07");

 }

}

function flashButton(id)	{

 if(flashTimer!="notSet")	{

  clearTimeout(flashTimer);

 }

 currentColor=document.getElementById(id).style.color;

 if(currentColor!="rgb(255, 51, 0)")	{

  document.getElementById(id).style.color="rgb(255, 51, 0)";
  document.getElementById(id).style.textDecoration="underline";

 }

 else	{

  document.getElementById(id).style.color=previousColor;
  document.getElementById(id).style.textDecoration="none";

 }

 previousColor=currentColor;

 flashTimer=setTimeout("flashButton('"+id+"');", 1000);

}
