var DDSPEED = 10;
var DDTIMER = 15;

// main function to handle the mouse events //
function ddMenu(id,d,idmenue){
  var vorher = id-1;	
  var doc = document;
	
  var h = doc.getElementById(id + '-ddheader');
  var c = doc.getElementById(id + '-ddcontent');
  doc.getElementById(id + '-ddheader').style.backgroundImage = "url(/web/images/dummy.gif)";
  if(d == 1  || id == idmenue )
  {
	doc.getElementById(id + '-ddlink').style.color = "#14366c";
	doc.getElementById(id + '-ddheader').style.backgroundImage = "url(/web/images/menue_high.gif)";
	if(id > 1) {doc.getElementById(vorher + '-ddheader').style.backgroundImage = "url(/web/images/dummy.gif)";}	
  }

  if(d != 1 && id != idmenue) {doc.getElementById(id + '-ddlink').style.color = "#fff"}
  
  if(d != 1) {doc.getElementById(id + '-ddheader').style.backgroundImage = "url(/web/images/menue_strich.gif)";}
   
  if(d != 1 && id > 1) {doc.getElementById(vorher + '-ddheader').style.backgroundImage = "url(/web/images/menue_strich.gif)";}
  
 /*
  * If browser is IE6, then display the menu
  * without visual effects. Otherwise with visual effects.
  */	
  if(isIE6() && d == 1) {
	c.style.display='block'
	showIframe(id);
  }		
  else if(isIE6() && d == -1) {
	c.style.display='none';
	hideIframe();
  }		
  else {	
	  clearInterval(c.timer);
	  //if(id > 1 && d == 1){doc.getElementById(vorher + '-ddlink').style.borderRight = '0px';doc.getElementById(vorher + '-ddlink').style.paddingRight = '17px';}
	  //if(id > 1 && d == -1){doc.getElementById(vorher + '-ddlink').style.borderRight = '1px solid #ffffff';doc.getElementById(vorher + '-ddlink').style.paddingRight = '16px';}
	  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);
	  }
  }	/* End:: Browser dependent display */
	
}
function showMenu(id,d,idmenue) {
	var c = document.getElementById(id + '-ddcontent');
	c.style.display = 'block';
	c.style.height = 'auto';
	showIframe(id);
}
function hideMenu(id,d,idmenue) {
	
	var ul = document.getElementById(id + '-ul');

	if(ul.style.display == 'none') {
		var c = document.getElementById(id + '-ddcontent');
		c.style.display = 'none';
	}
	
}

// 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) {

  if(isIE6()) {
		var c = document.getElementById(id + '-ddcontent');
		c.style.display = 'block';
		showIframe(id);
  } 
  else { 		
	  var vorher = id-1;	
	  var h = document.getElementById(id + '-ddheader');
	  var c = document.getElementById(id + '-ddcontent');
	  document.getElementById(id + '-ddheader').style.backgroundImage = "url(/web/images/menue_high.gif)";
	  document.getElementById(id + '-ddlink').style.color = "#14366c";
	  //document.getElementById(id + '-ddlink').style.borderRight = '0px';
	  //document.getElementById(id + '-ddlink').style.paddingRight = '17px';
	  if(id > 1){document.getElementById(vorher + '-ddheader').style.backgroundImage = "url(/web/images/dummy.gif)";}
	  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';
  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)){
    clearInterval(c.timer);
  }
}

function isIE6() {
	var isIE6 = false;
		
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
	{
	 var ieversion=new Number(RegExp.$1) 

		 if (ieversion>=6 && ieversion < 7)
		{
  			isIE6 = true;
		}
	}
	return isIE6;
}

function showIframe(id) {

	var c = document.getElementById(id + '-ddcontent');
	var iFrame = document.getElementById("iframe_hack");

	c.style.position="absolute";
	c.style.top=c.offsetTop + 'px';
	c.style.left=c.offsetLeft + 'px';
	c.style.zIndex=9;

	if(iFrame.style.display != "block") {
		iFrame.style.left =c.offsetLeft + 'px';
		iFrame.style.top =c.offsetTop + 'px';
		iFrame.style.width =c.offsetWidth + 'px';
		iFrame.style.height =c.offsetHeight + 'px';
		iFrame.style.display ='block';
		iFrame.style.zIndex ='4';
	}

	

}	

function hideIframe() {
	var iFrame = document.getElementById("iframe_hack");
	iFrame.style.display ='none';
}