jQuery(document).ready(function() {
	/* BLOG DIRECTORY button handling */
	jQuery("li#n1").mouseenter(
			function(){
				jQuery("div#blogmenuwrapper").slideDown(100);
				jQuery(this).css({background:"#03386A"});
			}
	);
	jQuery("li#n1").mouseleave(
			function(){
				jQuery("div#blogmenuwrapper").hide();
				jQuery(this).css({background:"none"});
			}
	);
	/* SAS SOFTWARE button handling */
	jQuery("li#n2").mouseenter(
			function(){
				jQuery("div#sasmenuwrapper").slideDown(100);
				jQuery(this).css({background:"#03386A"});
			}
	);
	jQuery("li#n2").mouseleave(
			function(){
				jQuery(this).css({background:"none"});
				jQuery("div#sasmenuwrapper").hide();
			}
	);
	/* FOLLOW US button handling */
	jQuery("li#n3").mouseenter(
			function(){
				jQuery("div#followmenuwrapper").slideDown(100);
				jQuery(this).css({background:"#03386A"});
			}
	);
	jQuery("li#n3").mouseleave(
			function(){
				jQuery(this).css({background:"none"});
				jQuery("div#followmenuwrapper").hide();
			}
	);
	/* HIDE MENUS IF CLICKED SO NOT VISIBLE VIA BACKBUTTON */
	jQuery("div#blogmenuwrapper a").click(
			function(){
				jQuery("div#blogmenuwrapper").slideUp(250);
			}
	);
	jQuery("div#sasmenuwrapper a").click(
			function(){
				jQuery("div#sasmenuwrapper").slideUp(100);
			}
	);
	jQuery("div#followmenuwrapper a").click(
			function(){
				jQuery("div#followmenuwrapper").slideUp(100);
			}
	);
	
	
	/* Search Form handling */
	jQuery("input.searchfield").hint();
	
	/* Post views tool tip */
	jQuery("span.postviews").mouseenter(
		function(){
			jQuery(this).append("<span class='tip'>Total Views</span>").children().show();
		}
	).mouseleave(
		function(){
			jQuery(this).children('span.tip').remove();
		}
	);
	
	/* Comments tool tip */
	jQuery("span.postcomments").mouseenter(
		function(){
			jQuery(this).append("<span class='tip'>Total Comments</span>").children().show();
		}
	).mouseleave(
		function(){
			jQuery(this).children('span.tip').remove();
		}
	);
	

});


jQuery(window).bind('beforeunload', function() {
    //if (iWantTo) {
        //alert('foo');
    //}
}); 

jQuery.fn.hint = function () {
	// Get the search field
	var $input = jQuery(this),

	// Capture the rest of the form
	title = $input.attr("alt");
	$form = jQuery("form#searchform");
	
	// Load alt attribute into the value attribute
	$input.val(title);

	function remove() {
		if ($input.val() === title) {
			$input.val("");
		}
	}
	function validate() {
		if ($input.val() === title || jQuery.trim($input.val()) === '') {
			alert("Type your search in the search box");
			return false;
		}
	}

	// On focus, set value to blank
	$input.focus(remove);

	// Validate the input when form is submitted
	$form.submit(validate);
};
