// Dropdown menu
var hover = true;
$.fn.makeDropdown = function() {
	var obj		= $(this);
	var timer;
	
	obj.click(function() {
		if ($(this).hasClass("current")) {
			// slide up (hide)
			hideDropdown($(this));
		} else {
			// slide down (show)
			triggerAll(".current");
			showDropdown($(this));
		}
		return false;
	});
}

/* hide-show functions */
hideDropdown = function(obj) {
	stopTimer();
	obj.removeClass("current");
	obj.removeClass("expanded");
	// hide the drop down
	obj.find("+ ul").slideToggle("medium");
}
showDropdown = function(obj) {
	obj.addClass("current");
	obj.addClass("expanded");
	// show the drop down
	startTimer(obj);
	obj.find("+ ul").mouseover(function() {
//		stopTimer();
	}).mouseout(function() {
//		startTimer(obj);
	}).slideToggle("medium");
}
triggerAll = function(selector) {
	$(selector).each(function() {
		$(this).removeClass("current");
		$(this).removeClass("expanded");
		// hide the drop down
		$(this).find("+ul").slideToggle("medium");
	});
}
/* timer functions */
startTimer = function(obj) {
	timer = setTimeout(function() {
		hideDropdown(obj);
	}, 2000);
}
stopTimer = function() {
	clearTimeout(timer);
}
