var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

function dropdown_open(){  
	dropdown_canceltimer();
	dropdown_close();
	ddmenuitem = $(this).find('ul').css('visibility', 'visible');
	
	//MAKES DROPDOWN SAME WIDTH AS BUTTON
	ddwidth = $(this).width() + "px";
	ddmenuitem.css('width', ddwidth)
}

function dropdown_close() { 
	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden'); 
}

function dropdown_timer() { closetimer = window.setTimeout(dropdown_close, timeout); }

function dropdown_canceltimer() {  
	if(closetimer) {
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}
document.onclick = dropdown_close;

$(document).ready( function() {

	//DROPDOWN MENUS
	$('#dropdown > li').bind('mouseover', dropdown_open);
	$('#dropdown > li').bind('mouseout',  dropdown_timer);

	//CELL PHONE NUMBER MASK
	jQuery(function($){
		$(".phone-number").mask("(999) 999-9999");
	});

	//CLEAR DEFAULT TEXT
	(function($){
		$.fn.clearDefault = function(){
			return this.each(function(){
				var default_value = $(this).val();
				$(this).focus(function(){
					if ($(this).val() == default_value) $(this).val("");
				});
				$(this).blur(function(){
					if ($(this).val() == "") $(this).val(default_value);
				});
			});
		};
	})(jQuery);
	$('input[type="text"]').clearDefault(); //ALL TEXT INPUTS
	
	$("img.rollover").hover(
		function() {
			this.src = this.src.replace(".jpg","-over.jpg");
		},
		function() {
			this.src = this.src.replace("-over.jpg",".jpg");
	});
	
});

