﻿var OneListBoxWidth = 7;
 //controls the list dropping speed, but... its the width of each "navigation item" surrounding box width
var ListDroppingTimer = 15;



// main function to handle the mouse events 


function ListDroppingMenu(id,d)
{
  
	var h = document.getElementById(id + '-ldheader');
  
	var c = document.getElementById(id + '-ldcontent');
  
	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;
 //<!--is a position of the mouse inside the list  -->   
			c.style.height = '0px';
    
		}
    
        c.timer = setInterval(function(){ListDroppingSlide(c,1)}, ListDroppingTimer);
 
	}
	else
	{
    
	    h.timer = setTimeout(function(){ListDroppingCollapse(c)},50);
 
	}

}



// collapse the menu 


function ListDroppingCollapse(c)
{
  
	c.timer = setInterval(function(){ListDroppingSlide(c,-1)},ListDroppingTimer);

}




// do not collapse if a user slides over the dropdown menu 
function cancelHide(id)
{
  
	var h = document.getElementById(id + '-ldheader');
  
	var c = document.getElementById(id + '-ldcontent');
  
	clearTimeout(h.timer);
  
	clearInterval(c.timer);
  
	if(c.offsetHeight < c.maxh)
	{
    
          c.timer = setInterval(function(){ListDroppingSlide(c,1)},ListDroppingTimer);
  
	}

}



// incrementally expand/contract the dropdown and change the opacity 
function ListDroppingSlide(c,d)
{
  
	var currh = c.offsetHeight;
  
	var dist;
  
	if(d == 1)
	{
    
		dist = (Math.round((c.maxh - currh) / OneListBoxWidth));
 //distance from 'dropdown one' menue is integer * the width of the list item box	
	}
	else
	{
    
	dist = (Math.round(currh / OneListBoxWidth));
  
	}
  
	if(dist <= 1 && d == 1){
 dist = 1;
  }
 //don't allow the fractional width each 'navigation item' 
 
	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);
  }


}