/*
 * Handle the search box events (setting default values and clearing them
 * when the user puts focus to the box)
 *
 * The default values are set by the "title" attribute of the input tags.
 */



// Wait for the document to be ready.
$(document).ready(function() {



	// on focus clear the text and change style if it is the default (title).
	// on blur put the default back if the box is blank.
	$("#searchWhat, #searchWhere").focus(function() {
		if( $(this).val() == $(this).attr("title") ) {
			$(this).val("");
			$(this).removeClass("searchInputTextDefault");
			$(this).addClass("searchInputText");
		}
	}).blur(function() {
		if( $(this).val() == "" ) {
			$(this).val($(this).attr("title"));
			$(this).removeClass("searchInputText");
			$(this).addClass("searchInputTextDefault");
		}
	});


	// When the page loads set the default value from the title.
	$("#searchWhat, #searchWhere").blur();


	// If someone comes to the page with a value other than blank or the default
	// (back button or refresh) then set the appropriate style.
	if ( $("#searchWhat").val() != $("#searchWhat").attr("title") ) {
		$("#searchWhat").removeClass("searchInputTextDefault");
		$("#searchWhat").addClass("searchInputText");
	}
	if ( $("#searchWhere").val() != $("#searchWhere").attr("title") ) {
		$("#searchWhere").removeClass("searchInputTextDefault");
		$("#searchWhere").addClass("searchInputText");
	}

	
	// Clear out the search boxes if they still have the default values when
	// the user clicks Go.
	$("#searchGo").click(function() {
		if ( $("#searchWhat").val() == $("#searchWhat").attr("title") ) {
			$("#searchWhat").val("");
		}
		if ( $("#searchWhere").val() == $("#searchWhere").attr("title") ) {
			$("#searchWhere").val("");
		}
	});


});


