		
function swapNav(navItem,on){
	var item = document.getElementById(navItem);
	
	if(on == 1){
		item.src = "templates/lifeBLUE/images/nav_" + navItem + "_on.gif";
		on = 1;
	} else {
		item.src = "templates/lifeBLUE/images/nav_" + navItem + ".gif";
		on = 0;
	}
}

var DDSPEED = 10;
var DDTIMER = 15;

// main function to handle the mouse events //
function ddMenu(id,d){
	
  var h = document.getElementById(id);
  var c = document.getElementById(id + '_submenu');
    
  if(c){
	  // lets set our position
	  var xpos = lbElementGetX(h);
	  if (navigator.userAgent.indexOf("Firefox")!=-1){
	  	xpos = xpos - 40;
	  }
	  var ypos = lbElementGetY(h) + h.offsetHeight;
	  
	  c.style.left = xpos + "px";
	  c.style.top = ypos + "px";
	  
	  clearInterval(c.timer);
	  if(d == 1){
	  	//addClass(h, "nav_active");
	  	swapNav(id, 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)},100);
	    //removeClass(h, "nav_active");
	    swapNav(id, 0);
	  }
  }
}

// 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(id);
  var c = document.getElementById(id + '_submenu');
  if(c){
  	
	  clearTimeout(h.timer);
	  clearInterval(c.timer);
	  swapNav(id, 1);
	  //addClass(h, "nav_active");
	  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';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
  	if(d != 1){
  		
  		c.style.height = "0px";
  	}
    clearInterval(c.timer);
  }
}

function lbElementGetX(elem){
	
	var xpos = elem.offsetLeft;
	var tempe = elem.offsetParent;
	while (tempe != null){
    	xpos += tempe.offsetLeft;
       	tempe = tempe.offsetParent;
    }
    
    return(xpos); 
	
}

function lbElementGetY(elem){
	
	var ypos = elem.offsetTop;
	var tempe = elem.offsetParent;
	while (tempe != null){
    	ypos += tempe.offsetTop;
       	tempe = tempe.offsetParent;
    }
    
    return(ypos); 
	
}


/*
 
Correctly handle PNG transparency in Win IE 5.5 & 6.
http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.

Use in <HEAD> with DEFER keyword wrapped in conditional comments:
<!--[if lt IE 7]>
<script defer type="text/javascript" src="pngfix.js"></script>
<![endif]-->

*/

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters)) 
{
   for(var i=0; i<document.images.length; i++)
   {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
         img.outerHTML = strNewHTML
         i = i-1
      }
   }
}

