//bootstrap

$(function() {
	//does the input field exist
	var search_field = $("#site-search-field");
	var search_result = $("#ajax-search-result");
	if ( $(search_field).length > 0 ) {
		//attach keypress event
		$(search_field).keypress(function(){
			if($(search_field).val().length > 2)
			{
				$.get('/search?sq=' + $(search_field).val() + '&limit=15&offset=0&ajax=html', function(data){
					$(search_result).html(data);
				});
			}
		});
	}
});

// Remove text from input field onfocus

$(document).ready(function(){
	// identify the input box(es)
	var searchBoxes = $(".text");
	var searchBox = $("#site-search-field");
	var searchBoxDefault = "Search Ludus...";

	// js class adding to use later
	searchBoxes.focus(function(e){
		$(this).addClass("active");
	});
	// js class removing to use later
	searchBoxes.blur(function(e){
		$(this).removeClass("active");
		$(this).addClass("inactive");
	});

	// Clear the value on focus
	searchBox.focus(function(){
		if($(this).attr("value") == searchBoxDefault) $(this).attr("value", "");
	});
	// Focus lost and no text has been entered so let's roll back
	searchBox.blur(function(){
		if($(this).attr("value") == "") $(this).attr("value", searchBoxDefault);
	});

});
