$(document).ready(function() {
	/* decorate search field */
	var searchfield = $("#ip_text");
	var searchbutton = $("#ip_submit");
	var language = window.location.pathname.substring(2,1).toLowerCase();

	if (searchfield) {
		// TODO: localization
		var defaultvalue = "Enter search term...";
		var pages = "Pages";
		switch (language) {
			case "d": 
				defaultvalue = "Suchbegriff eingeben...";
				pages = "/Seiten"; 
				break
			case "i": 
				defaultvalue = "";
				pages = "/Pagine"; 
				break
			case "f": 
				defaultvalue = "Entrez le mot de recherche...";
				pages = "/Pages"; 
				break
		}	
		searchfield.val(defaultvalue);

		/**
		 * open the language-specific target url for rendering the search results.
		 */
		var submitSearchForm = function() {
			var location = "/" + language + "/" +  pages + "/Results.aspx?k=" + searchfield.val();
			window.location = location;
		}
		
		/**
		  * handle the input hint while focussing/blurring the field 
		  */
		searchfield.focus(function() { 
			if ($(this).val() == defaultvalue ) { 
				$(this).val("") 
			} 
		});
		searchfield.blur(function() { 
			if ($(this).val() == "" ) { 
				$(this).val(defaultvalue) 
			} 
		});
		
		/**
		  * handle form submission, and the hover effect on the input[submit] element.
		  */		
		searchfield.keypress(function (e) {
			if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
				 submitSearchForm();
			} 
		});				
		searchbutton.hover(function() {
			$(this).addClass("hover");
		}, function() {
			$(this).removeClass("hover");
		});		
		searchbutton.click(function(e) { 
			e.preventDefault(); 
			submitSearchForm() 
		});		
	}
});