var ie4=document.all;
var ns6=document.getElementById&&!document.all;

timer = 5000;
objDropDownItem = new Object;
objDropDownItem="";
intOpacity = 100;


function fnSwitchMenu(objSwitch, strMode, blnTimeout)
{
  if ((objDropDownItem!="")&&(objDropDownItem!=objSwitch))
    fnRemoveMenu();	
  
  fnFindBrowserStyle(document.getElementById(objSwitch)).display=strMode;
  if (objDropDownItem) changeOpacity(100, objDropDownItem);
  intOpacity = 100;
  
  if (blnTimeout)
    objDropDownItem="";
  else
    clearTimeout(timer);
  
  objDropDownItem = objSwitch;  
}

var DDSPEED = 3;
var DDTIMER = 15;

// main function to handle the mouse events //
function ddMenu(id,d){
  var h = document.getElementById('ddheader'+id);
  var c = document.getElementById('ddcontent'+id);
  c.style.display = "block";
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){ return}
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},50);
  }
}

// collapse the menu //
function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
  var h = document.getElementById('ddheader'+id);
  var c = document.getElementById('ddcontent'+id);
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;	
  }
  c.style.height = currh + (dist * d) + 'px';
  if (!ie4)
  {
	c.style.opacity = currh / c.maxh;
	c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  }
  
  //alert(currh);
  
  if((currh <= 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    if (currh==2) c.style.display = "none";
    clearInterval(c.timer);
  }
}

function fadeMenu()
{
  
  intOpacity-=10;
  
  changeOpacity(intOpacity, objDropDownItem);
  
  if (intOpacity <= 0)
    fnRemoveMenu();    
  else
    timer=setTimeout('fadeMenu()', 50);
}

function fnRemoveMenu()
{
  fnFindBrowserStyle(document.getElementById(objDropDownItem)).display="none";
  changeOpacity(100, objDropDownItem);
  intOpacity = 100;
}



function changeOpacity(newOpacity, objObject)
{
    if (ie4)
        fnFindBrowserStyle(document.getElementById(objObject)).filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+newOpacity+")"
    else
    {
        fnFindBrowserStyle(document.getElementById(objObject)).KhtmlOpacity = (newOpacity/100);
    	fnFindBrowserStyle(document.getElementById(objObject)).MozOpacity = (newOpacity/100);
    }  
}

function highlightMenu(menuId)
{  document.getElementById(menuId).className="menOver";	 }

function unHighlightMenu(menuId)
{  document.getElementById(menuId).className="";  }

function fnFindBrowserStyle(objIdent)
{ return ((ie4||ns6) ? objIdent.style : objIdent); }
