//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;};
	});
};	

//-----------------------------------------
//trip and meeting planner dropdown
$.fn.plan_slider=function(){
	return this
	.hoverIntent(
		function () {if ($(this).children('ul').is(":has(li)")) {$(this).children('ul').slideDown(300);}},
		function () {$(this).children('ul').slideUp(300)});
};

//-----------------------------------------
//check-uncheck all 
$.fn.checkall=function(checkbox_container) {
	return this
	.click(function(){
		$checkboxes = $(checkbox_container).find('input[type=checkbox][id!=' + this.id + ']');
		if ($checkboxes.filter(':checked').size() == 0 || $checkboxes.filter(':checked').size() < $checkboxes.size()) {
			$($checkboxes).attr('checked','checked');
			$(this).attr('checked','checked');
		}
		else {
			$($checkboxes).removeAttr('checked');
			$(this).removeAttr('checked');
		}

	});	
};

//-----------------------------------------
//map click checkboxes
$.fn.mapclick=function() {
	return this
	.click(function () {
		var area = $(this).attr('id');
		var description = $(this).attr('title');
		var cbx = '#chk_' + area.substring(4);
		if (!($(cbx).attr('checked'))) {
			$(cbx).attr('checked', 'checked');
			$('p.description').html(description);
			return false;
		}
		else if ($(cbx).attr('checked')) {
			$(cbx).removeAttr('checked');
			$('p.description').html(description);
			return false;
		}
	});
};

//-----------------------------------------
//Star rater
$.fn.stars=function(r_field){
	return this
	.hover(
		function () {$(this).prevAll().andSelf().addClass('hover')},
		function () {$(this).prevAll().andSelf().removeClass('hover')}
	)
	.click(
		function () {
			var rating = $(this).html();
			$(r_field).attr('value',rating);	
			$(this).siblings().removeClass('active');
			$(this).prevAll().andSelf().addClass('active');
		}
	)
};


//-----------------------------------------
//validate category search (if no location checked, check all)
$.fn.validcatsearch=function(checkbox_container){
	return this
	.submit(function(){
		$checkboxes = $(checkbox_container).find('input[type=checkbox]');
		if ($checkboxes.filter(':checked').size() == 0) {
			$($checkboxes).attr('checked','checked');
		}
	});
};	


//-----------------------------------
// 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:150,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);
