var timeout;
var nSlideTime = 0.5; // seconds
var strSelect = "div.dropdown";
var strOption = "div.options";
jQuery.easing.def = "easeOutQuart";

function hideDropdown(object) {
	$(object).slideUp((nSlideTime*1000),function(){ clearTimeout(timeout); }); // hide the object parameter and when done clear timeout
}

$(document).ready(function(){

	$(strSelect).find("button").click(function(){
		if ($(strSelect+" "+strOption).is(':hidden')) { // if the options are hidden then show them
			$(strSelect+" "+strOption).slideDown((nSlideTime*1000)); // show dropdown options
			timeout = setTimeout("hideDropdown(strSelect+' '+strOption)",3000); // set a long timeout for when the user doesn't hover at all
		} else { // if the options are visible then hide them
			hideDropdown(strSelect+" "+strOption); // hide dropdown options
		}
	});

	$(strSelect+" "+strOption).hover(function(){ 
		clearTimeout(timeout); // when we hover over the dropdown list reset the timeout so we don't hide it
	},function(){
		timeout = setTimeout("hideDropdown(strSelect+' '+strOption)",(nSlideTime*1000)); // timeout must be the same as slide time .. i know this is a flaw but i dont care ;)
	});
	
	$(strSelect+" "+strOption).find("ul li a").click(function(){
		$(strSelect).find("p.label").text($(this).text()); // replace label with selected option value
		$(strSelect+" "+strOption).find("ul li").removeClass("active"); // remove all active states
		$(this).parent("li").addClass("active"); // add new active state
		hideDropdown(strSelect+" "+strOption); // hide dropdown options
	});

});