//clear input box plugin
$.fn.search=function(){
	return this
	.focus(function(){if(this.value==this.defaultValue){this.value=""};})
	.blur(function(){if(!this.value.length){this.value=this.defaultValue};})
};

//-----------------------------------------
//validate search on submit
$.fn.validsearch=function(status, textbox){
	return this
	.submit(function(){
		var dvalue = $(textbox).attr("defaultValue");
		var value = $(textbox).attr("value");
		var error_msg = "Please enter a query before submitting.";
		if(dvalue==value){$(status).html(error_msg).fadeIn(300);setTimeout('$("' + status + '").fadeOut()', 2000);return false;};
	});
};

//-----------------------------------------
// hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+ <http://cherne.net/brian/resources/jquery.hoverIntent.html | author Brian Cherne <brian@cherne.net>
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:500};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

//nav dropdown
$.fn.dropdowns=function(){return this
.hoverIntent(function () {{$(this).children('ul').fadeIn(100);}},function () {$(this).children('ul').hide(100)});};


//global initialization
$(document).ready(function() {
	//keyword search form
	$("#keywords").search();
	$("#keywordform").validsearch(".tryagain", "#keywords");
	$('#primary_nav li.top').dropdowns();

});

// Added 10.2010 by R.Taylor
function getParam( name, obj )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( obj ); // was window.location.href
  if( results == null )
    return "";
  else
    return results[1];
}

function setReturnURL(obj)
{
	document.forms[1].elements["returnURL"].value = window.location.href; 
	// alert("HERE: " + document.forms[1].elements["returnURL"].value);
}
