/**************************************
/kindly taken from http://www.alistapart.com/articles/dropdowns
/adds over class to appropriate classe, as IE doesnt support li:hover
/**************************************/
startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI" || node.nodeName=="li") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					//this.className=this.className.replace(" over", "");
					this.className=this.className.replace(" over", " hide");
				}
			}
		}
	}
}
if (window.attachEvent) window.attachEvent('onload', startList);

// *************************
function swapImage(elm_id, src)
{
  var elm = document.getElementById(elm_id);
  elm.src = src;
}

// *************************
//IE hack for the dropdown-select problem
selectHide = function()
{
  //alert(ieDetect());
  if(ieDetect())  //if Internet explorer which is the only browser where the problem occurs
  {
    var ieULs = document.getElementById('nav').getElementsByTagName('ul');
    
    /** IE script to cover <select> elements with <iframe>s **/
    
    for (j=0; j<ieULs.length; j++)
    {

      //determines the height of each li element based on no of characters in each link      
      /*
      listItemCounter = 0;
      for (k = 0; k < ieULs[j].childNodes.length; k++)
      {
            text = ieULs[j].childNodes[k].childNodes[0]; 
            if (text.innerHTML.length < 32)
              listItemCounter++;
            else
              listItemCounter = listItemCounter + 2;
              
              //alert(text.innerHTML.length );
      }
      */
      //alert(listItemCounter);
      //insert iframe to hide select dropdowns
      ieULs[j].innerHTML = (ieULs[j].innerHTML + '<div></div><iframe title="IEBugHider" longdesc="This Iframe hides selectbox on dropdown because of IE bug" name="IEBugHider" style="filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)" id="iFrameHider" ' + j + '" src="about:blank" scrolling="no" frameborder="0"></iframe>');
      
	    var ieMat = ieULs[j].lastChild; //select iFrame in each UL

	    //ieMat.style.height = listItemCounter * 17 + 5 + "px";  //sets heigtht on iFrame. Based on no of LI and NOT actual height!!! TODO:base on actual height
	    
	    ieMat.style.height = ieULs[j].offsetHeight + "px";
      //ieMat.style.height = "0px";
      getStyleObject('iFrameHider' + j).zIndex="5"; //sets z-index to lower number than ul's
      ieULs[j].className = 'hide';
    }
  }
}
if (window.attachEvent) window.attachEvent('onload', selectHide);


/*--------------------------------------------------*/
//Internet explorer detect
function ieDetect()
{
  var detect = navigator.userAgent.toLowerCase();
  if (checkIt('msie'))
    return true;  
  return false;
  
  function checkIt(string)
  {
	  if ((detect.indexOf(string) + 1) && !(detect.indexOf('opera') + 1)) //hvis msie og ikke opera!!! :-)
	    return true;
	  return false;
  }
}


