// Russell Thompson
// Project: FHCC website V3.0  
// Page: 'more specials' glide down
// Version Control
// 		Version 1.0
// 		Date 09/04/2008
// 
// Copyright (c) 2008 Russell Thompson and Freelance I.T. Solutions

var DDSPECIALSSPEED = 10;
var DDSPECIALSTIMER = 15;

// main function to handle the mouse events //
function ddSpecials(id,d)
{
	var h = document.getElementById(id + '-ddheader');
	var c = document.getElementById(id + '-ddcontent');
	
	if (d == 1)
	{
		h.innerHTML = "<span id=\"specialsTitle\" name=\"specialsTitle\" class=\"specialsTitle\" style=\"color: #FFFFFF\"><a href=\"javascript: ddSpecials('moreSpecials', -1);\" class=\"symbolLink\" style=\"color: #FFFFFF\">-</a>&nbsp;&nbsp;&nbsp;&nbsp;m o r e&nbsp;&nbsp;&nbsp;&nbsp;s p e c i a l s</span>";
		document.getElementById('specialsPanel').style.backgroundColor = "#FF6600";
	}
	else if (d == -1)
	{
		h.innerHTML = "<span id=\"specialsTitle\" name=\"specialsTitle\" class=\"specialsTitle\" style=\"color: #487634\"><a href=\"javascript: ddSpecials('moreSpecials', 1);\" class=\"symbolLink\" style=\"color: #487634\">+</a>&nbsp;&nbsp;&nbsp;&nbsp;m o r e&nbsp;&nbsp;&nbsp;&nbsp;s p e c i a l s</span>";
		document.getElementById('specialsPanel').style.backgroundColor = "#FFFFFF";
	}
	
	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';
	    }
	
    	c.timer = setInterval(function(){ddSpecialsSlide(c,1)},DDSPECIALSTIMER);
	}
	else
	{
	  h.timer = setTimeout(function(){ddSpecialsCollapse(c)},50);
	}
}

// collapse the menu //
function ddSpecialsCollapse(c)
{
	c.timer = setInterval(function(){ddSpecialsSlide(c,-1)},DDSPECIALSTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelSpecialsHide(id)
{
	var h = document.getElementById(id + '-ddheader');
	var c = document.getElementById(id + '-ddcontent');
	clearTimeout(h.timer);
	clearInterval(c.timer);
	if(c.offsetHeight < c.maxh)
	{
		c.timer = setInterval(function(){ddSpecialsSlide(c,1)},DDSPECIALSTIMER);
	}
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSpecialsSlide(c,d)
{
	var currh = c.offsetHeight;
	var dist;
	if(d == 1)
	{
		dist = (Math.round((c.maxh - currh) / DDSPECIALSSPEED));
	}
	else
	{
		dist = (Math.round(currh / DDSPECIALSSPEED));
	}
	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);
	}
}

