/*---------------------------------- Global JavaScript Information -----------------------------------
------------------------------------------------------------------------------------------------------
Version: 0.1.4
Included on the following html pages:
	=All Tillamook Community Pages Except Blog

Contains:
	=jScrollPane - v2.0.0beta11
	=mousewheel v.3.0.6
	=jCal-light v.0.3.4
	=touchSwipe v.1.2.5
	=Swipe Slider Function
	=Equal Height Columns
	=DOM Ready Functions
----------------------------------------------------------------------------------------------------*/


/*
 * jScrollPane - v2.0.0beta11 - 2011-07-04
 * http://jscrollpane.kelvinluck.com/
 *
 * Copyright (c) 2010 Kelvin Luck
 * Dual licensed under the MIT and GPL licenses.
 */
(function(b,a,c){b.fn.jScrollPane=function(e){function d(D,O){var az,Q=this,Y,ak,v,am,T,Z,y,q,aA,aF,av,i,I,h,j,aa,U,aq,X,t,A,ar,af,an,G,l,au,ay,x,aw,aI,f,L,aj=true,P=true,aH=false,k=false,ap=D.clone(false,false).empty(),ac=b.fn.mwheelIntent?"mwheelIntent.jsp":"mousewheel.jsp";aI=D.css("paddingTop")+" "+D.css("paddingRight")+" "+D.css("paddingBottom")+" "+D.css("paddingLeft");f=(parseInt(D.css("paddingLeft"),10)||0)+(parseInt(D.css("paddingRight"),10)||0);function at(aR){var aM,aO,aN,aK,aJ,aQ,aP=false,aL=false;az=aR;if(Y===c){aJ=D.scrollTop();aQ=D.scrollLeft();D.css({overflow:"hidden",padding:0});ak=D.innerWidth()+f;v=D.innerHeight();D.width(ak);Y=b('<div class="jspPane" />').css("padding",aI).append(D.children());am=b('<div class="jspContainer" />').css({width:ak+"px",height:v+"px"}).append(Y).appendTo(D)}else{D.css("width","");aP=az.stickToBottom&&K();aL=az.stickToRight&&B();aK=D.innerWidth()+f!=ak||D.outerHeight()!=v;if(aK){ak=D.innerWidth()+f;v=D.innerHeight();am.css({width:ak+"px",height:v+"px"})}if(!aK&&L==T&&Y.outerHeight()==Z){D.width(ak);return}L=T;Y.css("width","");D.width(ak);am.find(">.jspVerticalBar,>.jspHorizontalBar").remove().end()}Y.css("overflow","auto");if(aR.contentWidth){T=aR.contentWidth}else{T=Y[0].scrollWidth}Z=Y[0].scrollHeight;Y.css("overflow","");y=T/ak;q=Z/v;aA=q>1;aF=y>1;if(!(aF||aA)){D.removeClass("jspScrollable");Y.css({top:0,width:am.width()-f});n();E();R();w();ai()}else{D.addClass("jspScrollable");aM=az.maintainPosition&&(I||aa);if(aM){aO=aD();aN=aB()}aG();z();F();if(aM){N(aL?(T-ak):aO,false);M(aP?(Z-v):aN,false)}J();ag();ao();if(az.enableKeyboardNavigation){S()}if(az.clickOnTrack){p()}C();if(az.hijackInternalLinks){m()}}if(az.autoReinitialise&&!aw){aw=setInterval(function(){at(az)},az.autoReinitialiseDelay)}else{if(!az.autoReinitialise&&aw){clearInterval(aw)}}aJ&&D.scrollTop(0)&&M(aJ,false);aQ&&D.scrollLeft(0)&&N(aQ,false);D.trigger("jsp-initialised",[aF||aA])}function aG(){if(aA){am.append(b('<div class="jspVerticalBar" />').append(b('<div class="jspCap jspCapTop" />'),b('<div class="jspTrack" />').append(b('<div class="jspDrag" />').append(b('<div class="jspDragTop" />'),b('<div class="jspDragBottom" />'))),b('<div class="jspCap jspCapBottom" />')));U=am.find(">.jspVerticalBar");aq=U.find(">.jspTrack");av=aq.find(">.jspDrag");if(az.showArrows){ar=b('<a class="jspArrow jspArrowUp" />').bind("mousedown.jsp",aE(0,-1)).bind("click.jsp",aC);af=b('<a class="jspArrow jspArrowDown" />').bind("mousedown.jsp",aE(0,1)).bind("click.jsp",aC);if(az.arrowScrollOnHover){ar.bind("mouseover.jsp",aE(0,-1,ar));af.bind("mouseover.jsp",aE(0,1,af))}al(aq,az.verticalArrowPositions,ar,af)}t=v;am.find(">.jspVerticalBar>.jspCap:visible,>.jspVerticalBar>.jspArrow").each(function(){t-=b(this).outerHeight()});av.hover(function(){av.addClass("jspHover")},function(){av.removeClass("jspHover")}).bind("mousedown.jsp",function(aJ){b("html").bind("dragstart.jsp selectstart.jsp",aC);av.addClass("jspActive");var s=aJ.pageY-av.position().top;b("html").bind("mousemove.jsp",function(aK){V(aK.pageY-s,false)}).bind("mouseup.jsp mouseleave.jsp",ax);return false});o()}}function o(){aq.height(t+"px");I=0;X=az.verticalGutter+aq.outerWidth();Y.width(ak-X-f);try{if(U.position().left===0){Y.css("margin-left",X+"px")}}catch(s){}}function z(){if(aF){am.append(b('<div class="jspHorizontalBar" />').append(b('<div class="jspCap jspCapLeft" />'),b('<div class="jspTrack" />').append(b('<div class="jspDrag" />').append(b('<div class="jspDragLeft" />'),b('<div class="jspDragRight" />'))),b('<div class="jspCap jspCapRight" />')));an=am.find(">.jspHorizontalBar");G=an.find(">.jspTrack");h=G.find(">.jspDrag");if(az.showArrows){ay=b('<a class="jspArrow jspArrowLeft" />').bind("mousedown.jsp",aE(-1,0)).bind("click.jsp",aC);x=b('<a class="jspArrow jspArrowRight" />').bind("mousedown.jsp",aE(1,0)).bind("click.jsp",aC);
if(az.arrowScrollOnHover){ay.bind("mouseover.jsp",aE(-1,0,ay));x.bind("mouseover.jsp",aE(1,0,x))}al(G,az.horizontalArrowPositions,ay,x)}h.hover(function(){h.addClass("jspHover")},function(){h.removeClass("jspHover")}).bind("mousedown.jsp",function(aJ){b("html").bind("dragstart.jsp selectstart.jsp",aC);h.addClass("jspActive");var s=aJ.pageX-h.position().left;b("html").bind("mousemove.jsp",function(aK){W(aK.pageX-s,false)}).bind("mouseup.jsp mouseleave.jsp",ax);return false});l=am.innerWidth();ah()}}function ah(){am.find(">.jspHorizontalBar>.jspCap:visible,>.jspHorizontalBar>.jspArrow").each(function(){l-=b(this).outerWidth()});G.width(l+"px");aa=0}function F(){if(aF&&aA){var aJ=G.outerHeight(),s=aq.outerWidth();t-=aJ;b(an).find(">.jspCap:visible,>.jspArrow").each(function(){l+=b(this).outerWidth()});l-=s;v-=s;ak-=aJ;G.parent().append(b('<div class="jspCorner" />').css("width",aJ+"px"));o();ah()}if(aF){Y.width((am.outerWidth()-f)+"px")}Z=Y.outerHeight();q=Z/v;if(aF){au=Math.ceil(1/y*l);if(au>az.horizontalDragMaxWidth){au=az.horizontalDragMaxWidth}else{if(au<az.horizontalDragMinWidth){au=az.horizontalDragMinWidth}}h.width(au+"px");j=l-au;ae(aa)}if(aA){A=Math.ceil(1/q*t);if(A>az.verticalDragMaxHeight){A=az.verticalDragMaxHeight}else{if(A<az.verticalDragMinHeight){A=az.verticalDragMinHeight}}av.height(A+"px");i=t-A;ad(I)}}function al(aK,aM,aJ,s){var aO="before",aL="after",aN;if(aM=="os"){aM=/Mac/.test(navigator.platform)?"after":"split"}if(aM==aO){aL=aM}else{if(aM==aL){aO=aM;aN=aJ;aJ=s;s=aN}}aK[aO](aJ)[aL](s)}function aE(aJ,s,aK){return function(){H(aJ,s,this,aK);this.blur();return false}}function H(aM,aL,aP,aO){aP=b(aP).addClass("jspActive");var aN,aK,aJ=true,s=function(){if(aM!==0){Q.scrollByX(aM*az.arrowButtonSpeed)}if(aL!==0){Q.scrollByY(aL*az.arrowButtonSpeed)}aK=setTimeout(s,aJ?az.initialDelay:az.arrowRepeatFreq);aJ=false};s();aN=aO?"mouseout.jsp":"mouseup.jsp";aO=aO||b("html");aO.bind(aN,function(){aP.removeClass("jspActive");aK&&clearTimeout(aK);aK=null;aO.unbind(aN)})}function p(){w();if(aA){aq.bind("mousedown.jsp",function(aO){if(aO.originalTarget===c||aO.originalTarget==aO.currentTarget){var aM=b(this),aP=aM.offset(),aN=aO.pageY-aP.top-I,aK,aJ=true,s=function(){var aS=aM.offset(),aT=aO.pageY-aS.top-A/2,aQ=v*az.scrollPagePercent,aR=i*aQ/(Z-v);if(aN<0){if(I-aR>aT){Q.scrollByY(-aQ)}else{V(aT)}}else{if(aN>0){if(I+aR<aT){Q.scrollByY(aQ)}else{V(aT)}}else{aL();return}}aK=setTimeout(s,aJ?az.initialDelay:az.trackClickRepeatFreq);aJ=false},aL=function(){aK&&clearTimeout(aK);aK=null;b(document).unbind("mouseup.jsp",aL)};s();b(document).bind("mouseup.jsp",aL);return false}})}if(aF){G.bind("mousedown.jsp",function(aO){if(aO.originalTarget===c||aO.originalTarget==aO.currentTarget){var aM=b(this),aP=aM.offset(),aN=aO.pageX-aP.left-aa,aK,aJ=true,s=function(){var aS=aM.offset(),aT=aO.pageX-aS.left-au/2,aQ=ak*az.scrollPagePercent,aR=j*aQ/(T-ak);if(aN<0){if(aa-aR>aT){Q.scrollByX(-aQ)}else{W(aT)}}else{if(aN>0){if(aa+aR<aT){Q.scrollByX(aQ)}else{W(aT)}}else{aL();return}}aK=setTimeout(s,aJ?az.initialDelay:az.trackClickRepeatFreq);aJ=false},aL=function(){aK&&clearTimeout(aK);aK=null;b(document).unbind("mouseup.jsp",aL)};s();b(document).bind("mouseup.jsp",aL);return false}})}}function w(){if(G){G.unbind("mousedown.jsp")}if(aq){aq.unbind("mousedown.jsp")}}function ax(){b("html").unbind("dragstart.jsp selectstart.jsp mousemove.jsp mouseup.jsp mouseleave.jsp");if(av){av.removeClass("jspActive")}if(h){h.removeClass("jspActive")}}function V(s,aJ){if(!aA){return}if(s<0){s=0}else{if(s>i){s=i}}if(aJ===c){aJ=az.animateScroll}if(aJ){Q.animate(av,"top",s,ad)}else{av.css("top",s);ad(s)}}function ad(aJ){if(aJ===c){aJ=av.position().top}am.scrollTop(0);I=aJ;var aM=I===0,aK=I==i,aL=aJ/i,s=-aL*(Z-v);if(aj!=aM||aH!=aK){aj=aM;aH=aK;D.trigger("jsp-arrow-change",[aj,aH,P,k])}u(aM,aK);Y.css("top",s);D.trigger("jsp-scroll-y",[-s,aM,aK]).trigger("scroll")}function W(aJ,s){if(!aF){return}if(aJ<0){aJ=0}else{if(aJ>j){aJ=j}}if(s===c){s=az.animateScroll}if(s){Q.animate(h,"left",aJ,ae)
}else{h.css("left",aJ);ae(aJ)}}function ae(aJ){if(aJ===c){aJ=h.position().left}am.scrollTop(0);aa=aJ;var aM=aa===0,aL=aa==j,aK=aJ/j,s=-aK*(T-ak);if(P!=aM||k!=aL){P=aM;k=aL;D.trigger("jsp-arrow-change",[aj,aH,P,k])}r(aM,aL);Y.css("left",s);D.trigger("jsp-scroll-x",[-s,aM,aL]).trigger("scroll")}function u(aJ,s){if(az.showArrows){ar[aJ?"addClass":"removeClass"]("jspDisabled");af[s?"addClass":"removeClass"]("jspDisabled")}}function r(aJ,s){if(az.showArrows){ay[aJ?"addClass":"removeClass"]("jspDisabled");x[s?"addClass":"removeClass"]("jspDisabled")}}function M(s,aJ){var aK=s/(Z-v);V(aK*i,aJ)}function N(aJ,s){var aK=aJ/(T-ak);W(aK*j,s)}function ab(aW,aR,aK){var aO,aL,aM,s=0,aV=0,aJ,aQ,aP,aT,aS,aU;try{aO=b(aW)}catch(aN){return}aL=aO.outerHeight();aM=aO.outerWidth();am.scrollTop(0);am.scrollLeft(0);while(!aO.is(".jspPane")){s+=aO.position().top;aV+=aO.position().left;aO=aO.offsetParent();if(/^body|html$/i.test(aO[0].nodeName)){return}}aJ=aB();aP=aJ+v;if(s<aJ||aR){aS=s-az.verticalGutter}else{if(s+aL>aP){aS=s-v+aL+az.verticalGutter}}if(aS){M(aS,aK)}aQ=aD();aT=aQ+ak;if(aV<aQ||aR){aU=aV-az.horizontalGutter}else{if(aV+aM>aT){aU=aV-ak+aM+az.horizontalGutter}}if(aU){N(aU,aK)}}function aD(){return -Y.position().left}function aB(){return -Y.position().top}function K(){var s=Z-v;return(s>20)&&(s-aB()<10)}function B(){var s=T-ak;return(s>20)&&(s-aD()<10)}function ag(){am.unbind(ac).bind(ac,function(aM,aN,aL,aJ){var aK=aa,s=I;Q.scrollBy(aL*az.mouseWheelSpeed,-aJ*az.mouseWheelSpeed,false);return aK==aa&&s==I})}function n(){am.unbind(ac)}function aC(){return false}function J(){Y.find(":input,a").unbind("focus.jsp").bind("focus.jsp",function(s){ab(s.target,false)})}function E(){Y.find(":input,a").unbind("focus.jsp")}function S(){var s,aJ,aL=[];aF&&aL.push(an[0]);aA&&aL.push(U[0]);Y.focus(function(){D.focus()});D.attr("tabindex",0).unbind("keydown.jsp keypress.jsp").bind("keydown.jsp",function(aO){if(aO.target!==this&&!(aL.length&&b(aO.target).closest(aL).length)){return}var aN=aa,aM=I;switch(aO.keyCode){case 40:case 38:case 34:case 32:case 33:case 39:case 37:s=aO.keyCode;aK();break;case 35:M(Z-v);s=null;break;case 36:M(0);s=null;break}aJ=aO.keyCode==s&&aN!=aa||aM!=I;return !aJ}).bind("keypress.jsp",function(aM){if(aM.keyCode==s){aK()}return !aJ});if(az.hideFocus){D.css("outline","none");if("hideFocus" in am[0]){D.attr("hideFocus",true)}}else{D.css("outline","");if("hideFocus" in am[0]){D.attr("hideFocus",false)}}function aK(){var aN=aa,aM=I;switch(s){case 40:Q.scrollByY(az.keyboardSpeed,false);break;case 38:Q.scrollByY(-az.keyboardSpeed,false);break;case 34:case 32:Q.scrollByY(v*az.scrollPagePercent,false);break;case 33:Q.scrollByY(-v*az.scrollPagePercent,false);break;case 39:Q.scrollByX(az.keyboardSpeed,false);break;case 37:Q.scrollByX(-az.keyboardSpeed,false);break}aJ=aN!=aa||aM!=I;return aJ}}function R(){D.attr("tabindex","-1").removeAttr("tabindex").unbind("keydown.jsp keypress.jsp")}function C(){if(location.hash&&location.hash.length>1){var aL,aJ,aK=escape(location.hash);try{aL=b(aK)}catch(s){return}if(aL.length&&Y.find(aK)){if(am.scrollTop()===0){aJ=setInterval(function(){if(am.scrollTop()>0){ab(aK,true);b(document).scrollTop(am.position().top);clearInterval(aJ)}},50)}else{ab(aK,true);b(document).scrollTop(am.position().top)}}}}function ai(){b("a.jspHijack").unbind("click.jsp-hijack").removeClass("jspHijack")}function m(){ai();b("a[href^=#]").addClass("jspHijack").bind("click.jsp-hijack",function(){var s=this.href.split("#"),aJ;if(s.length>1){aJ=s[1];if(aJ.length>0&&Y.find("#"+aJ).length>0){ab("#"+aJ,true);return false}}})}function ao(){var aK,aJ,aM,aL,aN,s=false;am.unbind("touchstart.jsp touchmove.jsp touchend.jsp click.jsp-touchclick").bind("touchstart.jsp",function(aO){var aP=aO.originalEvent.touches[0];aK=aD();aJ=aB();aM=aP.pageX;aL=aP.pageY;aN=false;s=true}).bind("touchmove.jsp",function(aR){if(!s){return}var aQ=aR.originalEvent.touches[0],aP=aa,aO=I;Q.scrollTo(aK+aM-aQ.pageX,aJ+aL-aQ.pageY);aN=aN||Math.abs(aM-aQ.pageX)>5||Math.abs(aL-aQ.pageY)>5;
return aP==aa&&aO==I}).bind("touchend.jsp",function(aO){s=false}).bind("click.jsp-touchclick",function(aO){if(aN){aN=false;return false}})}function g(){var s=aB(),aJ=aD();D.removeClass("jspScrollable").unbind(".jsp");D.replaceWith(ap.append(Y.children()));ap.scrollTop(s);ap.scrollLeft(aJ)}b.extend(Q,{reinitialise:function(aJ){aJ=b.extend({},az,aJ);at(aJ)},scrollToElement:function(aK,aJ,s){ab(aK,aJ,s)},scrollTo:function(aK,s,aJ){N(aK,aJ);M(s,aJ)},scrollToX:function(aJ,s){N(aJ,s)},scrollToY:function(s,aJ){M(s,aJ)},scrollToPercentX:function(aJ,s){N(aJ*(T-ak),s)},scrollToPercentY:function(aJ,s){M(aJ*(Z-v),s)},scrollBy:function(aJ,s,aK){Q.scrollByX(aJ,aK);Q.scrollByY(s,aK)},scrollByX:function(s,aK){var aJ=aD()+Math[s<0?"floor":"ceil"](s),aL=aJ/(T-ak);W(aL*j,aK)},scrollByY:function(s,aK){var aJ=aB()+Math[s<0?"floor":"ceil"](s),aL=aJ/(Z-v);V(aL*i,aK)},positionDragX:function(s,aJ){W(s,aJ)},positionDragY:function(aJ,s){V(aJ,s)},animate:function(aJ,aM,s,aL){var aK={};aK[aM]=s;aJ.animate(aK,{duration:az.animateDuration,easing:az.animateEase,queue:false,step:aL})},getContentPositionX:function(){return aD()},getContentPositionY:function(){return aB()},getContentWidth:function(){return T},getContentHeight:function(){return Z},getPercentScrolledX:function(){return aD()/(T-ak)},getPercentScrolledY:function(){return aB()/(Z-v)},getIsScrollableH:function(){return aF},getIsScrollableV:function(){return aA},getContentPane:function(){return Y},scrollToBottom:function(s){V(i,s)},hijackInternalLinks:function(){m()},destroy:function(){g()}});at(O)}e=b.extend({},b.fn.jScrollPane.defaults,e);b.each(["mouseWheelSpeed","arrowButtonSpeed","trackClickSpeed","keyboardSpeed"],function(){e[this]=e[this]||e.speed});return this.each(function(){var f=b(this),g=f.data("jsp");if(g){g.reinitialise(e)}else{g=new d(f,e);f.data("jsp",g)}})};b.fn.jScrollPane.defaults={showArrows:false,maintainPosition:true,stickToBottom:false,stickToRight:false,clickOnTrack:true,autoReinitialise:false,autoReinitialiseDelay:500,verticalDragMinHeight:0,verticalDragMaxHeight:99999,horizontalDragMinWidth:0,horizontalDragMaxWidth:99999,contentWidth:c,animateScroll:false,animateDuration:300,animateEase:"linear",hijackInternalLinks:false,verticalGutter:4,horizontalGutter:4,mouseWheelSpeed:0,arrowButtonSpeed:0,arrowRepeatFreq:50,arrowScrollOnHover:false,trackClickSpeed:0,trackClickRepeatFreq:70,verticalArrowPositions:"split",horizontalArrowPositions:"split",enableKeyboardNavigation:true,hideFocus:false,keyboardSpeed:0,initialDelay:300,speed:30,scrollPagePercent:0.8}})(jQuery,this);



/*! Copyright (c) 2011 Brandon Aaron (http://brandonaaron.net)
 * Licensed under the MIT License (LICENSE.txt).
 *
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 * Thanks to: Seamus Leahy for adding deltaX and deltaY
 *
 * Version: 3.0.6
 * 
 * Requires: 1.2.2+
 */
(function(a){function d(b){var c=b||window.event,d=[].slice.call(arguments,1),e=0,f=!0,g=0,h=0;return b=a.event.fix(c),b.type="mousewheel",c.wheelDelta&&(e=c.wheelDelta/120),c.detail&&(e=-c.detail/3),h=e,c.axis!==undefined&&c.axis===c.HORIZONTAL_AXIS&&(h=0,g=-1*e),c.wheelDeltaY!==undefined&&(h=c.wheelDeltaY/120),c.wheelDeltaX!==undefined&&(g=-1*c.wheelDeltaX/120),d.unshift(b,e,g,h),(a.event.dispatch||a.event.handle).apply(this,d)}var b=["DOMMouseScroll","mousewheel"];if(a.event.fixHooks)for(var c=b.length;c;)a.event.fixHooks[b[--c]]=a.event.mouseHooks;a.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=b.length;a;)this.addEventListener(b[--a],d,!1);else this.onmousewheel=d},teardown:function(){if(this.removeEventListener)for(var a=b.length;a;)this.removeEventListener(b[--a],d,!1);else this.onmousewheel=null}},a.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery);



/*
 * jCal-light calendar multi-day and multi-month datepicker plugin for jQuery
 *	version 0.3.4
 * Author: Jim Palmer
 * Released under MIT license.
 */
(function($){$.fn.jCal=function(opt){$.jCal(this,opt);};$.jCal=function(target,opt){opt=$.extend({day:new Date(),days:1,showMonths:1,dCheck:function(day){return true;},callback:function(day,days){return true;},selectedBG:'rgb(0, 143, 214)',defaultBG:'rgb(255, 255, 255)',dayOffset:0,forceWeek:false,dow:['S','M','T','W','T','F','S'],ml:['January','February','March','April','May','June','July','August','September','October','November','December'],ms:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],_target:target},opt);opt.day=new Date(opt.day.getFullYear(),opt.day.getMonth(),1);if(!$(opt._target).data('days'))$(opt._target).data('days',opt.days);$(target).stop().empty();for(var sm=0;sm<opt.showMonths;sm++)$(target).append('<div class="jCalMo"></div>');opt.cID='c'+$('.jCalMo').length;$('.jCalMo',target).each(function(ind){drawCalControl($(this),$.extend({},opt,{'ind':ind,'day':new Date(new Date(opt.day.getTime()).setMonth(new Date(opt.day.getTime()).getMonth()+ind))}));drawCal($(this),$.extend({},opt,{'ind':ind,'day':new Date(new Date(opt.day.getTime()).setMonth(new Date(opt.day.getTime()).getMonth()+ind))}));});if($(opt._target).data('day')&&$(opt._target).data('days'))reSelectDates(target,$(opt._target).data('day'),$(opt._target).data('days'),opt);};function drawCalControl(target,opt){$(target).append('<div class="jCal">'+((opt.ind==0)?'<div class="left" />':'')+'<div class="month">'+'<span class="monthYear">'+opt.day.getFullYear()+'</span>'+'<span class="monthName">'+opt.ml[opt.day.getMonth()]+'</span>'+'</div>'+((opt.ind==(opt.showMonths-1))?'<div class="right" />':'')+'</div>');$(target).find('.jCal .left').bind('click',$.extend({},opt),function(e){if($('.jCalMask',e.data._target).length>0)return false;var mD={w:0,h:0};$('.jCalMo',e.data._target).each(function(){mD.w+=$(this).width()+parseInt($(this).css('padding-left'))+parseInt($(this).css('padding-right'));var cH=$(this).height()+parseInt($(this).css('padding-top'))+parseInt($(this).css('padding-bottom'));mD.h=((cH>mD.h)?cH:mD.h);});$(e.data._target).prepend('<div class="jCalMo"></div>');e.data.day=new Date($('div[id*='+e.data.cID+'d_]:first',e.data._target).attr('id').replace(e.data.cID+'d_','').replace(/_/g,'/'));e.data.day.setDate(1);e.data.day.setMonth(e.data.day.getMonth()-1);drawCalControl($('.jCalMo:first',e.data._target),e.data);drawCal($('.jCalMo:first',e.data._target),e.data);if(e.data.showMonths>1){$('.right',e.data._target).clone(true).appendTo($('.jCalMo:eq(1) .jCal',e.data._target));$('.left:last, .right:last',e.data._target).remove();}$(e.data._target).append('<div class="jCalSpace" style="width:'+mD.w+'px; height:'+mD.h+'px;"></div>');$('.jCalMo',e.data._target).wrapAll('<div class="jCalMask" style="clip:rect(0px '+mD.w+'px '+mD.h+'px 0px); width:'+(mD.w+(mD.w/e.data.showMonths))+'px; height:'+mD.h+'px;">'+'<div class="jCalMove"></div>'+'</div>');$('.jCalMove',e.data._target).css('margin-left',((mD.w/e.data.showMonths)*-1)+'px').css('opacity',0.5).animate({marginLeft:'0px'},'fast',function(){$(this).children('.jCalMo:not(:last)').appendTo($(e.data._target));$('.jCalSpace, .jCalMask',e.data._target).empty().remove();if($(e.data._target).data('day'))reSelectDates(e.data._target,$(e.data._target).data('day'),$(e.data._target).data('days'),e.data);});});$(target).find('.jCal .right').bind('click',$.extend({},opt),function(e){if($('.jCalMask',e.data._target).length>0)return false;var mD={w:0,h:0};$('.jCalMo',e.data._target).each(function(){mD.w+=$(this).width()+parseInt($(this).css('padding-left'))+parseInt($(this).css('padding-right'));var cH=$(this).height()+parseInt($(this).css('padding-top'))+parseInt($(this).css('padding-bottom'));mD.h=((cH>mD.h)?cH:mD.h);});$(e.data._target).append('<div class="jCalMo"></div>');e.data.day=new Date($('div[id^='+e.data.cID+'d_]:last',e.data._target).attr('id').replace(e.data.cID+'d_','').replace(/_/g,'/'));e.data.day.setDate(1);e.data.day.setMonth(e.data.day.getMonth()+1);drawCalControl($('.jCalMo:last',e.data._target),e.data);drawCal($('.jCalMo:last',e.data._target),e.data);if(e.data.showMonths>1){$('.left',e.data._target).clone(true).prependTo($('.jCalMo:eq(1) .jCal',e.data._target));$('.left:first, .right:first',e.data._target).remove();}$(e.data._target).append('<div class="jCalSpace" style="width:'+mD.w+'px; height:'+mD.h+'px;"></div>');$('.jCalMo',e.data._target).wrapAll('<div class="jCalMask" style="clip:rect(0px '+mD.w+'px '+mD.h+'px 0px); width:'+(mD.w+(mD.w/e.data.showMonths))+'px; height:'+mD.h+'px;">'+'<div class="jCalMove"></div>'+'</div>');$('.jCalMove',e.data._target).css('opacity',0.5).animate({marginLeft:((mD.w/e.data.showMonths)*-1)+'px'},'fast',function(){$(this).children('.jCalMo:not(:first)').appendTo($(e.data._target));$('.jCalSpace, .jCalMask',e.data._target).empty().remove();if($(e.data._target).data('day'))reSelectDates(e.data._target,$(e.data._target).data('day'),$(e.data._target).data('days'),e.data);$(this).children('.jCalMo:not(:first)').removeClass('');});});$('.jCal',target).each(function(){var width=$(this).parent().width()-($('.left',this).width()||0)-($('.right',this).width()||0);$('.month',this).css('width',width).find('.monthName, .monthYear').css('width',((width/2)-4));});$(window).load(function(){$('.jCal',target).each(function(){var width=$(this).parent().width()-($('.left',this).width()||0)-($('.right',this).width()||0);$('.month',this).css('width',width).find('.monthName, .monthYear').css('width',((width/2)-4));});});};function reSelectDates(target,day,days,opt){var fDay=new Date(day.getTime());var sDay=new Date(day.getTime());for(var fC=false,di=0,dC=days;di<dC;di++){var dF=$(target).find('div[id*=d_'+(sDay.getMonth()+1)+'_'+sDay.getDate()+'_'+sDay.getFullYear()+']');if(dF.length>0){dF.stop().addClass('selectedDay');fC=true;}sDay.setDate(sDay.getDate()+1);}if(fC&&typeof opt.callback=='function')opt.callback(day,days);};function drawCal(target,opt){for(var ds=0,length=opt.dow.length;ds<length;ds++)$(target).append('<div class="dow">'+opt.dow[ds]+'</div>');var fd=new Date(new Date(opt.day.getTime()).setDate(1));var ldlm=new Date(new Date(fd.getTime()).setDate(0));var ld=new Date(new Date(new Date(fd.getTime()).setMonth(fd.getMonth()+1)).setDate(0));var copt={fd:fd.getDay(),lld:ldlm.getDate(),ld:ld.getDate()};var offsetDayStart=((copt.fd<opt.dayOffset)?(opt.dayOffset-7):1);var offsetDayEnd=((ld.getDay()<opt.dayOffset)?(7-ld.getDay()):ld.getDay());for(var d=offsetDayStart,dE=(copt.fd+copt.ld+(7-offsetDayEnd));d<dE;d++)$(target).append(((d<=(copt.fd-opt.dayOffset))?'<div id="'+opt.cID+'d'+d+'" class="pday">'+(copt.lld-((copt.fd-opt.dayOffset)-d))+'</div>':((d>((copt.fd-opt.dayOffset)+copt.ld))?'<div id="'+opt.cID+'d'+d+'" class="aday">'+(d-((copt.fd-opt.dayOffset)+copt.ld))+'</div>':'<div id="'+opt.cID+'d_'+(fd.getMonth()+1)+'_'+(d-(copt.fd-opt.dayOffset))+'_'+fd.getFullYear()+'" class="'+((opt.dCheck(new Date((new Date(fd.getTime())).setDate(d-(copt.fd-opt.dayOffset)))))?'day':'invday')+'">'+(d-(copt.fd-opt.dayOffset))+'</div>')));$(target).find('div[id^='+opt.cID+'d]:first, div[id^='+opt.cID+'d]:nth-child(7n+2)').before('<br style="clear:both; font-size:0.1em;" />');$(target).find('div[id^='+opt.cID+'d_]:not(.invday)').bind("mouseover mouseout click",$.extend({},opt),function(e){if($('.jCalMask',e.data._target).length>0)return false;var osDate=new Date($(this).attr('id').replace(/c[0-9]{1,}d_([0-9]{1,2})_([0-9]{1,2})_([0-9]{4})/,'$1/$2/$3'));if(e.data.forceWeek)osDate.setDate(osDate.getDate()+(e.data.dayOffset-osDate.getDay()));var sDate=new Date(osDate.getTime());if(e.type=='click')$('div[id*=d_]',e.data._target).stop().removeClass('selectedDay').removeClass('overDay').css('backgroundColor','');for(var di=0,ds=$(e.data._target).data('days');di<ds;di++){var currDay=$(e.data._target).find('#'+e.data.cID+'d_'+(sDate.getMonth()+1)+'_'+sDate.getDate()+'_'+sDate.getFullYear());if(currDay.length==0||$(currDay).hasClass('invday'))break;if(e.type=='mouseover')$(currDay).addClass('overDay');else if(e.type=='mouseout')$(currDay).stop().removeClass('overDay').css('backgroundColor','');else if(e.type=='click')$(currDay).stop().addClass('selectedDay');sDate.setDate(sDate.getDate()+1);}if(e.type=='click'){e.data.day=osDate;e.data.callback(osDate,di);$(e.data._target).data('day',e.data.day).data('days',di);}});};})(jQuery);



/* touchSwipe - jQuery Plugin
 * http://plugins.jquery.com/project/touchSwipe
 * http://labs.skinkers.com/touchSwipe/
 *
 * Copyright (c) 2010 Matt Bryson (www.skinkers.com)
 * Licensed under the GNU GPL license
 *
 * $version: 1.2.5 
 *
 * This jQuery plugin will only run on devices running Mobile Webkit based browsers (iOS 2.0+, android 2.2+)
 */
(function(a){a.fn.swipe=function(b){if(!this)return false;var c={fingers:1,threshold:75,swipe:null,swipeLeft:null,swipeRight:null,swipeUp:null,swipeDown:null,swipeStatus:null,click:null,triggerOnTouchEnd:true,allowPageScroll:"auto"};var d="left";var e="right";var f="up";var g="down";var h="none";var i="horizontal";var j="vertical";var k="auto";var l="start";var m="move";var n="end";var o="cancel";var p="ontouchstart"in window,q=p?"touchstart":"mousedown",r=p?"touchmove":"mousemove",s=p?"touchend":"mouseup",t="touchcancel";var u="start";if(b.allowPageScroll==undefined&&(b.swipe!=undefined||b.swipeStatus!=undefined))b.allowPageScroll=h;if(b)a.extend(c,b);return this.each(function(){function J(){var a=I();if(a<=45&&a>=0)return d;else if(a<=360&&a>=315)return d;else if(a>=135&&a<=225)return e;else if(a>45&&a<135)return g;else return f}function I(){var a=y.x-z.x;var b=z.y-y.y;var c=Math.atan2(b,a);var d=Math.round(c*180/Math.PI);if(d<0)d=360-Math.abs(d);return d}function H(){return Math.round(Math.sqrt(Math.pow(z.x-y.x,2)+Math.pow(z.y-y.y,2)))}function G(a,b){if(c.allowPageScroll==h){a.preventDefault()}else{var l=c.allowPageScroll==k;switch(b){case d:if(c.swipeLeft&&l||!l&&c.allowPageScroll!=i)a.preventDefault();break;case e:if(c.swipeRight&&l||!l&&c.allowPageScroll!=i)a.preventDefault();break;case f:if(c.swipeUp&&l||!l&&c.allowPageScroll!=j)a.preventDefault();break;case g:if(c.swipeDown&&l||!l&&c.allowPageScroll!=j)a.preventDefault();break}}}function F(a,b){if(c.swipeStatus)c.swipeStatus.call(v,a,b,direction||null,distance||0);if(b==o){if(c.click&&(x==1||!p)&&(isNaN(distance)||distance==0))c.click.call(v,a,a.target)}if(b==n){if(c.swipe){c.swipe.call(v,a,direction,distance)}switch(direction){case d:if(c.swipeLeft)c.swipeLeft.call(v,a,direction,distance);break;case e:if(c.swipeRight)c.swipeRight.call(v,a,direction,distance);break;case f:if(c.swipeUp)c.swipeUp.call(v,a,direction,distance);break;case g:if(c.swipeDown)c.swipeDown.call(v,a,direction,distance);break}}}function E(a){x=0;y.x=0;y.y=0;z.x=0;z.y=0;A.x=0;A.y=0}function D(a){a.preventDefault();distance=H();direction=J();if(c.triggerOnTouchEnd){u=n;if((x==c.fingers||!p)&&z.x!=0){if(distance>=c.threshold){F(a,u);E(a)}else{u=o;F(a,u);E(a)}}else{u=o;F(a,u);E(a)}}else if(u==m){u=o;F(a,u);E(a)}b.removeEventListener(r,C,false);b.removeEventListener(s,D,false)}function C(a){if(u==n||u==o)return;var b=p?a.touches[0]:a;z.x=b.pageX;z.y=b.pageY;direction=J();if(p){x=a.touches.length}u=m;G(a,direction);if(x==c.fingers||!p){distance=H();if(c.swipeStatus)F(a,u,direction,distance);if(!c.triggerOnTouchEnd){if(distance>=c.threshold){u=n;F(a,u);E(a)}}}else{u=o;F(a,u);E(a)}}function B(a){var d=p?a.touches[0]:a;u=l;if(p){x=a.touches.length}distance=0;direction=null;if(x==c.fingers||!p){y.x=z.x=d.pageX;y.y=z.y=d.pageY;if(c.swipeStatus)F(a,u)}else{E(a)}b.addEventListener(r,C,false);b.addEventListener(s,D,false)}var b=this;var v=a(this);var w=null;var x=0;var y={x:0,y:0};var z={x:0,y:0};var A={x:0,y:0};try{this.addEventListener(q,B,false);this.addEventListener(t,E)}catch(K){}})}})(jQuery);



// Swipe Slider Function
$.fn.slider = function(slideElement,speed) {
	return this.each(function(){
		var item = $(this).children('.sliderWrap').find(slideElement),	
			itemW = item.width(),
			currItem= 0,
			maxItems= item.length,
			sliderW = maxItems*itemW,
			setSpeed= speed,
			rotateSpeed= 6000,
			swipeOptions={
			triggerOnTouchEnd: true,	
			swipeStatus: swipeStatus,
			allowPageScroll: 'vertical',
			threshold: 100
		}
		item.swipe( swipeOptions );

		// Set Total Width of Container
		$(this).children('.sliderWrap').css('width',sliderW);

		// Build Dot Nav
		if ( maxItems > 1 && !$(this).children('.sliderNav').length ) {
			$(this).append('<ul class="sliderNav"/>');
			for(var i = 1; i <= maxItems; i++) {
				$(this).children('.sliderNav').append('<li><a href="#"/></li>').find('li:first-child').addClass('active');
			}
		}
		
		// Center Nav in IE7
		if ($.browser.msie && $.browser.version == 7) {
    		var sliderNavW = ($('.sliderNav').closest('.imgSlider').width() - $('.sliderNav').width())/2;   		
    		$('.sliderNav').css('margin-left',sliderNavW);
    	}

		// Define Nav Variables
		var nav = $(this).children('.sliderNav'),
			navItem = $(this).children('.sliderNav').find('li');

		/*	
		Catch each phase of the swipe.
		move : drag the div.
		cancel : animate back to where we were
		end : animate to the next image
		*/			
		function swipeStatus(event, phase, direction, distance){
			if ( $(nav).length ) {
				stopRotate();
			};
			// If we are moving before swipe, and we are going L or R in X mode, or U or D in Y mode then drag.
			if( phase=="move" && (direction=="left" || direction=="right") ){
				var duration=0;
				
				if (direction == "left")
					scrollItems((itemW * currItem) + distance, duration);
				
				else if (direction == "right")
					scrollItems((itemW * currItem) - distance, duration);
					
			} else if ( phase == "cancel") {
				scrollItems(itemW * currItem, speed);
			} else if ( phase =="end" ) {
				if (direction == "right")
					prevItem()
				else if (direction == "left")			
					nextItem()
			}
		}
		
		// Go to Previous Item
		function prevItem(){
			currItem = Math.max(currItem-1, 0);
			scrollItems( itemW * currItem, setSpeed);
			// Toggle Active Nav Item
			if ( $(nav).length ) {
				$(navItem).removeClass('active').eq(currItem).addClass('active');
			}
		}

		// Go to Next Item
		function nextItem(){
			currItem = Math.min(currItem+1, maxItems-1);
			scrollItems( itemW * currItem, setSpeed);
			// Toggle Active Nav Item
			if ( $(nav).length ) {
				$(navItem).removeClass('active').eq(currItem).addClass('active');
			}
		}
			
		// Scroll Items on Drag
		function scrollItems(distance, duration){
			//inverse the number we set in the css
			var value = (distance<0 ? "" : "-") + Math.abs(distance).toString();
			if ($.browser.webkit) {
				item.css("-webkit-transition-duration", (duration/1000).toFixed(1) + "s");
				item.css("-webkit-transform", "translate3d("+value +"px,0px,0px)");
			} else if ($.browser.mozilla) {			
				item.css("-moz-transition-duration", (duration/1000).toFixed(1) + "s");
				item.css("-moz-transform", "translate("+value +"px,0px)");
			} else {
				item.animate({'left' : value});
			}
		}

		if ( $(nav).length ) {
			// Auto-Rotation
			function startRotate(){
				var navItemActive = $('.sliderNav li.active');
				if ( navItemActive.is(':last-child') ) {
					currItem = 0;
					scrollItems( itemW * 0, setSpeed);
					$(navItem).removeClass('active').eq(currItem).addClass('active');
				} else {
					nextItem();
				}
			}
			var autoRotate = setInterval(startRotate, rotateSpeed);
			function stopRotate(){
				clearInterval(autoRotate);
			}
			
			// Scroll Items on Click
			$(navItem).click(function(){
				stopRotate();
				$(this).siblings('li').removeClass('active');	
				$(this).addClass('active');
				// Match Current Item with Nav Item
				var navIndex = $(this).index();	
				currItem = navIndex;
				
				// Scroll Items
				scrollItems( itemW * currItem, setSpeed);
				
				// Prevent Default Link Action
				return false;
			});
		}

		// Hero Image Slider Dot Navigation
		$('#navBuses').delegate('a','click', function() {
			stopRotate();
			var pos = $(this).position().top;
			$('#navBuses a').removeClass('active');
			$(this).addClass('active');
			$('.border').animate({top:pos}, 350, function(){ });
			
			var idx = $('#navBuses a').index(this);
			$('.imgSlider').hide();
	
			if ( !$('.imgSlider').eq(idx).hasClass('active') ) {
				$('.imgSlider').eq(idx).show().slider('img',350).hide().addClass('active');
			}
			$('.imgSlider').eq(idx).fadeIn(350, function(){
				$('#specs .active').hide().removeClass('active');
				$('#specs img').eq(idx).show().addClass('active');
			});
			return false;
		});
	});
};



// Equal Height Columns
$.fn.setAllToMaxHeight = function(){
	if ( this.length > 1 ) {
		return this.height( Math.max.apply(this, $.map( this , function(e){ return $(e).height() }) ) );
	}
};



/* =DOM Ready Functions */
$(function(){
	// Welcome Template
	if ( $('.welcome').length ) {
		// Check if Horizontal Scrollbars are Present on Initial Load
		if ($(document).width() > $(window).width() && $(window).width() > 980 ) {
			if ($.browser.msie && $.browser.version < 8) {
				$('html,body').css('overflow-x','hidden');
			} else {
				$('body').css('overflow-x','hidden');
			}
		}
	    
	    // Show/Hide Horizontal Scrollbars on Resize
		$(window).resize(function() {
			if ( $(window).width() < 980 ) { 
				if ($.browser.msie && $.browser.version < 8) {
					$('html,body').css('overflow-x','scroll');
				} else {
					$('body').css('overflow-x','scroll');
				}
			} else {
	
				if ($.browser.msie && $.browser.version < 8) {
					$('html,body').css('overflow-x','hidden');
				} else {
					$('body').css('overflow-x','hidden');
				}
			}
		});

		// Initialize Custom Scrollbar
		$('.scrollPane').jScrollPane();

		// Initialize Equal Height Columns
		$('.mod.w272').setAllToMaxHeight();
	}
	
	// Welcome & Meet Buses Template : Initialize Carousel
	$('#photoStream .carousel').jCarouselLite({
		visible: 4,
	    btnNext: '#photoStream .next',
	    btnPrev: '#photoStream .prev'
	});
	
	// Welcome & Photos Template : Initialize Modal Windows
	initModalWin($('a.openModal'));

	// Schedule Template : Add Top/Bottom Borders to Featured Item
	$('.featured').append('<div class="border top"></div><div class="border btm"></div>');
	
	// Schedule Template : Show/Hide Featured Description
	$('.result').delegate('.toggleDescription','click', function() {
		var startHt = 30,
			curHt = $(this).prev('.description').height();
		if ( curHt == startHt ) {
			autoHt = $(this).prev('.description').css('height', 'auto').height();
		} else {
			autoHt = startHt;
		}
		$(this).prev('.description').height(curHt).animate({height: autoHt}, 500);		
		$(this).text($(this).text() == 'More' ? 'Less' : 'More');
		$(this).toggleClass('up');
		return false;
	});
	
	// Schedule Template : Show/Hide Calendar
	$('.btnCalendar, .jCalClose').click(function(){
		$('#calendar').toggleClass('visible');
		if ( !$(this).hasClass('active') ) {
			$(this).addClass('active');		
			$('#jCal').jCal({
				day:			new Date(),
				days:			7,
				showMonths:		2,
				callback:		function (day, days) {
					var months = {
							 '1': '31',
							 '2': '28',
							 '3': '31',
							 '4': '30',
							 '5': '31',
							 '6': '30',
							 '7': '31',
							 '8': '31',
							 '9': '30',
							'10': '31',
							'11': '30',
							'12': '31'
					}
					
					var month = day.getMonth() + 1;
					var theday = day.getDate() + '';
					var year = day.getFullYear() + '';
					year = year.substring(2);
					var start = month + '/' + theday;
					
					$('#dateInput').val(start + '/' + year);
					
					theday = (parseInt(theday) + days) - 1;
					if (parseInt(theday) + days > parseInt(months[month])) {
						theday = theday % months[month];
						month = month + 1;
						if (month > 12) {
							year = parseInt(year) + 1;
							month = month % 12;
						}
					}
					var end = month + '/' + theday + '/' + year;
					
					$('#searchDate').val(start + ' - ' + end);
//					console.log(day);
					$('#dateSearch').submit();
				}
			});
		}
		return false;
	});
	
	// Meet Buses Template : Initialize Hero Image Slider
	$('.imgSlider:first').slider('img',500).addClass('active');

	// Meet Buses Template : Vertical Align Inline Video Text
	$('.videoInline .valignTxt').each(function(){
		var ht = $(this).height(),
			pHt = $(this).parent().height(),
			setMargin = (pHt - ht)/2;
			$(this).find('h2').css('margin-top',setMargin);
	});
	
	// About Tour Template : Inline Video
	$('.videoInline').delegate('.video, .action','click', function() {
		if ( $(this).hasClass('action') ) {
			var el = $(this).closest('.videoInline').find('.video');
		} else	{
			var el = $(this);
		}
		var url = el.attr('href'),
			w 	= el.find('img').attr('width'),
			ht 	= el.find('img').attr('height');
		el.append('<iframe width="'+w+'" height="'+ht+'" src="'+url+'" frameborder="0" allowfullscreen></iframe>');
		return false;
	});
});
