//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;};
	});
};

//-----------------------------------------
//validate event search on submit
$.fn.event_validate=function(textbox){
	return this
	.submit(function(){
		var dvalue = $(textbox).attr("defaultValue");
		var value = $(textbox).attr("value");
		if(value==dvalue){$(textbox).attr("value", "");};
	});
};

//-----------------------------------------
//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');
		}
	});
};	

//-----------------------------------------
//default dates for travelocity search			
function ddlDefaultDates(){
	var doa =  $.datemaker('+6d');
	var amonth = doa.getMonth();
	var aday = doa.getDate();
	var ayear = doa.getFullYear();
	$('#smonth').attr('selectedIndex', amonth);
	$('#sday').attr('selectedIndex', aday);
	$('#syear').attr('value', ayear);
	var dod =  $.datemaker('+7d');
	var dmonth = dod.getMonth();
	var dday = dod.getDate();
	var dyear = dod.getFullYear();
	$('#emonth').attr('selectedIndex', dmonth);
	$('#eday').attr('selectedIndex', dday);
	$('#eyear').attr('value', dyear);
};				

//-----------------------------------------
//set date of an input element - requres datemaker
$.fn.set_date=function(date){
	var d1 = $.datemaker(date); 
	var sDate = d1.getMonth() + 1 + "/" + d1.getDate() + "/" + d1.getFullYear();
	$(this).attr('value', sDate);
};

//-----------------------------------------
//jCarouselLite 1.01 - (c) 2007 Ganeshji Marwaha 
(function($) {                
$.fn.jCarouselLite = function(o) {o = $.extend({btnPrev: null,btnNext: null,btnGo: null,mouseWheel: false,auto: null,speed: 800,easing: 'easeInOutCubic',vertical: false,circular: true,visible: 1,start: 0,scroll: 1,beforeStart: null,afterEnd: null}, o || {});
    return this.each(function() {                          
        var running = false, animCss=o.vertical?"top":"left", sizeCss=o.vertical?"height":"width";
        var div = $(this), ul = $("ul", div), tLi = $("li", ul), tl = tLi.size(), v = o.visible;
        if(o.circular) {
            ul.prepend(tLi.slice(tl-v-1+1).clone())
              .append(tLi.slice(0,v).clone());
            o.start += v;
        }
        var li = $("li", ul), itemLength = li.size(), curr = o.start;
        div.css("visibility", "visible");
        li.css({overflow: "hidden", float: o.vertical ? "none" : "left"});
        ul.css({margin: "0", padding: "0", position: "relative", "list-style-type": "none", "z-index": "1"});
        div.css({overflow: "hidden", position: "relative", "z-index": "2", left: "0px"});
        var liSize = o.vertical ? height(li) : width(li);   
        var ulSize = liSize * itemLength;                   
        var divSize = liSize * v;                          
        li.css({width: li.width(), height: li.height()});
        ul.css(sizeCss, ulSize+"px").css(animCss, -(curr*liSize));
        div.css(sizeCss, divSize+"px"); 
        if(o.btnPrev)
            $(o.btnPrev).click(function() {
                return go(curr-o.scroll);
            });
        if(o.btnNext)
            $(o.btnNext).click(function() {
                return go(curr+o.scroll);
            });
        if(o.btnGo)
            $.each(o.btnGo, function(i, val) {
                $(val).click(function() {
                    return go(o.circular ? o.visible+i : i);
                });
            });
        if(o.mouseWheel && div.mousewheel)
            div.mousewheel(function(e, d) {
                return d>0 ? go(curr-o.scroll) : go(curr+o.scroll);
            });
        if(o.auto)
            setInterval(function() {
                go(curr+o.scroll);
            }, o.auto+o.speed);
        function vis() {return li.slice(curr).slice(0,v);};
        function go(to) {
            if(!running) {
                if(o.beforeStart)
                    o.beforeStart.call(this, vis());
                if(o.circular) {      
                    if(to<=o.start-v-1) {    
                        ul.css(animCss, -((itemLength-(v*2))*liSize)+"px");
                        curr = to==o.start-v-1 ? itemLength-(v*2)-1 : itemLength-(v*2)-o.scroll;
                    } else if(to>=itemLength-v+1) { 
                        ul.css(animCss, -( (v) * liSize ) + "px" );
                        curr = to==itemLength-v+1 ? v+1 : v+o.scroll;
                    } else curr = to;
                } else {             
                    if(to<0 || to>itemLength-v) return;
                    else curr = to;
                }                      
                running = true;
                ul.animate(
                    animCss == "left" ? { left: -(curr*liSize) } : { top: -(curr*liSize) } , o.speed, o.easing,
                    function() {
                        if(o.afterEnd)
                            o.afterEnd.call(this, vis());
                        running = false;
                    }
                );
                if(!o.circular) {
                    $(o.btnPrev + "," + o.btnNext).removeClass("disabled");
                    $( (curr-o.scroll<0 && o.btnPrev)
                        ||
                       (curr+o.scroll > itemLength-v && o.btnNext)
                        ||
                       []
                     ).addClass("disabled");
                }
            }
            return false;
        };
    });
};
function css(el, prop) {return parseInt($.css(el[0], prop)) || 0;};
function width(el) {return  el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');};
function height(el) {return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom');};
})(jQuery);



//JQUERY EASING
// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});



//-----------------------------------------
/* jquery.datemaker.js: Date Maker plugin | Copyright (c) 2008 Doug Sparling | Dual licensed under the MIT and GPL licenses*/
(function($) {$.datemaker = function(expires) {
	var d1 = new Date();
	if ( ar = expires.match(/^([+|-])?(\d+)(\w)$/) ) {
		var action;
		RegExp.$1 == '+' || RegExp.$1 == ''  ? action = '+' : action = '-';
		if (RegExp.$3 == 's') {action  == '-' ? $.datemaker.advanceSeconds(d1, '-', RegExp.$2) : $.datemaker.advanceSeconds(d1, '+', RegExp.$2);} 
		else if (RegExp.$3 == 'm') {action  == '-' ? $.datemaker.advanceMinutes(d1, '-', RegExp.$2) : $.datemaker.advanceMinutes(d1, '+', RegExp.$2);} 
		else if (RegExp.$3 == 'h') {action  == '-' ? $.datemaker.advanceHours(d1, '-', RegExp.$2) : $.datemaker.advanceHours(d1, '+', RegExp.$2);} 
		else if (RegExp.$3 == 'd') {action  == '-' ? $.datemaker.advanceDays(d1, '-', RegExp.$2) : $.datemaker.advanceDays(d1, '+', RegExp.$2);} 
		else if (RegExp.$3 == 'M') {action  == '-' ? $.datemaker.advanceMonths(d1, '-', RegExp.$2) : $.datemaker.advanceMonths(d1, '+', RegExp.$2);} 
		else if (RegExp.$3 == 'y') {action  == '-' ? $.datemaker.advanceYears(d1, '-', RegExp.$2) : $.datemaker.advanceYears(d1, '+', RegExp.$2);}
	} 
	else if ( ar = expires.match(/^(\d+)\.seconds?\.ago$/) ) {$.datemaker.advanceSeconds(d1, '-', RegExp.$1);}
	else if ( ar = expires.match(/^(\d+)\.seconds?\.from_now$/) ) {$.datemaker.advanceSeconds(d1, '+', RegExp.$1);}
	else if ( ar = expires.match(/^(\d+)\.minutes?\.ago$/) ) {$.datemaker.advanceMinutes(d1, '-', RegExp.$1);}
	else if ( ar = expires.match(/^(\d+)\.minutes?\.from_now$/) ) {$.datemaker.advanceMinutes(d1, '+', RegExp.$1);}
	else if ( ar = expires.match(/^(\d+)\.hours?\.ago$/) ) {$.datemaker.advanceHours(d1, '-', RegExp.$1);}
	else if ( ar = expires.match(/^(\d+)\.hours?\.from_now$/) ) {$.datemaker.advanceHours(d1, '+', RegExp.$1);}
	else if ( ar = expires.match(/^(\d+)\.days?\.ago$/) ) {$.datemaker.advanceDays(d1, '-', RegExp.$1);} 
	else if ( ar = expires.match(/^(\d+)\.days?\.from_now$/) ) {$.datemaker.advanceDays(d1, '+', RegExp.$1);}
	else if ( ar = expires.match(/^(\d+)\.years?\.ago$/) ) {$.datemaker.advanceYears(d1, '-', RegExp.$1);} 
	else if ( ar = expires.match(/^(\d+)\.years?\.from_now$/) ) {$.datemaker.advanceYears(d1, '+', RegExp.$1);}
	else if (ar = expires.match(/^now$/)) { }
	else if (ar = expires.match(/^midnight$/)) {d1.setDate(d1.getDate()+1);d1.setHours(0);d1.setMinutes(0);d1.setSeconds(0);}
    return d1;
	};
  $.datemaker.advanceSeconds = function(d1, direction, seconds) {direction == '-' ? d1.setSeconds( d1.getSeconds() - parseInt(seconds) ) : d1.setSeconds( d1.getSeconds() + parseInt(seconds) );};
  $.datemaker.advanceMinutes = function(d1, direction, minutes) {direction == '-' ? d1.setMinutes( d1.getMinutes() - parseInt(minutes) ) : d1.setMinutes( d1.getMinutes() + parseInt(minutes) );};
  $.datemaker.advanceHours = function(d1, direction, hours) {direction == '-' ? d1.setHours( d1.getHours() - parseInt(hours) ) : d1.setHours( d1.getHours() + parseInt(hours) );};
  $.datemaker.advanceDays = function(d1, direction, days) {direction == '-' ? d1.setDate( d1.getDate() - parseInt(days) ) : d1.setDate( d1.getDate() + parseInt(days) );};
  $.datemaker.advanceMonths = function(d1, direction, months) {direction == '-' ? d1.setMonth( d1.getMonth() - parseInt(months) ) : d1.setMonth( d1.getMonth() + parseInt(months) );};
  $.datemaker.advanceYears = function(d1, direction, years) {direction == '-' ? d1.setFullYear( d1.getFullYear() - parseInt(years) ) : d1.setFullYear( d1.getFullYear() + parseInt(years) );};
}) (jQuery);


//-----------------------------------
// 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);

//-----------------------
//jQuery Cookie
jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}expires='; expires='+date.toUTCString();}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}return cookieValue;}};


