//var k = 0;
var tf_DROPDOWN = 
{
	ddspeed: 5,
	ddtimer: 25,
	i: [],
	
	// main function to handle the mouse events //
	ddMenu: function(id, i)
	{
		if(tf_PHP.isset(this.i[id]))
			this.i[id] = -this.i[id];
		else
			this.i[id] = i ? i : -1;
			
		d = this.i[id];
		
	  	var h = tf_DOM.$(id + '-ddheader');
	  	var c = tf_DOM.$(id + '-ddcontent');
	  	
	  	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';
	    	}
	    	
	    	var obj = this;
	    	c.timer = setInterval(function(){ obj.ddSlide(c, 1) }, this.ddtimer);
	  	}
	  	else
	  	{
	  		var obj = this;
	    	h.timer = setTimeout(function(){ obj.ddCollapse(c) }, 50);
	  	}
	},
	
	// collapse the menu //
	ddCollapse: function(c)
	{
		var obj = this;
  		c.timer = setInterval(function(){ obj.ddSlide(c, -1) }, this.ddtimer);
	},
	
	// cancel the collapse if a user rolls over the dropdown //
	cancelHide: function(id)
	{
		var h = tf_DOM.$(id + '-ddheader');
		var c = tf_DOM.$(id + '-ddcontent');
		
		clearTimeout(h.timer);
		clearInterval(c.timer);
		
		if(c.offsetHeight < c.maxh)
		{
			var obj = this;
			c.timer = setInterval(function(){ obj.ddSlide(c, 1) }, this.ddtimer);
		}
	},
	
	// incrementally expand/contract the dropdown and change the opacity //
	ddSlide: function(c, d)
	{
		var currh = c.offsetHeight;
		
		var	dist = (d == 1) ? Math.round((c.maxh - currh) / this.ddspeed) : Math.round(currh / this.ddspeed);
		dist = (dist <= 1) ? 1 : dist;
			
		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);
	}
}
