// JavaScript Document
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

//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(){return this.submit(function(){if(this.elements['keywords'].value==''||this.elements['keywords'].value==this.elements['keywords'].defaultValue){$("p.tryagain").html("Please enter a keyword before submitting.").fadeIn(300);setTimeout('$("p.tryagain").fadeOut()', 5000);return false}})};
$.fn.validsearch2=function(){return this.submit(function(){if(this.elements['keywords'].value==''||this.elements['keywords'].value==this.elements['keywords'].defaultValue){$("p.tryagain2").html("Please enter a keyword before submitting.").fadeIn(300);setTimeout('$("p.tryagain2").fadeOut()', 5000);return false}})};

//Start Previous and Next Changer and SWF Cat ID changer
function prevNext (divOff,divOn,catID) {
	document.getElementById(divOff).style.display = 'none';
	document.getElementById(divOn).style.display = 'block';
	if (catID != null)
	{
		changeCategorySWF(catID);	
	}
	//$("#divOff").css({"display":"none"});
	//$("#divOn").css({"display":"block"});
}
function thisMovieSWF(movieName)
{
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}
function changeCategorySWF(categoryID)
{
	//$("p#tester").html(categoryID);
	//window.alert("The function has been called. The category being passed is: " + categoryID + ".");
	var swf = thisMovieSWF('subPagePhotoGallerySWF');
	swf.changeCategory(categoryID);
}
//End Previous and Next Changer and SWF Cat ID changer

//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)});
};

// 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);

// check all uncheck all functions
function CheckAll(chk)
{
for (i = 0; i < chk.length; i++)
chk[i].checked = true ;
}

function UnCheckAll(chk)
{
for (i = 0; i < chk.length; i++)
chk[i].checked = false ;
}

//Modified jQuery Easing - (gsgd.co.uk/sandbox/jquery.easing.php) - Copyright (c) 2007 George Smith - Licensed under the MIT License
jQuery.extend(jQuery.easing,{easeinout:function(x,t,b,c,d){if(t<d/2)return 2*c*t*t/(d*d)+b;var ts=t-d/2;return-2*c*ts*ts/(d*d)+2*c*ts/d+c/2+b}});

// jQuery UI Accordion 1.6 -  Copyright (c) 2007 Jörn Zaefferer - http://docs.jquery.com/UI/Accordion -  Dual licensed under the MIT and GPL licenses
(function($){$.ui=$.ui||{};$.fn.extend({accordion:function(options,data){var args=Array.prototype.slice.call(arguments,1);return this.each(function(){if(typeof options=="string"){var accordion=$.data(this,"ui-accordion");accordion[options].apply(accordion,args)}else if(!$(this).is(".ui-accordion"))$.data(this,"ui-accordion",new $.ui.accordion(this,options))})},activate:function(index){return this.accordion("activate",index)}});$.ui.accordion=function(container,options){this.options=options=$.extend({},$.ui.accordion.defaults,options);this.element=container;$(container).addClass("ui-accordion");if(options.navigation){var current=$(container).find("a").filter(options.navigationFilter);if(current.length){if(current.filter(options.header).length){options.active=current}else{options.active=current.parent().parent().prev();current.addClass("current")}}};options.headers=$(container).find(options.header);options.active=findActive(options.headers,options.active);if(options.fillSpace){var maxHeight=$(container).parent().height();options.headers.each(function(){maxHeight-=$(this).outerHeight()});var maxPadding=0;options.headers.next().each(function(){maxPadding=Math.max(maxPadding,$(this).innerHeight()-$(this).height())}).height(maxHeight-maxPadding)}else if(options.autoheight){var maxHeight=0;options.headers.next().each(function(){maxHeight=Math.max(maxHeight,$(this).outerHeight())}).height(maxHeight)};options.headers.not(options.active||"").next().hide();options.active.parent().andSelf().addClass(options.selectedClass);if(options.event)$(container).bind((options.event)+".ui-accordion",clickHandler)};$.ui.accordion.prototype={activate:function(index){clickHandler.call(this.element,{target:findActive(this.options.headers,index)[0]})},enable:function(){this.options.disabled=false},disable:function(){this.options.disabled=true},destroy:function(){this.options.headers.next().css("display","");if(this.options.fillSpace||this.options.autoheight){this.options.headers.next().css("height","")}$.removeData(this.element,"ui-accordion");$(this.element).removeClass("ui-accordion").unbind(".ui-accordion")}};function scopeCallback(callback,scope){return function(){return callback.apply(scope,arguments)}};function completed(cancel){if(!$.data(this,"ui-accordion"))return;var instance=$.data(this,"ui-accordion");var options=instance.options;options.running=cancel?0:--options.running;if(options.running)return;if(options.clearStyle){options.toShow.add(options.toHide).css({height:"",overflow:""})}$(this).triggerHandler("change.ui-accordion",[options.data],options.change)};function toggle(toShow,toHide,data,clickedActive,down){var options=$.data(this,"ui-accordion").options;options.toShow=toShow;options.toHide=toHide;options.data=data;var complete=scopeCallback(completed,this);options.running=toHide.size()==0?toShow.size():toHide.size();if(options.animated){if(!options.alwaysOpen&&clickedActive){$.ui.accordion.animations[options.animated]({toShow:jQuery([]),toHide:toHide,complete:complete,down:down,autoheight:options.autoheight})}else{$.ui.accordion.animations[options.animated]({toShow:toShow,toHide:toHide,complete:complete,down:down,autoheight:options.autoheight})}}else{if(!options.alwaysOpen&&clickedActive){toShow.toggle()}else{toHide.hide();toShow.show()}complete(true)}};function clickHandler(event){var options=$.data(this,"ui-accordion").options;if(options.disabled)return false;if(!event.target&&!options.alwaysOpen){options.active.parent().andSelf().toggleClass(options.selectedClass);var toHide=options.active.next(),data={instance:this,options:options,newHeader:jQuery([]),oldHeader:options.active,newContent:jQuery([]),oldContent:toHide},toShow=options.active=$([]);toggle.call(this,toShow,toHide,data);return false}var clicked=$(event.target);if(clicked.parents(options.header).length)while(!clicked.is(options.header))clicked=clicked.parent();var clickedActive=clicked[0]==options.active[0];if(options.running||(options.alwaysOpen&&clickedActive))return false;if(!clicked.is(options.header))return;options.active.parent().andSelf().toggleClass(options.selectedClass);if(!clickedActive){clicked.parent().andSelf().addClass(options.selectedClass)}var toShow=clicked.next(),toHide=options.active.next(),data={instance:this,options:options,newHeader:clicked,oldHeader:options.active,newContent:toShow,oldContent:toHide},down=options.headers.index(options.active[0])>options.headers.index(clicked[0]);options.active=clickedActive?$([]):clicked;toggle.call(this,toShow,toHide,data,clickedActive,down);return false};function findActive(headers,selector){return selector!=undefined?typeof selector=="number"?headers.filter(":eq("+selector+")"):headers.not(headers.not(selector)):selector===false?$([]):headers.filter(":eq(0)")};$.extend($.ui.accordion,{defaults:{selectedClass:"selected",alwaysOpen:true,animated:'slide',event:"click",header:"a",autoheight:true,running:0,navigationFilter:function(){return this.href.toLowerCase()==location.href.toLowerCase()}},animations:{slide:function(options,additions){options=$.extend({easing:"swing",duration:300},options,additions);if(!options.toHide.size()){options.toShow.animate({height:"show"},options);return}var hideHeight=options.toHide.height(),showHeight=options.toShow.height(),difference=showHeight/hideHeight;options.toShow.css({height:0,overflow:'hidden'}).show();options.toHide.filter(":hidden").each(options.complete).end().filter(":visible").animate({height:"hide"},{step:function(now){var current=(hideHeight-now)*difference;if($.browser.msie||$.browser.opera){current=Math.ceil(current)}options.toShow.height(current)},duration:options.duration,easing:options.easing,complete:function(){if(!options.autoheight){options.toShow.css("height","auto")}options.complete()}})},easeslide:function(options){this.slide(options,{easing:"easeinout",duration:700})}}})})(jQuery);

//cookies - credit: Klaus Hartl (stilbuero.de)...Klaus is representin' DEUTSHLAND!!!
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;}};

//BarkleyREI AJAX Click function 1.0
$.fn.rei_ajax_click=function(templateId, targetId, loadingId){
	return this.click(function(){
		$(loadingId).fadeIn(100);
		var datasource = "/TemplateMarkupCallbackHandler.ashx?templateId=" + templateId + "&amp;",
			datasource = datasource.replace("amp;", ""),
			href = $(this).attr("href").split("?");
			//set cookie, expires in 4:30min
			$.cookie('results_url', datasource + href[1], {expires:.003});
		$.ajax({
			type: "GET",
			url: datasource + href[1],
			dataType: "html",
			success: function(html){
				$(targetId).html(html);
				$(loadingId).hide();
			}
		});
		return false;
	});
};

//BarkleyREI AJAX Submit function 1.0
$.fn.rei_ajax_submit=function(templateId, targetId, loadingId){
	return this.submit(function(){
		$(loadingId).fadeIn(100);
		var datasource = "/TemplateMarkupCallbackHandler.ashx?templateId=" + templateId + "&amp;",
			datasource = datasource.replace("amp;", ""),
			formdata = $(this).serialize();
			//set cookie, expires in 4:30min
			$.cookie('results_url', datasource + formdata, {expires:.003});
		$.ajax({
			type: "GET",
			url: datasource + formdata,
			dataType: "html",
			success: function(html){
				$(targetId).html(html);
				$(loadingId).hide();
			}
		});
		return false;
	});
};

//BarkleyREI AJAX State Restore 1.0
function restore_ajax_state(targetId, loadingId) {
	if ($.cookie('results_url') != null) {
		$(loadingId).fadeIn(100);
		$.ajax({
			type: "GET",
			url: $.cookie('results_url'),
			dataType: "html",
			success: function(html){$(targetId).html(html);$(loadingId).hide();}
		});
	};
};

//REI AJAX Seondary Form Set Cookie
$.fn.rei_ajax_second_form=function(templateId, cookiePath){
	return this.submit(function(){
		var datasource = "/TemplateMarkupCallbackHandler.ashx?templateId=" + templateId + "&amp;",
			datasource = datasource.replace("amp;", ""),
			formdata = $(this).serialize();
		//set cookie, expires in 4:30min
		$.cookie('results_url', datasource + formdata, {path:cookiePath, expires:.003});
		return true;
	});
};

function cookiekiller(deliciousCookies) {
	$.cookie('results_url', '', {path:deliciousCookies, expires: -1}); 
}
