var dd = {
	speed : 10,
	delay : 10,
	
	// Initialize vars to hide and show the menu
	_toggle : function(id, display) {
		var link = document.getElementById(id + '_link');
		var element = document.getElementById(id + '_ddmenu');
		
		if (display == 1) {
			link.style.backgroundImage = "url('tpl/default/inc/img/ddmenu_hover.png')";
			var temp = element.offsetHeight;
			element.style.display = 'block';
			element.style.height = 'auto';
			element.maxHeight = element.offsetHeight;
			if (temp == element.maxHeight) {
				return;
			} 
			element.style.height = '0px';
		}	else {
			link.style.backgroundImage = 'none';
		}
		if (element.timer) {
			clearInterval(element.timer);
			element.timer = false;
		}

		element.timer = setInterval(function() {
				dd._hideAndShow(element, display);
			}, dd.delay);
	},
	
	// Hide and show the menu
	_hideAndShow : function(element, display) {
		var currentHeight = element.offsetHeight;
		var distance;
		
		if (display == 1) {
			distance = Math.ceil((element.maxHeight - currentHeight) / dd.speed);
		} else {
			distance = Math.ceil(currentHeight / dd.speed);
		}
		
		element.style.height = currentHeight + (distance * display) + 'px';
		element.style.opacity = currentHeight / element.maxHeight;
		element.style.filter = 'alpha(opacity = ' + (currentHeight / element.maxHeight * 100) + ')';
		
		if ((display == 1 && currentHeight >= element.maxHeight) || (display == -1 && currentHeight <= 0)) {
			clearInterval(element.timer);
			element.timer = false;
		}
	},
	
	// Cancel menu hide when the mouse is over the menu
	_cancel : function(id) {
		var link = document.getElementById(id + '_link');
		var element = document.getElementById(id + '_ddmenu');
		
		link.style.backgroundImage = "url('tpl/default/inc/img/ddmenu_hover.png')";
		
		clearInterval(element.timer);
		element.timer = false;
		
		if (element.offsetHeight < element.maxHeight) {
			element.timer = setInterval(function() {
					dd._hideAndShow(element, 1);
				}, dd.delay);
		}
	}
};