/**
 * Static class for the search box with an "over label".
 *
 * Inspiration for this came from the A List Apart article "Making Compact Forms More Accessible"
 * http://www.alistapart.com/articles/makingcompactformsmoreaccessible/
 */
SearchBox = {

	form: null,
	input: null,
	label: null,

	/**
	 * Initializes the over label search box.
	 */
	init: function()
	{
		/* get DOM elements */
		SearchBox.form = $("search");
		SearchBox.input = $("q");
		SearchBox.label = $("q-label");

		/* Add a custom onsubmit event for the search form, not submitting it
		 * when no query has been entered.
		 */
		connect(SearchBox.form, "onsubmit", function (e) { if (SearchBox.input.value == "") { e.stop(); } });

		/* show the label if field is empty */
		if (SearchBox.input.value == "")
		{
			SearchBox.showLabel();
		}

		/* hide the label when clicked or the input field gets focus */
		connect(SearchBox.input, "onfocus", SearchBox.hideLabel);
		connect(SearchBox.label, "onclick", SearchBox.hideLabel);

		/* if the input field loses focus, and no text has been entered, show the label */
		connect(SearchBox.input, "onblur", function () { if (SearchBox.input.value == "") { SearchBox.showLabel(); } });
	}, // function init

	/**
	 * Shows the label.
	 */
	showLabel: function()
	{
		/* add the "over label" class, showing the label */
		addElementClass(SearchBox.label, "overlabel");
	}, // function showLabel

	/**
	 * Hides the label.
	 */
	hideLabel: function()
	{
		/* remove the "over label" class, hiding the label */
		removeElementClass(SearchBox.label, "overlabel");
	} // function hideLabel

}; // class SearchBox

/* initialize the over label search box on document load */
addLoadEvent(SearchBox.init);