// JavaScript Document
$(document).ready(function(){
	navsearch.init();
});

/* START applesearch object */
		
if (!navsearch)	var navsearch = {};

navsearch.init = function ()
{
	// add applesearch css for non-safari, dom-capable browsers
	if ( navigator.userAgent.toLowerCase().indexOf('safari') < 0  && document.getElementById )
	{
		this.clearBtn = false;
		
		// add style sheet if not safari
		var dummy = document.getElementById("dummy_css");
		if (dummy)	dummy.href = "/css/navSearch.css";
		
	}
}

// called when on user input - toggles clear fld btn
navsearch.onChange = function (fldID, btnID)
{
	// check whether to show delete button
	var fld = document.getElementById( fldID );
	var btn = document.getElementById( btnID );
	if (fld.value.length > 0 && !this.clearBtn)
	{
		btn.style.background = "white url('/images/imgNav/navsearch_r2.gif') no-repeat top left";
		btn.fldID = fldID; // btn remembers it's field
		btn.onclick = this.clearBtnClick;
		this.clearBtn = true;
	} else if (fld.value.length == 0 && this.clearBtn)
	{
		btn.style.background = "white url('/images/imgNav/navsearch_r.gif') no-repeat top left";
		btn.onclick = null;
		this.clearBtn = false;
	}
}


// clears field
navsearch.clearFld = function (fldID,btnID)
{
	var fld = document.getElementById( fldID );
	fld.value = "";
	this.onChange(fldID,btnID);
}

// called by btn.onclick event handler - calls clearFld for this button
navsearch.clearBtnClick = function ()
{
	navsearch.clearFld(this.fldID, this.id);
}

/* END applesearch object */

/**
 * Written by Rob Schmitt, The Web Developer's Blog 
 * http://webdeveloper.beforeseven.com/ 
 */
 /** 
 * The following variables may be adjusted */
 var active_color = '#000000'; // Colour of user provided text
 var inactive_color = '#969696'; // Colour of default text
 /** 
 * No need to modify anything below this line 
 */
$(document).ready(function() {
/** Start Searchfield default value **/
  $("input.navSearchColor").css("color", inactive_color);
	var default_values = new Array();
	$("input.navSearchColor").focus(function() {
		if (!default_values[this.id]) {
			default_values[this.id] = this.value;
		}
		if (this.value == default_values[this.id]) {
			this.value = '';
			this.style.color = active_color;
		}
		$(this).blur(function() {
			if (this.value == '') {
				this.style.color = inactive_color;
				this.value = default_values[this.id];
			}
		});
	});
/** End Searchfield default value **/

});