function scrollableElement(els) {
    for (var i = 0, argLength = arguments.length; i <argLength; i++) {
            var el = arguments[i],
            $scrollElement = $(el);
            if ($scrollElement.scrollTop()> 0) {
                    return el;
            } else {
                    $scrollElement.scrollTop(1);
                    var isScrollable = $scrollElement.scrollTop()> 0;
                    $scrollElement.scrollTop(0);
                    if (isScrollable) {
                            return el;
                    }
            }
    }
    return [];
}

(function(h){function C(d,e,g,f,j){d={duration:f,easing:d.easing};if(typeof j=="function")d.complete=j;e.animate({opacity:g},d)}function U(d,e,g,f,n,b){var p=G(j(g),f,!0)[0],l={},m={};l[f.dimensions[0]]=p;l[f.dimensions[6]]=b?-p:p;m[f.dimensions[6]]=0;e.animate({opacity:"+=0"},n);g.css(l).animate(m,{duration:n,easing:d.easing,complete:function(){h(this).remove()}})}function V(d,e,g,f,n){var b=G(j(e),g,!0)[0],p={},l={};p[g.dimensions[0]]=b;l[g.dimensions[6]]=n?b:-b;e.css(p).animate(l,{duration:f,easing:d.easing,
complete:function(){h(this).remove()}})}function I(d,e){if(e=="show"||e=="hide")var g=e;else d.items.minimum>=e?(w("Not enough items: not scrolling"),g="hide"):g="show";if(d.prev.button)d.prev.button[g]();if(d.next.button)d.next.button[g]();if(d.pagination.container)d.pagination.container[g]()}function E(d,e){if(!d.circular&&!d.infinite){var g=e=="removeClass"||e=="addClass"?e:!1;if(d.next.button){var f=g||e==d.items.visible?"addClass":"removeClass";d.next.button[f]("disabled")}if(d.prev.button)d.prev.button[g||
e==0?"addClass":"removeClass"]("disabled")}}function y(d){if(d=="right")return 39;if(d=="left")return 37;if(d=="up")return 38;if(d=="down")return 40;return-1}function O(d){typeof d=="undefined"&&(d={});return d}function J(d,e,g){typeof e!="boolean"&&(e=!1);typeof g!="boolean"&&(g=!1);d=O(d);if(typeof d=="string")var f=y(d),d=f==-1?h(d):f;if(e){if(typeof d=="boolean"&&(d={keys:d}),typeof d.jquery!="undefined"&&(d={container:d}),typeof d.container=="string")d.container=h(d.container)}else if(g){if(typeof d==
"boolean"&&(d={play:d}),typeof d=="number"&&(d={pauseDuration:d}),typeof d.timer!="object")d.timer={}}else{typeof d.jquery!="undefined"&&(d={button:d});typeof d=="number"&&(d={key:d});if(typeof d.button=="string")d.button=h(d.button);if(typeof d.key=="string")d.key=y(d.key)}return d}function K(d,e,g,f,n,b){typeof d=="string"&&(d=isNaN(d)?h(d):parseInt(d));typeof d=="object"?(typeof d.jquery=="undefined"&&(d=h(d)),d=j(b).index(d),d==-1&&(d=0),typeof g!="boolean"&&(g=!1)):typeof g!="boolean"&&(g=!0);
d=isNaN(d)?0:parseInt(d);e=isNaN(e)?0:parseInt(e);g&&(d+=f);d+=e;if(n>0){for(;d>=n;)d-=n;for(;d<0;)d+=n}return d}function j(d,e){typeof e!="string"&&(e="");return h("> *"+e,d)}function p(d,e,g){var f=typeof g=="boolean"?g:!1;typeof g!="number"&&(g=0);d.each(function(){var d=parseInt(h(this).css(e.dimensions[8]));isNaN(d)&&(d=0);h(this).data("cfs_tempCssMargin",d);h(this).css(e.dimensions[8],f?h(this).data("cfs_tempCssMargin"):g+h(this).data("cfs_origCssMargin"))})}function G(d,e,g){s1=H(d,e,0,g);
s2=t(d,e,3,g);return[s1,s2]}function t(d,e,g,f){typeof f!="boolean"&&(f=!1);if(typeof e[e.dimensions[g]]=="number"&&f)return e[e.dimensions[g]];if(typeof e.items[e.dimensions[g]]=="number")return e.items[e.dimensions[g]];return W(d,e,g+2)}function W(d,e,g){var f=0;d.each(function(){var d=h(this)[e.dimensions[g]](!0);f<d&&(f=d)});return f}function X(d,e,g){var f=d[e.dimensions[g]](),e=e.dimensions[g].toLowerCase().indexOf("width")>-1?["paddingLeft","paddingRight"]:["paddingTop","paddingBottom"];for(a=
0;a<e.length;a++)g=parseInt(d.css(e[a])),isNaN(g)&&(g=0),f-=g;return f}function H(d,e,g,f){typeof f!="boolean"&&(f=!1);if(typeof e[e.dimensions[g]]=="number"&&f)return e[e.dimensions[g]];if(typeof e.items[e.dimensions[g]]=="number")return e.items[e.dimensions[g]]*d.length;return $(d,e,g+2)}function $(d,e,g){var f=0;d.each(function(){f+=h(this)[e.dimensions[g]](!0)});return f}function Y(d,e,g){var f=!1,j=!1;d.each(function(){c=h(this)[e.dimensions[g]]();f===!1?f=c:f!=c&&(j=!0)});return j}function P(d,
e,g){typeof g!="boolean"&&(g=!0);var g=e.usePadding&&g?e.padding:[0,0,0,0],f={};f[e.dimensions[0]]=d[0]+g[1]+g[3];f[e.dimensions[3]]=d[1]+g[0]+g[2];return f}function L(d,e,g){var f=d.parent(),h=j(d),b=h.filter(":eq("+(e.items.visible-1)+")");f.css(P(G(h.filter(":lt("+e.items.visible+")"),e,!0),e,g));e.usePadding&&(b.css(e.dimensions[8],b.data("cfs_origCssMargin")+e.padding[e.dimensions[10]]),d.css(e.dimensions[7],e.padding[e.dimensions[9]]),d.css(e.dimensions[6],e.padding[e.dimensions[12]]));d.css(e.dimensions[0],
H(h,e,0)*2);d.css(e.dimensions[3],t(h,e,3))}function aa(d){if(typeof d=="undefined")return[0,0,0,0];if(typeof d=="number")return[d,d,d,d];else typeof d=="string"&&(d=d.split("px").join("").split(" "));if(typeof d!="object")return[0,0,0,0];for(i in d)d[i]=parseInt(d[i]);switch(d.length){case 0:return[0,0,0,0];case 1:return[d[0],d[0],d[0],d[0]];case 2:return[d[0],d[1],d[0],d[1]];case 3:return[d[0],d[1],d[2],d[1]];default:return[d[0],d[1],d[2],d[3]]}}function Q(d,e){var g=typeof e[e.dimensions[3]]==
"number"?e[e.dimensions[3]]:t(d,e,3);return[(e[e.dimensions[0]]-H(d,e,0))/2,(g-t(d,e,3))/2]}function M(d,e,g){for(var d=j(d),f=0,h=0;g<=d.length-1;g++){f+=d.filter(":eq("+g+")")[e.dimensions[2]](!0);if(f>e.maxDimention)return h;g==d.length-1&&(g=-1);h++}}function w(d){typeof d=="string"&&(d="carouFredSel: "+d);if(window.console&&window.console.log)window.console.log(d);else try{console.log(d)}catch(e){}return!1}if(!h.fn.carouFredSel)h.fn.carouFredSel=function(d){if(this.length==0)return w("No element selected.");
if(this.length>1)return this.each(function(){h(this).carouFredSel(d)});var e=this,g=e[0],f=h(this);e.init=function(d,o){for(var e=["items","scroll","auto","prev","next","pagination"],d=O(d),g=0;g<e.length;g++)d[e[g]]=O(d[e[g]]);if(typeof d.scroll=="number")d.scroll=d.scroll<=50?{items:d.scroll}:{duration:d.scroll};else if(typeof d.scroll=="string")d.scroll={easing:d.scroll};if(typeof d.items=="number")d.items={visible:d.items};else if(typeof d.items=="string")d.items={visible:d.items,width:d.items,
height:d.items};o&&(t=h.extend(!0,{},h.fn.carouFredSel.defaults,d));b=h.extend(!0,{},h.fn.carouFredSel.defaults,d);b.variableVisible=!1;y=b.direction=="up"||b.direction=="left"?"next":"prev";b.dimensions=b.direction=="right"||b.direction=="left"?["width","innerWidth","outerWidth","height","innerHeight","outerHeight","left","top","marginRight",0,1,2,3]:["height","innerHeight","outerHeight","width","innerWidth","outerWidth","top","left","marginBottom",3,2,1,0];g=j(f);e=W(g,b,5,!1);b[b.dimensions[3]]==
"auto"&&(b[b.dimensions[3]]=e,b.items[b.dimensions[3]]=e);b.items[b.dimensions[0]]||(b.items[b.dimensions[0]]=Y(g,b,2)?"variable":g[b.dimensions[2]](!0));b.items[b.dimensions[3]]||(b.items[b.dimensions[3]]=Y(g,b,5)?"variable":g[b.dimensions[5]](!0));b[b.dimensions[3]]||(b[b.dimensions[3]]=b.items[b.dimensions[3]]);if(!b.items.visible)if(b.items[b.dimensions[0]]=="variable")b.items.visible="variable";else if(typeof b[b.dimensions[0]]=="number")b.items.visible=Math.floor(b[b.dimensions[0]]/b.items[b.dimensions[0]]);
else if(g=X(n.parent(),b,1),b.items.visible=Math.floor(g/b.items[b.dimensions[0]]),b[b.dimensions[0]]=b.items.visible*b.items[b.dimensions[0]],typeof b.padding=="undefined")b.padding=0;if(!b[b.dimensions[0]])if(b.items.visible!="variable"&&b.items[b.dimensions[0]]!="variable"){if(b[b.dimensions[0]]=b.items.visible*b.items[b.dimensions[0]],typeof b.padding=="undefined")b.padding=0}else b[b.dimensions[0]]="variable";if(b.items.visible=="variable"){b.variableVisible=!0;b.maxDimention=b[b.dimensions[0]]==
"variable"?X(n.parent(),b,1):b[b.dimensions[0]];if(b.padding===!1||b.padding===0)b[b.dimensions[0]]="variable";b.items.visible=M(f,b,0)}else if(b.padding===!1)b.padding=0;if(typeof b.padding=="undefined")b.padding=b[b.dimensions[0]]=="variable"?0:"auto";b.items.oldVisible=b.items.visible;b.usePadding=!1;if(b.padding=="auto"){b.padding=[0,0,0,0];if(b[b.dimensions[0]]!="variable")b.usePadding="auto",g=Q(j(f,":lt("+b.items.visible+")"),b),b.padding[b.dimensions[10]]=g[0],b.padding[b.dimensions[12]]=
g[0];b[b.dimensions[3]]!="variable"&&(g=(b[b.dimensions[3]]-e)/2,g<0&&(g=0),b.padding[b.dimensions[9]]=g,b.padding[b.dimensions[11]]=g)}else b.padding=aa(b.padding),b.usePadding=b.padding[0]==0&&b.padding[1]==0&&b.padding[2]==0&&b.padding[3]==0?!1:!0;if(typeof b.items.minimum!="number")b.items.minimum=b.variableVisible?1:b.items.visible;if(typeof b.scroll.items!="number")b.scroll.items=b.variableVisible?"variable":b.items.visible;if(typeof b.scroll.duration!="number")b.scroll.duration=500;b.auto=
J(b.auto,!1,!0);b.prev=J(b.prev);b.next=J(b.next);b.pagination=J(b.pagination,!0);b.auto=h.extend(!0,{},b.scroll,b.auto);b.prev=h.extend(!0,{},b.scroll,b.prev);b.next=h.extend(!0,{},b.scroll,b.next);b.pagination=h.extend(!0,{},b.scroll,b.pagination);if(typeof b.pagination.keys!="boolean")b.pagination.keys=!1;if(typeof b.pagination.anchorBuilder!="function")b.pagination.anchorBuilder=h.fn.carouFredSel.pageAnchorBuilder;if(typeof b.auto.play!="boolean")b.auto.play=!0;if(typeof b.auto.nap!="boolean")b.auto.nap=
!0;if(typeof b.auto.delay!="number")b.auto.delay=0;if(typeof b.auto.pauseDuration!="number")b.auto.pauseDuration=b.auto.duration<10?2500:b.auto.duration*5};e.build=function(){(f.css("position")=="absolute"||f.css("position")=="fixed")&&w('Carousels CSS-attribute "position" should be "static" or "relative".');n.css({position:"relative",overflow:"hidden",marginTop:f.css("marginTop"),marginRight:f.css("marginRight"),marginBottom:f.css("marginBottom"),marginLeft:f.css("marginLeft")});f.data("cfs_origCss",
{width:f.css("width"),height:f.css("height"),marginTop:f.css("marginTop"),marginRight:f.css("marginRight"),marginBottom:f.css("marginBottom"),marginLeft:f.css("marginLeft"),"float":f.css("float"),position:f.css("position"),top:f.css("top"),left:f.css("left")}).css({marginTop:0,marginRight:0,marginBottom:0,marginLeft:0,"float":"none",position:"absolute"});b.usePadding&&j(f).each(function(){var f=parseInt(h(this).css(b.dimensions[8]));isNaN(f)&&(f=0);h(this).data("cfs_origCssMargin",f)})};e.bind_events=
function(){e.unbind_events();f.bind("pause",function(f,d){typeof d!="boolean"&&(d=!1);d&&(N=!0);R!=null&&clearTimeout(R);S!=null&&clearInterval(S);T!=null&&clearInterval(T);var e=b.auto.pauseDuration-z,h=100-Math.ceil(e*100/b.auto.pauseDuration);h!=0&&b.auto.onPausePause&&b.auto.onPausePause.call(g,h,e)});f.bind("play",function(d,o,e,h){f.trigger("pause");if(b.auto.play&&(typeof h!="boolean"&&(h=typeof e=="boolean"?e:typeof o=="boolean"?o:!1),typeof e!="number"&&(e=typeof o=="number"?o:0),o!="prev"&&
o!="next"&&(o=y),h&&(N=!1),!N)){var j=b.auto.pauseDuration-z;perc=100-Math.ceil(j*100/b.auto.pauseDuration);R=setTimeout(function(){f.is(":animated")?f.trigger("play",o):(z=0,f.trigger(o,b.auto))},j+e);b.auto.pauseOnHover==="resume"&&(S=setInterval(function(){z+=50},50));b.auto.onPauseEnd&&perc==0&&b.auto.onPauseEnd.call(g,perc,j);b.auto.onPauseStart&&(T=setTimeout(function(){b.auto.onPauseStart.call(g,perc,j)},e))}});f.bind("prev next",function(d){N||f.is(":animated")||f.is(":hidden")?d.stopImmediatePropagation():
b.items.minimum>=l?(w("Not enough items: not scrolling"),d.stopImmediatePropagation()):z=0});b.variableVisible?(f.bind("prev",function(d,o,e){typeof o=="number"&&(e=o);if(typeof o!="object")o=b.prev;typeof e!="number"&&(e=typeof o.items=="number"?o.items:b.items.visible);oI=e;b.items.oldVisible=b.items.visible;d=j(f);b.usePadding&&p(d,b);var e=b.items,g;a:{var h=b,m=oI,n=j(f),s=0,v=h.items.visible-m-1,m=0;for(v<0&&(v=n.length-1);v>=0;v--){s+=n.filter(":eq("+v+")")[h.dimensions[2]](!0);if(s>h.maxDimention){g=
m;break a}if(v==0)v=n.length;m++}}e.visible=g;e=b.items.visible-b.items.oldVisible+oI;if(e<=0)b.items.visible=M(f,b,l-oI),e=oI;b.usePadding&&p(d,b,!0);f.trigger("slidePrev",[o,e])}),f.bind("next",function(d,o,e){typeof o=="number"&&(e=o);if(typeof o!="object")o=b.next;typeof e!="number"&&(e=typeof o.items=="number"?o.items:b.items.visible);b.items.oldVisible=b.items.visible;d=j(f);b.usePadding&&p(d,b);b.items.visible=M(f,b,e);if(b.items.oldVisible-e>=b.items.visible)b.items.visible=M(f,b,++e);b.usePadding&&
p(d,b,!0);f.trigger("slideNext",[o,e])})):(f.bind("prev",function(b,d,e){f.trigger("slidePrev",[d,e])}),f.bind("next",function(b,d,e){f.trigger("slideNext",[d,e])}));f.bind("slidePrev",function(d,e,k){typeof e=="number"&&(k=e);if(typeof e!="object")e=b.prev;typeof k!="number"&&(k=typeof e.items=="number"?e.items:b.items.visible);if(typeof k!="number")return w("Not a valid number: not scrolling");if(!e.conditions||e.conditions.call(g)){b.circular||(d=l-m,d-k<0&&(k=d),m==0&&(k=0));m+=k;m>=l&&(m-=l);
if(!b.circular)if(m==0&&k!=0&&e.onEnd&&e.onEnd.call(g),b.infinite){if(k==0){f.trigger("next",l-b.items.visible);return}}else E(b,m);if(k!=0){j(f,":gt("+(l-k-1)+")").prependTo(f);l<b.items.visible+k&&j(f,":lt("+(b.items.visible+k-l)+")").clone(!0).appendTo(f);var h=j(f,":lt("+(b.items.oldVisible+k)+"):gt("+(k-1)+")"),A=j(f,":lt("+b.items.visible+")"),d=j(f,":eq("+(k-1)+")"),B=h.filter(":last"),t=A.filter(":last");b.usePadding&&(p(B,b),p(A,b));if(b.usePadding=="auto")var s=Q(j(f,":lt("+b.items.visible+
")"),b);var v=H(j(f,":lt("+k+")"),b,0),u=P(G(A,b,!0),b,!b.usePadding);b.usePadding&&(p(B,b,b.padding[b.dimensions[10]]),p(d,b,b.padding[b.dimensions[12]]));b.usePadding=="auto"&&(b.padding[b.dimensions[9]]=s[1],b.padding[b.dimensions[10]]=s[0],b.padding[b.dimensions[11]]=s[1],b.padding[b.dimensions[12]]=s[0]);var s={},y={},z={},r={},q=e.duration;e.fx=="none"?q=0:q=="auto"?q=b.scroll.duration/b.scroll.items*k:q<=0?q=0:q<10&&(q=v/q);var x={duration:q,easing:e.easing};e.onBefore&&e.onBefore.call(g,h,
A,u,q);if(b.usePadding){var F=b.padding[b.dimensions[12]];z[b.dimensions[8]]=d.data("cfs_origCssMargin");y[b.dimensions[8]]=t.data("cfs_origCssMargin")+b.padding[b.dimensions[10]];r[b.dimensions[8]]=B.data("cfs_origCssMargin");d.stop().animate(z,x);t.stop().animate(y,x);B.stop().animate(r,x)}else F=0;s[b.dimensions[6]]=F;(b[b.dimensions[0]]=="variable"||b[b.dimensions[3]]=="variable")&&n.stop().animate(u,x);switch(e.fx){case "crossfade":case "cover":case "uncover":var D=f.clone().appendTo(n)}switch(e.fx){case "uncover":j(D,
":lt("+k+")").remove();case "crossfade":case "cover":j(D,":gt("+(b.items.oldVisible-1)+")").remove()}switch(e.fx){case "fade":C(e,f,0,q);break;case "crossfade":D.css({opacity:0});C(e,D,1,q);C(e,f,1,q,function(){D.remove()});break;case "cover":U(e,f,D,b,q,!0);break;case "uncover":V(e,D,b,q,!0)}switch(e.fx){case "fade":case "crossfade":case "cover":case "uncover":f_dur=q,q=0}var Z=k;f.css(b.dimensions[6],-v);f.animate(s,{duration:q,easing:e.easing,complete:function(){var d=b.items.visible+Z-l;d>0&&
(j(f,":gt("+(l-1)+")").remove(),h=j(f,":gt("+(l-(Z-d)-1)+")").get().concat(j(f,":lt("+d+")").get()));b.usePadding&&(d=j(f,":eq("+(b.items.visible+k-1)+")"),d.css(b.dimensions[8],d.data("cfs_origCssMargin")));d=e.onAfter?function(){e.onAfter.call(g,h,A,u)}:!1;switch(e.fx){case "fade":C(e,f,1,f_dur,d);break;case "uncover":f.animate({opacity:"+=0"},{duration:f_dur,complete:d});break;default:d&&d()}}});f.trigger("updatePageStatus").trigger("play",q)}}});f.bind("slideNext",function(d,e,k){typeof e=="number"&&
(k=e);if(typeof e!="object")e=b.next;typeof k!="number"&&(k=typeof e.items=="number"?e.items:b.items.visible);if(typeof k!="number")return w("Not a valid number: not scrolling");if(!e.conditions||e.conditions.call(g)){b.circular||(m==0?k>l-b.items.visible&&(k=l-b.items.visible):m-k<b.items.visible&&(k=m-b.items.visible));m-=k;m<0&&(m+=l);if(!b.circular)if(m==b.items.visible&&k!=0&&e.onEnd&&e.onEnd.call(g),b.infinite){if(k==0){f.trigger("prev",l-b.items.visible);return}}else E(b,m);if(k!=0){l<b.items.visible+
k&&j(f,":lt("+(b.items.visible+k-l)+")").clone(!0).appendTo(f);var h=j(f,":lt("+b.items.oldVisible+")"),A=j(f,":lt("+(b.items.visible+k)+"):gt("+(k-1)+")"),d=h.filter(":eq("+(k-1)+")"),B=h.filter(":last"),t=A.filter(":last");b.usePadding&&(p(B,b),p(t,b));if(b.usePadding=="auto")var s=Q(j(f,":lt("+(b.items.visible+k)+"):gt("+(k-1)+")"),b);var v=H(j(f,":lt("+k+")"),b,0),u=P(G(A,b,!0),b,!b.usePadding);b.usePadding&&(p(B,b,b.padding[b.dimensions[10]]),p(t,b,b.padding[b.dimensions[10]]));b.usePadding==
"auto"&&(b.padding[b.dimensions[9]]=s[1],b.padding[b.dimensions[10]]=s[0],b.padding[b.dimensions[11]]=s[1],b.padding[b.dimensions[12]]=s[0]);var s={},y={},z={},r=e.duration;e.fx=="none"?r=0:r=="auto"?r=b.scroll.duration/b.scroll.items*k:r<=0?r=0:r<10&&(r=v/r);var q={duration:r,easing:e.easing};e.onBefore&&e.onBefore.call(g,h,A,u,r);b.usePadding&&(y[b.dimensions[8]]=B.data("cfs_origCssMargin"),z[b.dimensions[8]]=d.data("cfs_origCssMargin")+b.padding[b.dimensions[12]],t.css(b.dimensions[8],t.data("cfs_origCssMargin")+
b.padding[b.dimensions[10]]),B.stop().animate(y,q),d.stop().animate(z,q));s[b.dimensions[6]]=-v;(b[b.dimensions[0]]=="variable"||b[b.dimensions[3]]=="variable")&&n.stop().animate(u,q);switch(e.fx){case "crossfade":case "cover":case "uncover":var x=f.clone().appendTo(n)}switch(e.fx){case "crossfade":case "cover":j(x,":lt("+k+")").remove();case "uncover":j(x,":gt("+(b.items.visible-1)+")").remove()}switch(e.fx){case "fade":C(e,f,0,r);break;case "crossfade":x.css({opacity:0});C(e,x,1,r);C(e,f,1,r,function(){x.remove()});
break;case "cover":U(e,f,x,b,r,!1);break;case "uncover":V(e,x,b,r,!1)}switch(e.fx){case "fade":case "crossfade":case "cover":case "uncover":f_dur=r,r=0}var F=k;f.animate(s,{duration:r,easing:e.easing,complete:function(){var d=b.items.visible+F-l;f.css(b.dimensions[6],b.padding[b.dimensions[12]]);d>0&&j(f,":gt("+(l-1)+")").remove();var k=j(f,":lt("+F+")").appendTo(f).filter(":last");d>0&&(A=j(f,":lt("+b.items.visible+")"));b.usePadding&&(l<b.items.visible+F&&(d=j(f,":eq("+(b.items.visible-1)+")"),
d.css(b.dimensions[8],d.data("cfs_origCssMargin")+b.padding[b.dimensions[12]])),k.css(b.dimensions[8],k.data("cfs_origCssMargin")));k=e.onAfter?function(){e.onAfter.call(g,h,A,u)}:!1;switch(e.fx){case "fade":C(e,f,1,f_dur,k);break;case "uncover":f.animate({opacity:"+=0"},{duration:f_dur,complete:k});break;default:k&&k()}}});f.trigger("updatePageStatus").trigger("play",r)}}});f.bind("slideTo",function(d,e,g,h,j){f.is(":animated")||(e=K(e,g,h,m,l,f),e!=0&&(typeof j!="object"&&(j=!1),b.circular?e<l/
2?f.trigger("next",[j,e]):f.trigger("prev",[j,l-e]):m==0||m>e?f.trigger("next",[j,e]):f.trigger("prev",[j,l-e])))});f.bind("insertItem",function(d,e,g,n,p){typeof e=="object"&&typeof e.jquery=="undefined"&&(e=h(e));typeof e=="string"&&(e=h(e));if(typeof e!="object"||typeof e.jquery=="undefined"||e.length==0)return w("Not a valid object.");typeof g=="undefined"||g=="end"?f.append(e):(g=K(g,p,n,m,l,f),d=j(f,":eq("+g+")"),b.usePadding&&e.each(function(){var d=parseInt(h(this).css(b.dimensions[8]));isNaN(d)&&
(d=0);h(this).data("cfs_origCssMargin",d)}),d.length?(g<m&&(m+=e.length),m>=l&&(m-=l),d.before(e)):f.append(e));l=j(f).length;f.trigger("linkAnchors");L(f,b);I(b,l);E(b,m);f.trigger("updatePageStatus",!0)});f.bind("removeItem",function(d,e,g,h){typeof e=="undefined"||e=="end"?j(f,":last").remove():(e=K(e,h,g,m,l,f),d=j(f,":eq("+e+")"),d.length&&(e<m&&(m-=d.length),d.remove()));l=j(f).length;L(f,b);I(b,l);E(b,m);f.trigger("updatePageStatus",!0)});f.bind("linkAnchors",function(b,d,e){typeof d=="undefined"||
d.length==0?d=h("body"):typeof d=="string"&&(d=h(d));if(typeof d!="object")return w("Not a valid object.");if(typeof e!="string"||e.length==0)e="a.caroufredsel";d.find(e).each(function(){var b=this.hash||"";b.length>0&&j(f).index(h(b))!=-1&&h(this).unbind("click").click(function(d){d.preventDefault();f.trigger("slideTo",b)})})});f.bind("currentPosition",function(b,d){var e=m==0?0:l-m;typeof d=="function"&&d.call(g,e)});f.bind("configuration",function(d,h,k,l){if(f.is(":animated"))var m=setInterval(function(){f.trigger("configuration",
[h,k,l]);clearInterval(m)},100);else typeof l!="boolean"&&(l=!0),typeof h=="function"?h.call(g,b):typeof k=="function"?(d=eval("opts."+h),typeof d=="undefined"&&(d=""),k.call(g,d)):typeof h!="undefined"&&typeof k!="undefined"&&(eval("opts_orig."+h+" = b"),l?(p(j(f),b),e.init(t),L(f,b)):eval("opts."+h+" = b"))});f.bind("destroy",function(d,g){g&&f.trigger("slideTo",[0,0,!0,{duration:0}]);b.usePadding&&p(j(f),b);f.trigger("pause").css(f.data("cfs_origCss"));e.unbind_events();e.unbind_buttons();n.replaceWith(f)});
f.bind("updatePageStatus",function(d,e){if(b.pagination.container){if(typeof e=="boolean"&&e){j(b.pagination.container).remove();for(var g=0;g<Math.ceil(l/b.items.visible);g++){var n=j(f,":eq("+K(g*b.items.visible,0,!0,m,l,f)+")");b.pagination.container.append(b.pagination.anchorBuilder(g+1,n))}j(b.pagination.container).unbind("click").each(function(d){h(this).click(function(e){e.preventDefault();f.trigger("slideTo",[d*b.items.visible,0,!0,b.pagination])})})}g=Math.ceil(l/b.items.visible-1);n=m==
0?0:m<l%b.items.visible?0:m==b.items.visible&&!b.circular?g:Math.round((l-m)/b.items.visible);n<0&&(n=0);n>g&&(n=g);j(b.pagination.container).removeClass("selected").filter(":eq("+n+")").addClass("selected")}})};e.unbind_events=function(){f.unbind("pause").unbind("play").unbind("prev").unbind("next").unbind("slidePrev").unbind("slideNext").unbind("slideTo").unbind("insertItem").unbind("removeItem").unbind("linkAnchors").unbind("destroy").unbind("updatePageStatus").unbind("currentPosition").unbind("configuration")};
e.bind_buttons=function(){I(b,"show");E(b,m);b.auto.pauseOnHover&&b.auto.play&&n.hover(function(){f.trigger("pause")},function(){f.trigger("play")});b.prev.button&&(b.prev.button.click(function(b){b.preventDefault();f.trigger("prev")}),b.prev.pauseOnHover&&b.auto.play&&b.prev.button.hover(function(){f.trigger("pause")},function(){f.trigger("play")}));b.next.button&&(b.next.button.click(function(b){b.preventDefault();f.trigger("next")}),b.next.pauseOnHover&&b.auto.play&&b.next.button.hover(function(){f.trigger("pause")},
function(){f.trigger("play")}));h.fn.mousewheel&&(b.prev.mousewheel&&n.mousewheel(function(d,e){e>0&&(d.preventDefault(),num=typeof b.prev.mousewheel=="number"?b.prev.mousewheel:"",f.trigger("prev",num))}),b.next.mousewheel&&n.mousewheel(function(d,e){e<0&&(d.preventDefault(),num=typeof b.next.mousewheel=="number"?b.next.mousewheel:"",f.trigger("next",num))}));b.pagination.container&&(f.trigger("updatePageStatus",!0),b.pagination.pauseOnHover&&b.auto.play&&b.pagination.container.hover(function(){f.trigger("pause")},
function(){f.trigger("play")}));(b.next.key||b.prev.key)&&h(document).keyup(function(d){var e=d.keyCode;e==b.next.key&&(d.preventDefault(),f.trigger("next"));e==b.prev.key&&(d.preventDefault(),f.trigger("prev"))});b.pagination.keys&&h(document).keyup(function(d){var e=d.keyCode;e>=49&&e<58&&(e=(e-49)*b.items.visible,e<=l&&(d.preventDefault(),f.trigger("slideTo",[e,0,!0,b.pagination])))});b.auto.play&&(f.trigger("play",b.auto.delay),h.fn.nap&&b.auto.nap&&f.nap("pause","play"))};e.unbind_buttons=function(){I(b,
"hide");E(b,"removeClass");b.pagination.container&&j(b.pagination.container).remove()};e.configuration=function(b,d){w('The "configuration" public method is deprecated, use the "configuration" custom event.');var e=!1,g=function(b){e=b};b||(b=g);d||(d=g);f.trigger("configuration",[b,d]);return e};e.current_position=function(){w('The "current_position" public method is deprecated, use the "currentPosition" custom event.');var b=!1;f.trigger("currentPosition",function(d){b=d});return b};e.destroy=function(){w('The "destroy" public method is deprecated, use the "destroy" custom event.');
f.trigger("destroy");return e};e.link_anchors=function(b,d){w('The "link_anchors" public method is deprecated, use the "linkAnchors" custom event.');f.trigger("linkAnchors",[b,d]);return e};if(f.parent().is(".caroufredsel_wrapper")){var n=f.parent();f.trigger("destroy")}var n=f.wrap('<div class="caroufredsel_wrapper" />').parent(),b={},t=d,l=j(f).length,m=0,R=null,S=null,T=null,z=0,N=!1,y="next";e.init(t,!0);e.build();e.bind_events();e.bind_buttons();f.trigger("linkAnchors");L(f,b,!1);if(b.items.start!==
0&&b.items.start!==!1){var u=b.items.start;if(u===!0)u=window.location.hash,u.length||(u=0);u==="random"&&(u=Math.floor(Math.random()*l));f.trigger("slideTo",[u,0,!0,{duration:0}])}return this},h.fn.carouFredSel.defaults={infinite:!0,circular:!0,direction:"left",items:{start:0},scroll:{easing:"swing",pauseOnHover:!1,mousewheel:!1}},h.fn.carouFredSel.pageAnchorBuilder=function(d){return'<a href="#"><span>'+d+"</span></a>"},h.fn.caroufredsel=function(d){return this.carouFredSel(d)}})(jQuery);

/* Modernizr 2.0.4 (Custom Build) | MIT & BSD
 * Contains: boxshadow | input | inputtypes | iepp | cssclasses | testprop | testallprops | domprefixes | load
 */
;window.Modernizr=function(a,b,c){function C(){e.input=function(a){for(var b=0,c=a.length;b<c;b++)r[a[b]]=a[b]in l;return r}("autocomplete autofocus list placeholder max min multiple pattern required step".split(" ")),e.inputtypes=function(a){for(var d=0,e,f,h,i=a.length;d<i;d++)l.setAttribute("type",f=a[d]),e=l.type!=="text",e&&(l.value=m,l.style.cssText="position:absolute;visibility:hidden;",/^range$/.test(f)&&l.style.WebkitAppearance!==c?(g.appendChild(l),h=b.defaultView,e=h.getComputedStyle&&h.getComputedStyle(l,null).WebkitAppearance!=="textfield"&&l.offsetHeight!==0,g.removeChild(l)):/^(search|tel)$/.test(f)||(/^(url|email)$/.test(f)?e=l.checkValidity&&l.checkValidity()===!1:/^color$/.test(f)?(g.appendChild(l),g.offsetWidth,e=l.value!=m,g.removeChild(l)):e=l.value!=m)),q[a[d]]=!!e;return q}("search tel url email datetime date month week time datetime-local number range color".split(" "))}function B(a,b){var c=a.charAt(0).toUpperCase()+a.substr(1),d=(a+" "+o.join(c+" ")+c).split(" ");return A(d,b)}function A(a,b){for(var d in a)if(k[a[d]]!==c)return b=="pfx"?a[d]:!0;return!1}function z(a,b){return!!~(""+a).indexOf(b)}function y(a,b){return typeof a===b}function x(a,b){return w(prefixes.join(a+";")+(b||""))}function w(a){k.cssText=a}var d="2.0.4",e={},f=!0,g=b.documentElement,h=b.head||b.getElementsByTagName("head")[0],i="modernizr",j=b.createElement(i),k=j.style,l=b.createElement("input"),m=":)",n=Object.prototype.toString,o="Webkit Moz O ms Khtml".split(" "),p={},q={},r={},s=[],t,u={}.hasOwnProperty,v;!y(u,c)&&!y(u.call,c)?v=function(a,b){return u.call(a,b)}:v=function(a,b){return b in a&&y(a.constructor.prototype[b],c)},p.boxshadow=function(){return B("boxShadow")};for(var D in p)v(p,D)&&(t=D.toLowerCase(),e[t]=p[D](),s.push((e[t]?"":"no-")+t));e.input||C(),w(""),j=l=null,a.attachEvent&&function(){var a=b.createElement("div");a.innerHTML="<elem></elem>";return a.childNodes.length!==1}()&&function(a,b){function s(a){var b=-1;while(++b<g)a.createElement(f[b])}a.iepp=a.iepp||{};var d=a.iepp,e=d.html5elements||"abbr|article|aside|audio|canvas|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",f=e.split("|"),g=f.length,h=new RegExp("(^|\\s)("+e+")","gi"),i=new RegExp("<(/*)("+e+")","gi"),j=/^\s*[\{\}]\s*$/,k=new RegExp("(^|[^\\n]*?\\s)("+e+")([^\\n]*)({[\\n\\w\\W]*?})","gi"),l=b.createDocumentFragment(),m=b.documentElement,n=m.firstChild,o=b.createElement("body"),p=b.createElement("style"),q=/print|all/,r;d.getCSS=function(a,b){if(a+""===c)return"";var e=-1,f=a.length,g,h=[];while(++e<f){g=a[e];if(g.disabled)continue;b=g.media||b,q.test(b)&&h.push(d.getCSS(g.imports,b),g.cssText),b="all"}return h.join("")},d.parseCSS=function(a){var b=[],c;while((c=k.exec(a))!=null)b.push(((j.exec(c[1])?"\n":c[1])+c[2]+c[3]).replace(h,"$1.iepp_$2")+c[4]);return b.join("\n")},d.writeHTML=function(){var a=-1;r=r||b.body;while(++a<g){var c=b.getElementsByTagName(f[a]),d=c.length,e=-1;while(++e<d)c[e].className.indexOf("iepp_")<0&&(c[e].className+=" iepp_"+f[a])}l.appendChild(r),m.appendChild(o),o.className=r.className,o.id=r.id,o.innerHTML=r.innerHTML.replace(i,"<$1font")},d._beforePrint=function(){p.styleSheet.cssText=d.parseCSS(d.getCSS(b.styleSheets,"all")),d.writeHTML()},d.restoreHTML=function(){o.innerHTML="",m.removeChild(o),m.appendChild(r)},d._afterPrint=function(){d.restoreHTML(),p.styleSheet.cssText=""},s(b),s(l);d.disablePP||(n.insertBefore(p,n.firstChild),p.media="print",p.className="iepp-printshim",a.attachEvent("onbeforeprint",d._beforePrint),a.attachEvent("onafterprint",d._afterPrint))}(a,b),e._version=d,e._domPrefixes=o,e.testProp=function(a){return A([a])},e.testAllProps=B,g.className=g.className.replace(/\bno-js\b/,"")+(f?" js "+s.join(" "):"");return e}(this,this.document),function(a,b,c){function k(a){return!a||a=="loaded"||a=="complete"}function j(){var a=1,b=-1;while(p.length- ++b)if(p[b].s&&!(a=p[b].r))break;a&&g()}function i(a){var c=b.createElement("script"),d;c.src=a.s,c.onreadystatechange=c.onload=function(){!d&&k(c.readyState)&&(d=1,j(),c.onload=c.onreadystatechange=null)},m(function(){d||(d=1,j())},H.errorTimeout),a.e?c.onload():n.parentNode.insertBefore(c,n)}function h(a){var c=b.createElement("link"),d;c.href=a.s,c.rel="stylesheet",c.type="text/css",!a.e&&(w||r)?function a(b){m(function(){if(!d)try{b.sheet.cssRules.length?(d=1,j()):a(b)}catch(c){c.code==1e3||c.message=="security"||c.message=="denied"?(d=1,m(function(){j()},0)):a(b)}},0)}(c):(c.onload=function(){d||(d=1,m(function(){j()},0))},a.e&&c.onload()),m(function(){d||(d=1,j())},H.errorTimeout),!a.e&&n.parentNode.insertBefore(c,n)}function g(){var a=p.shift();q=1,a?a.t?m(function(){a.t=="c"?h(a):i(a)},0):(a(),j()):q=0}function f(a,c,d,e,f,h){function i(){!o&&k(l.readyState)&&(r.r=o=1,!q&&j(),l.onload=l.onreadystatechange=null,m(function(){u.removeChild(l)},0))}var l=b.createElement(a),o=0,r={t:d,s:c,e:h};l.src=l.data=c,!s&&(l.style.display="none"),l.width=l.height="0",a!="object"&&(l.type=d),l.onload=l.onreadystatechange=i,a=="img"?l.onerror=i:a=="script"&&(l.onerror=function(){r.e=r.r=1,g()}),p.splice(e,0,r),u.insertBefore(l,s?null:n),m(function(){o||(u.removeChild(l),r.r=r.e=o=1,j())},H.errorTimeout)}function e(a,b,c){var d=b=="c"?z:y;q=0,b=b||"j",C(a)?f(d,a,b,this.i++,l,c):(p.splice(this.i++,0,a),p.length==1&&g());return this}function d(){var a=H;a.loader={load:e,i:0};return a}var l=b.documentElement,m=a.setTimeout,n=b.getElementsByTagName("script")[0],o={}.toString,p=[],q=0,r="MozAppearance"in l.style,s=r&&!!b.createRange().compareNode,t=r&&!s,u=s?l:n.parentNode,v=a.opera&&o.call(a.opera)=="[object Opera]",w="webkitAppearance"in l.style,x=w&&"async"in b.createElement("script"),y=r?"object":v||x?"img":"script",z=w?"img":y,A=Array.isArray||function(a){return o.call(a)=="[object Array]"},B=function(a){return typeof a=="object"},C=function(a){return typeof a=="string"},D=function(a){return o.call(a)=="[object Function]"},E=[],F={},G,H;H=function(a){function f(a){var b=a.split("!"),c=E.length,d=b.pop(),e=b.length,f={url:d,origUrl:d,prefixes:b},g,h;for(h=0;h<e;h++)g=F[b[h]],g&&(f=g(f));for(h=0;h<c;h++)f=E[h](f);return f}function e(a,b,e,g,h){var i=f(a),j=i.autoCallback;if(!i.bypass){b&&(b=D(b)?b:b[a]||b[g]||b[a.split("/").pop().split("?")[0]]);if(i.instead)return i.instead(a,b,e,g,h);e.load(i.url,i.forceCSS||!i.forceJS&&/css$/.test(i.url)?"c":c,i.noexec),(D(b)||D(j))&&e.load(function(){d(),b&&b(i.origUrl,h,g),j&&j(i.origUrl,h,g)})}}function b(a,b){function c(a){if(C(a))e(a,h,b,0,d);else if(B(a))for(i in a)a.hasOwnProperty(i)&&e(a[i],h,b,i,d)}var d=!!a.test,f=d?a.yep:a.nope,g=a.load||a.both,h=a.callback,i;c(f),c(g),a.complete&&b.load(a.complete)}var g,h,i=this.yepnope.loader;if(C(a))e(a,0,i,0);else if(A(a))for(g=0;g<a.length;g++)h=a[g],C(h)?e(h,0,i,0):A(h)?H(h):B(h)&&b(h,i);else B(a)&&b(a,i)},H.addPrefix=function(a,b){F[a]=b},H.addFilter=function(a){E.push(a)},H.errorTimeout=1e4,b.readyState==null&&b.addEventListener&&(b.readyState="loading",b.addEventListener("DOMContentLoaded",G=function(){b.removeEventListener("DOMContentLoaded",G,0),b.readyState="complete"},0)),a.yepnope=d()}(this,this.document),Modernizr.load=function(){yepnope.apply(window,[].slice.call(arguments,0))};

/* ***********************************************************************************

	CJ Simple Slideshow jQuery Plugin
	Written by: Doug Jones (www.cjboco.com)
	
	Copyright (c) 2011, Creative Juices Bo. Co. All rights reserved.

*********************************************************************************** */
(function($){$.fn.extend({cjSimpleSlideShow:function(i){var j={setSlide:function(a){var b=a.data('cj'),o=b.options,s=b.sys,$show=a.find(".cj_slideshow_slide"),$slide=$show.eq(s.current),$slideNext=$show.eq(s.current+1).length>0?$show.eq(s.current+1):$show.eq(0);if(s.inited&&s.started){$slide.stop().fadeOut(o.dissolve);$slideNext.stop().fadeIn(o.dissolve,function(){s.current=$show.eq(s.current+1).length>0?s.current+1:0;if(!s.paused){s.timer=window.setTimeout(function(){j.setSlide(a)},o.delay)}})}},pause:function(a){var b=a.data('cj'),s=b.sys;if(s.started){if(s.timer){window.clearTimeout(s.timer);s.timer=null}a.find(".cj_slideshow_pause").stop().fadeIn("fast");s.paused=true}},resume:function(a){var b=a.data('cj'),o=b.options,s=b.sys;if(s.started){a.find(".cj_slideshow_pause").stop().fadeOut("fast");s.timer=window.setTimeout(function(){j.setSlide(a)},o.delay);s.paused=false}},start:function(a){var b=a.data('cj'),o=b.options,s=b.sys;if(s.inited){s.timer=window.setTimeout(function(){j.setSlide(a)},o.delay);s.started=true}}};if(typeof i==="string"&&j[i]){var k=$(this),data=k.data('cj'),s=data.sys;if(s.inited){return j[i](k)}}else if(typeof i==="object"||!i){return this.each(function(){var f=$(this),data=f.data('cj'),o,s;if(!data){f.data('cj',{sys:{version:'3.0',timer:null,current:0,paused:false,inited:false,started:false},options:{autoRun:true,delay:5000,dissolve:500,showCaptions:false,centerImage:false,allowPause:false,pauseText:"Paused"}});data=f.data('cj')}if(!data.sys.inited&&!data.sys.started){if(i){data.options=$.extend(data.options,i)}o=data.options;s=data.sys;if(typeof o.dissolve==="number"&&typeof o.delay==="number"&&o.dissolve>o.delay){o.dissolve=o.delay}if(f.find("img").length>1){var g=$("<div>").css({"position":"absolute","display":"block","width":f.width()+"px","height":f.height()+"px","overflow":"hidden","cursor":"pointer"}).addClass("cj_slideshow_wrapper");f.find("img").each(function(a,b){var c=$(b),$slide=$('<div>').css({"position":"absolute","top":"0px","left":"0px","display":a>0?"none":"block","width":f.width()+"px","height":f.height()+"px"}).addClass("cj_slideshow_slide");if(c.parent().get(0).nodeName==="A"){var d=c.parent().attr("href");$slide.bind("click",function(){document.location.href=d;return false})}if(o.allowPause){$slide.bind("mouseenter",function(){j.pause(f)}).bind("mouseleave",function(){j.resume(f)})}if(o.centerImage){c.css({"position":"absolute","top":o.centerImage?parseInt((f.height()-c.height())/2,10)+"px":"0px","left":o.centerImage?parseInt((f.width()-c.width())/2,10)+"px":"0px"})}$slide.append(c);if(o.showCaptions&&c.attr("alt").length>0){var e=$("<span>").css({"position":"absolute","width":"100%","height":"auto","z-index":"5"}).addClass("cj_slideshow_caption").html(c.attr("alt"));$slide.append(e)}g.append($slide)});f.html("").append(g);if(o.allowPause&&o.pauseText.length>0){var h=$("<div>").css({"position":"absolute","top":"5px","left":"5px","display":"none","z-index":"10"}).addClass("cj_slideshow_pause").html(o.pauseText);f.append(h)}s.inited=true}else{s.inited=false}if(s.inited&&o.autoRun){j.start(f)}}})}else{$.error('Method '+i+' does not exist on jQuery.cjSimpleSlideShow')}}})}(jQuery));

/**
 * h5Validate
 * @version v0.6.0
 * Using semantic versioning: http://semver.org/
 * @author Eric Hamilton dilvie@dilvie.com
 * @copyright 2010 - 2011 Eric Hamilton
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Developed under the sponsorship of Root Music, Zumba Fitness, LLC, and Rese Property Management
 */

/*global jQuery window */
/*jslint browser: true, devel: true, onevar: true, undef: true, nomen: true, eqeqeq: true, bitwise: true, regexp: true, newcap: true, immed: true */
(function ($) {
    var h5 = { // Public API
			defaults : {
				debug: false,

				// HTML5-compatible validation pattern library that can be extended and/or overriden.
				patternLibrary : { //** TODO: Test the new regex patterns. Should I apply these to the new input types?
					// **TODO: password
					phone: /([\+][0-9]{1,3}([ \.\-])?)?([\(]{1}[0-9]{3}[\)])?([0-9A-Z \.\-]{1,32})((x|ext|extension)?[0-9]{1,4}?)/,

					// Shamelessly lifted from Scott Gonzalez via the Bassistance Validation plugin http://projects.scottsplayground.com/email_address_validation/
					email: /((([a-zA-Z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-zA-Z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?/,

					// Shamelessly lifted from Scott Gonzalez via the Bassistance Validation plugin http://projects.scottsplayground.com/iri/
					url: /(https?|ftp):\/\/(((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?/,

					// Number, including positive, negative, and floating decimal. Credit: bassistance
					number: /-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?/,

					// Date in ISO format. Credit: bassistance
					dateISO: /\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}/,

					alpha: /[a-zA-Z]+/,
					alphaNumeric: /\w+/,
					integer: /-?\d+/
				},
				messages : {
					required: 'This is a required field.',
					invalid: 'Please correct this field.'
				},

				// The prefix to use for dynamically-created class names.
				classPrefix: 'h5-',

				errorClass: 'ui-state-error', // No prefix for these.
				validClass: 'ui-state-valid', // "
				activeClass: 'active', // Prefix will get prepended.
				requiredClass: 'required',
				requiredAttribute: 'required',
				patternAttribute: 'pattern',

				// Attribute which stores the ID of the error container element (without the hash).
				errorAttribute: 'data-h5-errorid',

				// Setup KB event delegation.
				kbSelectors: ':text, :password, select, textarea',
				focusout: true,
				focusin: false,
				change: true,
				keyup: false,

				// Setup mouse event delegation.
				mSelectors: ':radio, :checkbox, select, option',
				click: true,

				activeKeyup: true,

				// What do we name the required .data variable?
				requiredVar: 'h5-required',
				
				// What do we name the pattern .data variable?
				patternVar: 'h5-pattern',
				stripMarkup: true,

				// Validate on submit?
				// **TODO: This isn't implemented, yet.
				submit: true,
				
				// Callback stubs
				invalidCallback: function () {},
				validCallback: function () {},

				// Mark field invalid.
				// ** TODO: Highlight labels
				// ** TODO: Implement setCustomValidity as per the spec:
				// http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html#dom-cva-setcustomvalidity
				markInvalid: function (options) { 
					var $element = $(options.element),
						$errorID = $(options.errorID);
					$element.addClass(options.errorClass).removeClass(options.validClass);

					// User needs help. Enable active validation.
					$element.addClass(options.settings.activeClass);

					if ($errorID.length) { // These ifs are technically not needed, but improve server-side performance 
						if ($element.attr('title')) {
							$errorID.text($element.attr('title'));
						}
						$errorID.show();
					}
					$element.data('valid', false);
					options.settings.invalidCallback.call(options.element);					
					return $element;
		        },

				// Mark field valid.
				markValid: function (options) {
					var $element = $(options.element),
						$errorID = $(options.errorID);

					$element.addClass(options.validClass).removeClass(options.errorClass);
					if ($errorID.length) {
						$errorID.hide();
					}
					$element.data('valid', true);
					options.settings.validCallback.call(options.element);
					return $element;
				},

				// Unmark field
				unmark: function (options) {
					var $element = $(options.element);
					$element.removeClass(options.errorClass).removeClass(options.validClass);
					$element.form.find("#" + options.element.id).removeClass(options.errorClass).removeClass(options.validClass);
					return $element;
				}	
			}
		},
		// Aliases
		defaults = h5.defaults,
		messages = defaults.messages,
		patternLibrary = defaults.patternLibrary,

		methods = {
			isValid: function (settings) {
				return (!!$(this).data('valid'));
			},
			allValid: function () {
				var valid = true;
				$(this).find('input, textarea, select').each(function() {
					valid = $(this).h5Validate('isValid');
					return valid;
				});
				return valid;
			},
			validate: function (settings) {
				// Get the HTML5 pattern attribute if it exists.
				// ** TODO: If a pattern class exists, grab the pattern from the patternLibrary, but the pattern attrib should override that value.
				var $this = $(this),
					pattern = $this.filter('[pattern]')[0] ? $this.attr('pattern') : false,

				// The pattern attribute must match the whole value, not just a subset:
				// "...as if it implied a ^(?: at the start of the pattern and a )$ at the end."
				re = new RegExp('^(?:' + pattern + ')$'),
				value = ( $this.is('[type=checkbox]') || $this.is('[type=radio]') ) ?
						$this.is(':checked') : $this.val(),
				errorClass = settings.errorClass,
				validClass = settings.validClass,
				errorIDbare = $this.attr(settings.errorAttribute) || false, // Get the ID of the error element.
				errorID = errorIDbare ? '#' + errorIDbare : false, // Add the hash for convenience. This is done in two steps to avoid two attribute lookups.
				required = false,
				isValid = true,
				reason = '',
				$checkRequired = $('<input required>');

				/*	If the required attribute exists, set it required to true, unless it's set 'false'.
				*	This is a minor deviation from the spec, but it seems some browsers have falsey 
				*	required values if the attribute is empty (should be true). The more conformant 
				*	version of this failed sanity checking in the browser environment.
				*	This plugin is meant to be practical, not ideologically married to the spec.
				*/
				// Feature fork
				if ($checkRequired.filter('[required]') && $checkRequired.filter('[required]').length) {
					required = ($this.filter('[required]').length && $this.attr('required') !== 'false') ? true : false;
				} else {
					required = ($this.attr('required') !== undefined) ? true : false;
				}

				if (settings.debug && window.console) {
					console.log('Validate called on "' + value + '" with regex "' + re + '". Required: ' + required); // **DEBUG
					console.log('Regex test: ' + re.test(value) + ', Pattern: ' + pattern); // **DEBUG
				}

				if (required && !value) {
					isValid = false;
					reason = 'required';
				} else if (pattern && !re.test(value) && value) {
					isValid = false;
					reason = 'pattern';
				} else {
					isValid = true;
					settings.markValid({
						element: this,
						errorClass: errorClass,
						validClass: validClass,
						errorID: errorID,
						settings: settings
					});
					
				}

				if (!isValid) {
					settings.markInvalid({
						element: this,
						reason: reason,
						errorClass: errorClass,
						validClass: validClass,
						errorID: errorID,
						settings: settings
					});
				}
			},

			/**
			 * Take the event preferences and delegate the events to selected
			 * objects.
			 * 
			 * @param {object} eventFlags The object containing event flags.
			 * 
			 * @returns {element} The passed element (for method chaining).
			 */
			delegateEvents: function (selectors, eventFlags, element, settings) {
				var events = [],
					key = 0,
					validate = function () {
						settings.validate.call(this, settings);
					};
				$.each(eventFlags, function (key, value) {
					if (value) {
						events[key] = key;
					}
				});
				key=0;
				for (key in events) {
					if (events.hasOwnProperty(key)) {
						$(element).delegate(selectors, events[key] + '.h5Validate', validate);
					}
				}
				return element;
			},
			/**
			 * Prepare for event delegation.
			 * 
			 * @param {object} settings The full plugin state, including
			 * options. 
			 * 
			 * @returns {object} jQuery object for chaining.
			 */
			bindDelegation: function (settings) {
				// Attach patterns from the library to elements.
				$.each(patternLibrary, function (key, value) {
					var pattern = value.toString();
					pattern = pattern.substring(1, pattern.length-1);
					$('.' + settings.classPrefix + key).attr('pattern', pattern);
				});

				$(this).filter('form').attr('novalidate', 'novalidate');
				$(this).find('form').attr('novalidate', 'novalidate');
				$(this).parents('form').attr('novalidate', 'novalidate');

				return this.each(function () {
					var kbEvents = {
							focusout: settings.focusout,
							focusin: settings.focusin,
							change: settings.change,
							keyup: settings.keyup
						},
						mEvents = {
							click: settings.click
						},
						activeEvents = {
							keyup:settings.activeKeyup
						};

					settings.delegateEvents(settings.kbSelectors, kbEvents, this, settings);
					settings.delegateEvents(settings.mSelectors, mEvents, this, settings);
					settings.delegateEvents(settings.activeClassSelector, activeEvents, this, settings);
				});
			}
		};

	$.h5Validate = {
		/**
		 * Take a map of pattern names and HTML5-compatible regular
		 * expressions, and add them to the patternLibrary. Patterns in
		 * the library are automatically assigned to HTML element pattern
		 * attributes for validation.
		 * 
		 * @param {Object} patterns A map of pattern names and HTML5 compatible
		 * regular expressions.
		 * 
		 * @returns {Object} patternLibrary The modified pattern library
		 */
		addPatterns: function (patterns) {
			var patternLibrary = defaults.patternLibrary,
				key;
			for (key in patterns) {
				if (patterns.hasOwnProperty(key)) {
					patternLibrary[key] = patterns[key];
				}
			}
			return patternLibrary;
		},
		/**
		 * Take a valid jQuery selector, and a list of valid values to
		 * validate against.
		 * If the user input isn't in the list, validation fails.
		 * 
		 * @param {String} selector Any valid jQuery selector.
		 *
		 * @param {Array} values A list of valid values to validate selected 
		 * fields against.
		 */
		validValues: function (selector, values) {
			var i = 0,
				ln = values.length,
				pattern = '',
				re;
			// Build regex pattern
			for (i = 0; i < ln; i++) {
				pattern = pattern ? pattern + '|' + values[i] : values[i];
			}
			re = new RegExp('^(?:' + pattern + ')$');
			$(selector).data('regex', re);
		}
	};

	$.fn.h5Validate = function (options) {
		// Combine defaults and options to get current settings.
		var settings = $.extend({}, defaults, options, methods),
			activeClass = settings.classPrefix + settings.activeClass,
			action,
			args;

		$.extend(settings, {
			activeClass: activeClass,
			activeClassSelector: '.' + activeClass,
			requiredClass: settings.classPrefix + settings.requiredClass
		});

		settings.messages = messages;

		// Expose public API.
		$.extend($.fn.h5Validate, h5);

		if (typeof options === 'string' && typeof methods[options] === 'function') {
			args = $.makeArray(arguments);
			action = options;
			args.shift();
			args = $.merge(args, [settings]);
			
			return settings[action].apply(this, args);
		}

		// Returning the jQuery object allows for method chaining.
		return methods.bindDelegation.call(this, settings);
	};
}(jQuery));
