// Supersized 3.2.1
if (!$.browser.msie || ($.browser.msie && parseInt($.browser.version) >= 9))
{
(function(a){a(document).ready(function(){a("body").append('<div id="supersized-loader"></div><div id="supersized"></div>')});a.supersized=function(b){var c="#supersized",d=this;d.$el=a(c);d.el=c;vars=a.supersized.vars;d.$el.data("supersized",d);api=d.$el.data("supersized");d.init=function(){a.supersized.vars.options=a.extend({},a.supersized.defaultOptions,b);d.options=a.supersized.vars.options;d._build()};d._build=function(){d._start()};d._start=function(){if(d.options.start_slide){vars.current_slide=d.options.start_slide-1}else{vars.current_slide=Math.floor(Math.random()*d.options.slides.length)}var f=d.options.new_window?' target="_blank"':"";imageLink=(api.getField("url"))?"href='"+api.getField("url")+"'":"";var e=a('<img src="'+api.getField("image")+'"/>');e.appendTo(d.el).wrap('<a class="image-loading activeslide" '+imageLink+f+"></a>").css("visibility","hidden");e.load(function(){d._origDim(a(this));d.resizeNow();d.launch()});d.$el.css("visibility","hidden")};d.launch=function(){d.$el.css("visibility","visible");a("#supersized-loader").hide();a(window).resize(function(){d.resizeNow()})};d.resizeNow=function(){return d.$el.each(function(){a("img",d.el).each(function(){thisSlide=a(this);var f=(thisSlide.data("origHeight")/thisSlide.data("origWidth")).toFixed(2);var e=d.$el.width(),h=d.$el.height(),i;if(d.options.fit_always){if((h/e)>f){g()}else{j()}}else{if((h<=d.options.min_height)&&(e<=d.options.min_width)){if((h/e)>f){d.options.fit_landscape&&f<1?g(true):j(true)}else{d.options.fit_portrait&&f>=1?j(true):g(true)}}else{if(e<=d.options.min_width){if((h/e)>f){d.options.fit_landscape&&f<1?g(true):j()}else{d.options.fit_portrait&&f>=1?j():g(true)}}else{if(h<=d.options.min_height){if((h/e)>f){d.options.fit_landscape&&f<1?g():j(true)}else{d.options.fit_portrait&&f>=1?j(true):g()}}else{if((h/e)>f){d.options.fit_landscape&&f<1?g():j()}else{d.options.fit_portrait&&f>=1?j():g()}}}}}function g(k){if(k){if(thisSlide.width()<e||thisSlide.width()<d.options.min_width){if(thisSlide.width()*f>=d.options.min_height){thisSlide.width(d.options.min_width);thisSlide.height(thisSlide.width()*f)}else{j()}}}else{if(d.options.min_height>=h&&!d.options.fit_landscape){if(e*f>=d.options.min_height||(e*f>=d.options.min_height&&f<=1)){thisSlide.width(e);thisSlide.height(e*f)}else{if(f>1){thisSlide.height(d.options.min_height);thisSlide.width(thisSlide.height()/f)}else{if(thisSlide.width()<e){thisSlide.width(e);thisSlide.height(thisSlide.width()*f)}}}}else{thisSlide.width(e);thisSlide.height(e*f)}}}function j(k){if(k){if(thisSlide.height()<h){if(thisSlide.height()/f>=d.options.min_width){thisSlide.height(d.options.min_height);thisSlide.width(thisSlide.height()/f)}else{g(true)}}}else{if(d.options.min_width>=e){if(h/f>=d.options.min_width||f>1){thisSlide.height(h);thisSlide.width(h/f)}else{if(f<=1){thisSlide.width(d.options.min_width);thisSlide.height(thisSlide.width()*f)}}}else{thisSlide.height(h);thisSlide.width(h/f)}}}if(thisSlide.parent().hasClass("image-loading")){a(".image-loading").removeClass("image-loading")}if(d.options.horizontal_center){a(this).css("left",(e-a(this).width())/2)}if(d.options.vertical_center){a(this).css("top",(h-a(this).height())/2)}});if(d.options.image_protect){a("img",d.el).bind("contextmenu mousedown",function(){return false})}return false})};d._origDim=function(e){e.data("origWidth",e.width()).data("origHeight",e.height()).css("visibility","visible")};d.getField=function(e){return d.options.slides[vars.current_slide][e]};d.init()};a.supersized.vars={current_slide:0,options:{}};a.supersized.defaultOptions={start_slide:1,new_window:1,image_protect:1,min_width:0,min_height:0,vertical_center:1,horizontal_center:1,fit_always:0,fit_portrait:1,fit_landscape:0};a.fn.supersized=function(b){return this.each(function(){(new a.supersized(b))})}})(jQuery);
}
/**/

// Animage background position
(function($)
{if(!document.defaultView||!document.defaultView.getComputedStyle){var oldCurCSS=$.curCSS;$.curCSS=function(elem,name,force){if(name==='background-position'){name='backgroundPosition';}
if(name!=='backgroundPosition'||!elem.currentStyle||elem.currentStyle[name]){return oldCurCSS.apply(this,arguments);}
var style=elem.style;if(!force&&style&&style[name]){return style[name];}
return oldCurCSS(elem,'backgroundPositionX',force)+' '+oldCurCSS(elem,'backgroundPositionY',force);};}
var oldAnim=$.fn.animate;$.fn.animate=function(prop){if('background-position'in prop){prop.backgroundPosition=prop['background-position'];delete prop['background-position'];}
if('backgroundPosition'in prop){prop.backgroundPosition='('+prop.backgroundPosition;}
return oldAnim.apply(this,arguments);};function toArray(strg){strg=strg.replace(/left|top/g,'0px');strg=strg.replace(/right|bottom/g,'100%');strg=strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");var res=strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);return[parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];}
$.fx.step.backgroundPosition=function(fx){if(!fx.bgPosReady){var start=$.curCSS(fx.elem,'backgroundPosition');if(!start){start='0px 0px';}
start=toArray(start);fx.start=[start[0],start[2]];var end=toArray(fx.end);fx.end=[end[0],end[2]];fx.unit=[end[1],end[3]];fx.bgPosReady=true;}
var nowPosX=[];nowPosX[0]=((fx.end[0]-fx.start[0])*fx.pos)+fx.start[0]+fx.unit[0];nowPosX[1]=((fx.end[1]-fx.start[1])*fx.pos)+fx.start[1]+fx.unit[1];fx.elem.style.backgroundPosition=nowPosX[0]+' '+nowPosX[1];};})(jQuery);
/**/


// Autoscroll
var AUTOSCROLL_BOTH,AUTOSCROLL_X,AUTOSCROLL_Y;AUTOSCROLL_X=1;AUTOSCROLL_Y=2;AUTOSCROLL_BOTH=3;(function($){$.autoscroll={};$.autoscroll.Easemove=function Easemove(){this.current_point=0;this.end_point=0;this.running=false;this.speed=0.07;this.onmove=function onmove(){};return this};$.autoscroll.Easemove.prototype.set_end_point=function set_end_point(point){this.end_point=point;if(this.running){return null}this.running=true;return this.move()};$.autoscroll.Easemove.prototype.move=function move(){var distance,move;distance=this.end_point-this.current_point;move=distance*this.speed;this.current_point+=move;this.onmove(this.current_point);if(Math.round(this.current_point)!==this.end_point){return setTimeout(((function(func,obj,args){return function(){return func.apply(obj,args.concat(Array.prototype.slice.call(arguments,0)))}}(this.move,this,[]))),20)}else{this.running=false;return this.running}};$.autoscroll.zip=function zip(callback){var _a,_b,_c,_d,_e,_f,i,items,line,results,x;items=Array.prototype.slice.call(arguments,1,arguments.length-0);results=[];_b=0;_c=items[0].length;for(_a=0,i=_b;(_b<=_c?i<_c:i>_c);(_b<=_c?i+=1:i-=1),_a++){line=[];_e=0;_f=items.length;for(_d=0,x=_e;(_e<=_f?x<_f:x>_f);(_e<=_f?x+=1:x-=1),_d++){line.push(items[x][i])}results.push(callback.apply(this,line))}return results};$.fn.autoscroll=function autoscroll(mode,degree_window,speed){var directions;mode=mode||AUTOSCROLL_BOTH;degree_window=degree_window||[20,20];speed=speed||0.07;directions=['left','top'];return this.each(function(){var ava_size,container,easemove,inner_container,offset,position,real_size;container=$(this);inner_container=container.children(":first");ava_size=[container.width(),container.height()];position=inner_container.css('position');inner_container.css('position','absolute');real_size=[inner_container.width(),inner_container.height()];inner_container.css('position',position);offset=container.offset();offset=[offset.left,offset.top];easemove=[];jQuery.each(directions,function(i,v){var obj;obj=new jQuery.autoscroll.Easemove();obj.speed=speed;obj.onmove=function onmove(position){return inner_container.css('margin-'+v,-position)};return easemove.push(obj)});return container.mousemove(function(event){var mouse;mouse=[event.pageX,event.pageY];return jQuery.autoscroll.zip((function(m,o,a,r,e,w,t){var d,f,real;if(!(t&mode)){return null}d=m-o;d=Math.min(Math.max(d-w,0),a-w*2);f=d/(a-w*2);real=f*(r-a);return e.set_end_point(real)}),mouse,offset,ava_size,real_size,easemove,degree_window,[AUTOSCROLL_X,AUTOSCROLL_Y])})})};return $.fn.autoscroll})(jQuery);
/**/


// CacheImage
(function($){$.extend($,{cacheImage:function(src,options){if(typeof src==='object'){$.each(src,function(){$.cacheImage(String(this),options);});return;}
var image=new Image();options=options||{};$.each(['load','error','abort'],function(){var e=String(this);if(typeof options[e]==='function'){$(image).bind(e,options[e]);}
if(typeof options.complete==='function'){$(image).bind(e,options.complete);}});image.src=src;return image;}});$.extend($.fn,{cacheImage:function(options){return this.each(function(){$.cacheImage(this.src,options);});}});})(jQuery);
/**/


// DefaultValue
(function($){$.fn.extend({defaultValue:function(callback){var nativePlaceholderSupport=(function(){var i=document.createElement('input');return('placeholder'in i);})();if(nativePlaceholderSupport){return false;}
return this.each(function(index,element){if($(this).data('defaultValued')){return false;}
var $input=$(this),defaultValue=$input.attr('placeholder');var callbackArguments={'input':$input};$input.data('defaultValued',true);var $clone=createClone();callbackArguments.clone=$clone;$clone.insertAfter($input);var setState=function(){if($input.val().length<=0){$clone.show();$input.hide();}else{$clone.hide();$input.show().trigger('click');}};$input.bind('blur',setState);function createClone(){var $el;if($input.context.nodeName.toLowerCase()=='input'){$el=$("<input />").attr({'type':'text'});}else if($input.context.nodeName.toLowerCase()=='textarea'){$el=$("<textarea />");}else{throw'DefaultValue only works with input and textareas';}
$el.attr({'value':defaultValue,'class':$input.attr('class')+' empty','size':$input.attr('size'),'style':$input.attr('style'),'tabindex':$input.attr('tabindex'),'rows':$input.attr('rows'),'cols':$input.attr('cols'),'name':'defaultvalue-clone-'+(((1+Math.random())*0x10000)|0).toString(16).substring(1)});$el.focus(function(){$el.hide();$input.show();setTimeout(function(){$input.focus();},1);});return $el;}
setState();if(callback){callback(callbackArguments);}});}});})(jQuery);
/**/


// ColorBox v1.3.17.2
(function(a,b,c){function bc(b){if(!U){P=b,_(),y=a(P),Q=0,K.rel!=="nofollow"&&(y=a("."+g).filter(function(){var b=a.data(this,e).rel||this.rel;return b===K.rel}),Q=y.index(P),Q===-1&&(y=y.add(P),Q=y.length-1));if(!S){S=T=!0,r.show();if(K.returnFocus)try{P.blur(),a(P).one(l,function(){try{this.focus()}catch(a){}})}catch(c){}q.css({opacity:+K.opacity,cursor:K.overlayClose?"pointer":"auto"}).show(),K.w=Z(K.initialWidth,"x"),K.h=Z(K.initialHeight,"y"),X.position(),o&&z.bind("resize."+p+" scroll."+p,function(){q.css({width:z.width(),height:z.height(),top:z.scrollTop(),left:z.scrollLeft()})}).trigger("resize."+p),ba(h,K.onOpen),J.add(D).hide(),I.html(K.close).show()}X.load(!0)}}function bb(){var a,b=f+"Slideshow_",c="click."+f,d,e,g;K.slideshow&&y[1]?(d=function(){F.text(K.slideshowStop).unbind(c).bind(j,function(){if(Q<y.length-1||K.loop)a=setTimeout(X.next,K.slideshowSpeed)}).bind(i,function(){clearTimeout(a)}).one(c+" "+k,e),r.removeClass(b+"off").addClass(b+"on"),a=setTimeout(X.next,K.slideshowSpeed)},e=function(){clearTimeout(a),F.text(K.slideshowStart).unbind([j,i,k,c].join(" ")).one(c,d),r.removeClass(b+"on").addClass(b+"off")},K.slideshowAuto?d():e()):r.removeClass(b+"off "+b+"on")}function ba(b,c){c&&c.call(P),a.event.trigger(b)}function _(b){K=a.extend({},a.data(P,e));for(b in K)a.isFunction(K[b])&&b.substring(0,2)!=="on"&&(K[b]=K[b].call(P));K.rel=K.rel||P.rel||"nofollow",K.href=K.href||a(P).attr("href"),K.title=K.title||P.title,typeof K.href=="string"&&(K.href=a.trim(K.href))}function $(a){return K.photo||/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i.test(a)}function Z(a,b){return Math.round((/%/.test(a)?(b==="x"?z.width():z.height())/100:1)*parseInt(a,10))}function Y(c,d,e){e=b.createElement("div"),c&&(e.id=f+c),e.style.cssText=d||"";return a(e)}var d={transition:"elastic",speed:300,width:!1,initialWidth:"600",innerWidth:!1,maxWidth:!1,height:!1,initialHeight:"450",innerHeight:!1,maxHeight:!1,scalePhotos:!0,scrolling:!0,inline:!1,html:!1,iframe:!1,fastIframe:!0,photo:!1,href:!1,title:!1,rel:!1,opacity:.9,preloading:!0,current:"image {current} of {total}",previous:"previous",next:"next",close:"close",open:!1,returnFocus:!0,loop:!0,slideshow:!1,slideshowAuto:!0,slideshowSpeed:2500,slideshowStart:"start slideshow",slideshowStop:"stop slideshow",onOpen:!1,onLoad:!1,onComplete:!1,onCleanup:!1,onClosed:!1,overlayClose:!0,escKey:!0,arrowKey:!0,top:!1,bottom:!1,left:!1,right:!1,fixed:!1,data:!1},e="colorbox",f="cbox",g=f+"Element",h=f+"_open",i=f+"_load",j=f+"_complete",k=f+"_cleanup",l=f+"_closed",m=f+"_purge",n=a.browser.msie&&!a.support.opacity,o=n&&a.browser.version<7,p=f+"_IE6",q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X;X=a.fn[e]=a[e]=function(b,c){var f=this;b=b||{};if(!f[0]){if(f.selector)return f;f=a("<a/>"),b.open=!0}c&&(b.onComplete=c),f.each(function(){a.data(this,e,a.extend({},a.data(this,e)||d,b)),a(this).addClass(g)}),(a.isFunction(b.open)&&b.open.call(f)||b.open)&&bc(f[0]);return f},X.init=function(){z=a(c),r=Y().attr({id:e,"class":n?f+(o?"IE6":"IE"):""}),q=Y("Overlay",o?"position:absolute":"").hide(),s=Y("Wrapper"),t=Y("Content").append(A=Y("LoadedContent","width:0; height:0; overflow:hidden"),C=Y("LoadingOverlay").add(Y("LoadingGraphic")),D=Y("Title"),E=Y("Current"),G=Y("Next"),H=Y("Previous"),F=Y("Slideshow").bind(h,bb),I=Y("Close")),s.append(Y().append(Y("TopLeft"),u=Y("TopCenter"),Y("TopRight")),Y(!1,"clear:left").append(v=Y("MiddleLeft"),t,w=Y("MiddleRight")),Y(!1,"clear:left").append(Y("BottomLeft"),x=Y("BottomCenter"),Y("BottomRight"))).children().children().css({"float":"left"}),B=Y(!1,"position:absolute; width:9999px; visibility:hidden; display:none"),a("body").prepend(q,r.append(s,B)),t.children().hover(function(){a(this).addClass("hover")},function(){a(this).removeClass("hover")}).addClass("hover"),L=u.height()+x.height()+t.outerHeight(!0)-t.height(),M=v.width()+w.width()+t.outerWidth(!0)-t.width(),N=A.outerHeight(!0),O=A.outerWidth(!0),r.css({"padding-bottom":L,"padding-right":M}).hide(),G.click(function(){X.next()}),H.click(function(){X.prev()}),I.click(function(){X.close()}),J=G.add(H).add(E).add(F),t.children().removeClass("hover"),q.click(function(){K.overlayClose&&X.close()}),a(b).bind("keydown."+f,function(a){var b=a.keyCode;S&&K.escKey&&b===27&&(a.preventDefault(),X.close()),S&&K.arrowKey&&y[1]&&(b===37?(a.preventDefault(),H.click()):b===39&&(a.preventDefault(),G.click()))})},X.remove=function(){r.add(q).remove(),a("."+g).removeData(e).removeClass(g)},X.position=function(a,c){function g(a){u[0].style.width=x[0].style.width=t[0].style.width=a.style.width,C[0].style.height=C[1].style.height=t[0].style.height=v[0].style.height=w[0].style.height=a.style.height}var d=0,e=0;z.unbind("resize."+f),r.hide(),K.fixed&&!o?r.css({position:"fixed"}):(d=z.scrollTop(),e=z.scrollLeft(),r.css({position:"absolute"})),K.right!==!1?e+=Math.max(z.width()-K.w-O-M-Z(K.right,"x"),0):K.left!==!1?e+=Z(K.left,"x"):e+=Math.round(Math.max(z.width()-K.w-O-M,0)/2),K.bottom!==!1?d+=Math.max(b.documentElement.clientHeight-K.h-N-L-Z(K.bottom,"y"),0):K.top!==!1?d+=Z(K.top,"y"):d+=Math.round(Math.max(b.documentElement.clientHeight-K.h-N-L,0)/2),r.show(),a=r.width()===K.w+O&&r.height()===K.h+N?0:a||0,s[0].style.width=s[0].style.height="9999px",r.dequeue().animate({width:K.w+O,height:K.h+N,top:d,left:e},{duration:a,complete:function(){g(this),T=!1,s[0].style.width=K.w+O+M+"px",s[0].style.height=K.h+N+L+"px",c&&c(),setTimeout(function(){z.bind("resize."+f,X.position)},1)},step:function(){g(this)}})},X.resize=function(a){if(S){a=a||{},a.width&&(K.w=Z(a.width,"x")-O-M),a.innerWidth&&(K.w=Z(a.innerWidth,"x")),A.css({width:K.w}),a.height&&(K.h=Z(a.height,"y")-N-L),a.innerHeight&&(K.h=Z(a.innerHeight,"y"));if(!a.innerHeight&&!a.height){var b=A.wrapInner("<div style='overflow:auto'></div>").children();K.h=b.height(),b.replaceWith(b.children())}A.css({height:K.h}),X.position(K.transition==="none"?0:K.speed)}},X.prep=function(b){function h(){K.h=K.h||A.height(),K.h=K.mh&&K.mh<K.h?K.mh:K.h;return K.h}function g(){K.w=K.w||A.width(),K.w=K.mw&&K.mw<K.w?K.mw:K.w;return K.w}if(!!S){var c,d=K.transition==="none"?0:K.speed;A.remove(),A=Y("LoadedContent").append(b),A.hide().appendTo(B.show()).css({width:g(),overflow:K.scrolling?"auto":"hidden"}).css({height:h()}).prependTo(t),B.hide(),a(R).css({"float":"none"}),o&&a("select").not(r.find("select")).filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one(k,function(){this.style.visibility="inherit"}),c=function(){function o(){n&&r[0].style.removeAttribute("filter")}var b,c,g,h,i=y.length,k,l;!S||(l=function(){clearTimeout(W),C.hide(),ba(j,K.onComplete)},n&&R&&A.fadeIn(100),D.html(K.title).add(A).show(),i>1?(typeof K.current=="string"&&E.html(K.current.replace("{current}",Q+1).replace("{total}",i)).show(),G[K.loop||Q<i-1?"show":"hide"]().html(K.next),H[K.loop||Q?"show":"hide"]().html(K.previous),b=Q?y[Q-1]:y[i-1],g=Q<i-1?y[Q+1]:y[0],K.slideshow&&F.show(),K.preloading&&(h=a.data(g,e).href||g.href,c=a.data(b,e).href||b.href,h=a.isFunction(h)?h.call(g):h,c=a.isFunction(c)?c.call(b):c,$(h)&&(a("<img/>")[0].src=h),$(c)&&(a("<img/>")[0].src=c))):J.hide(),K.iframe?(k=a("<iframe/>").addClass(f+"Iframe")[0],K.fastIframe?l():a(k).one("load",l),k.name=f+ +(new Date),k.src=K.href,K.scrolling||(k.scrolling="no"),n&&(k.frameBorder=0,k.allowTransparency="true"),a(k).appendTo(A).one(m,function(){k.src="//about:blank"})):l(),K.transition==="fade"?r.fadeTo(d,1,o):o())},K.transition==="fade"?r.fadeTo(d,0,function(){X.position(0,c)}):X.position(d,c)}},X.load=function(b){var c,d,e=X.prep;T=!0,R=!1,P=y[Q],b||_(),ba(m),ba(i,K.onLoad),K.h=K.height?Z(K.height,"y")-N-L:K.innerHeight&&Z(K.innerHeight,"y"),K.w=K.width?Z(K.width,"x")-O-M:K.innerWidth&&Z(K.innerWidth,"x"),K.mw=K.w,K.mh=K.h,K.maxWidth&&(K.mw=Z(K.maxWidth,"x")-O-M,K.mw=K.w&&K.w<K.mw?K.w:K.mw),K.maxHeight&&(K.mh=Z(K.maxHeight,"y")-N-L,K.mh=K.h&&K.h<K.mh?K.h:K.mh),c=K.href,W=setTimeout(function(){C.show()},100),K.inline?(Y().hide().insertBefore(a(c)[0]).one(m,function(){a(this).replaceWith(A.children())}),e(a(c))):K.iframe?e(" "):K.html?e(K.html):$(c)?(a(R=new Image).addClass(f+"Photo").error(function(){K.title=!1,e(Y("Error").text("This image could not be loaded"))}).load(function(){var a;R.onload=null,K.scalePhotos&&(d=function(){R.height-=R.height*a,R.width-=R.width*a},K.mw&&R.width>K.mw&&(a=(R.width-K.mw)/R.width,d()),K.mh&&R.height>K.mh&&(a=(R.height-K.mh)/R.height,d())),K.h&&(R.style.marginTop=Math.max(K.h-R.height,0)/2+"px"),y[1]&&(Q<y.length-1||K.loop)&&(R.style.cursor="pointer",R.onclick=function(){X.next()}),n&&(R.style.msInterpolationMode="bicubic"),setTimeout(function(){e(R)},1)}),setTimeout(function(){R.src=c},1)):c&&B.load(c,K.data,function(b,c,d){e(c==="error"?Y("Error").text("Request unsuccessful: "+d.statusText):a(this).contents())})},X.next=function(){!T&&y[1]&&(Q<y.length-1||K.loop)&&(Q=Q<y.length-1?Q+1:0,X.load())},X.prev=function(){!T&&y[1]&&(Q||K.loop)&&(Q=Q?Q-1:y.length-1,X.load())},X.close=function(){S&&!U&&(U=!0,S=!1,ba(k,K.onCleanup),z.unbind("."+f+" ."+p),q.fadeTo(200,0),r.stop().fadeTo(300,0,function(){r.add(q).css({opacity:1,cursor:"auto"}).hide(),ba(m),A.remove(),setTimeout(function(){U=!1,ba(l,K.onClosed)},1)}))},X.element=function(){return a(P)},X.settings=d,V=function(a){a.button!==0&&typeof a.button!="undefined"||a.ctrlKey||a.shiftKey||a.altKey||(a.preventDefault(),bc(this))},a.fn.delegate?a(b).delegate("."+g,"click",V):a("."+g).live("click",V),a(X.init)})(jQuery,document,this);
/**/


function open_content(bg)
{
	if (typeof(content_active) == "undefined" || content_active == false)
	{
		if ($('#menu a.active').length)
		{
			$('#menu a.active').stop().animate({backgroundPosition:"(0 0)"}, 100).removeClass('active').siblings('div.sub').removeClass('active').slideToggle('medium', function()
			{
				$("#slidermask").stop().hide('slide', {direction: 'right'}, 500, function()
				{
					changebg_open_main(bg)
				});
			});
		}
		else
		{
			$("#slidermask").stop().hide('slide', {direction: 'right'}, 500, function()
			{
				changebg_open_main(bg)
			});
		}
	}
	else
	{
		changebg_open_main(bg);
	}
}


function changebg_open_main(bg)
{
	if (bg != false)
	{
		if ($('#supersized img').attr('src') != '/media/up/bg/' + bg)
		{
			$('#supersized-loader').show();
			$.cacheImage('/media/up/bg/' + bg,
			{
				load: function(e)
				{
					if (!$.browser.msie || ($.browser.msie && parseInt($.browser.version) >= 9))
					{
						$('#supersized').fadeOut(1500, function()
						{
							$('#supersized img').attr('src', '/media/up/bg/' + bg);
							$('#supersized').fadeIn(1500, function()
							{
								$('#supersized-loader').hide();

								open_main();
							});
						});
					}
					else
					{
						$('#supersized').hide('fast', function()
						{
							$('#supersized img').attr('src', '/media/up/bg/' + bg);
							$('#supersized').show('fast', function()
							{
								$('#supersized-loader').hide();

								open_main();
							});
						});
					}
				}
			});
		}
		else
		{
			open_main();
		}
	}
	else
	{
		open_main();
	}
}


function open_main()
{
	if (x < 1120)
	{
		$("#main").css({'left':'97px'});
		blankspacer_width = blankspacer_width - 203;
	}
	else
	{
		$("#main").css({'left':'300px'});
	}

	if (typeof(content_active) == "undefined" || content_active == false)
	{
		$("#menu div.mlink").hide();
		$('#right_menu_mask').hide();
		$("#main").css({'width':'1px','display':'block'}).animate({'width':'814px'}, 1000, function()
		{
			$('#right_menu_mask').show('slide', {direction: 'left'}, 300);
		}).css({'overflow':'auto'});
		$("#blankspacer").css({'width':'1px','display':'table-cell'}).animate({'width':blankspacer_width+'px'}, 1200, function()
		{
			$("#blankspacer").css({'min-width':blankspacer_width+'px'})
		});

		content_active = true;
	}

	if (!$.browser.msie || ($.browser.msie && parseInt($.browser.version) >= 9))
	{
		if (typeof map !== "undefined" && map)
		{
			setTimeout(function()
			{
				google.maps.event.trigger(map, 'resize');
				window.map.setZoom(map.getZoom());
				window.map.setCenter(latlng);
			}, 1);
		}
	}
}

function close_content()
{
	if (content_active)
	{
		$("#main").animate({'width':'0px'}, 300, function()
		{
			$("#main").css({'display':'none'})
			$("#menu div.mlink").show();//'slide', {direction: 'right'}, 300);
		});
		$("#blankspacer").animate({'width':'0px'}, 100).css({'min-width':'0','width':'1px','display':'none'});

		$('#supersized-loader').show();
		$.cacheImage('/media/up/bg/inicio.jpg',
		{
			load: function(e)
			{
				if (!$.browser.msie || ($.browser.msie && parseInt($.browser.version) >= 9))
				{
					$('#supersized').fadeOut(1500, function()
					{
						$('#supersized img').attr('src', '/media/up/bg/inicio.jpg');
						$('#supersized').fadeIn(1500, function()
						{
							$('#supersized-loader').hide();

							$("#slidermask").show('slide', {direction: 'right'}, 300);

						});
					});
				}
				else
				{
					$('#supersized').hide('fast', function()
					{
						$('#supersized img').attr('src', '/media/up/bg/inicio.jpg');
						$('#supersized').show('fast', function()
						{
							$('#supersized-loader').hide();

							$("#slidermask").show('slide', {direction: 'right'}, 300);

						});
					});
				}
			}
		});

		content_active = false;
	}
}

function refresh()
{
	$('input[type=text], textarea').defaultValue();

	if (!$.browser.msie || ($.browser.msie && parseInt($.browser.version) >= 9))
	{
		Cufon.refresh();

		if ($.browser.msie)
		{
			$('#supersized-loader').hide();
		}
	}
	else
	{
		$('#supersized-loader').hide();
	}

	$('[placeholder]').focus(function()
	{
		var input = $(this);
		if (input.val() == input.attr('placeholder'))
		{
			input.val('');
			input.removeClass('placeholder');
		}
		}).blur(function() {
		var input = $(this);
		if (input.val() == '' || input.val() == input.attr('placeholder'))
		{
			input.addClass('placeholder');
			input.val(input.attr('placeholder'));
		}
	}).blur();

	$("a.gallery").colorbox({rel:'colorbox'});
}

$(document).ready(function()
{
	w=window,d=document,e=d.documentElement,g=d.getElementsByTagName('body')[0],x=w.innerWidth||e.clientWidth||g.clientWidth,y=w.innerHeight||e.clientHeight||g.clientHeight;

	$(window).bind('resize', function()
	{
		w=window,d=document,e=d.documentElement,g=d.getElementsByTagName('body')[0],x=w.innerWidth||e.clientWidth||g.clientWidth,y=w.innerHeight||e.clientHeight||g.clientHeight;

		if (content_active)
		{
			if (x < 1120)
			{
				$("#main").animate({'left':'97px'}, 300).css({'left':'97px'});
				blankspacer_width = blankspacer_width - 203;
			}
			else
			{
				$("#main").animate({'left':'300px'}, 300).css({'left':'300px'});
				blankspacer_width = 815;
			}
			$("#blankspacer:visible").css({'min-width':blankspacer_width+'px'}).animate({'width':blankspacer_width+'px'}, 500);
		}

		$('#slidermask').remove().clone().appendTo('#content').autoscroll(AUTOSCROLL_X);

		if (!$.browser.msie || ($.browser.msie && parseInt($.browser.version) >= 9))
		{
			Cufon.refresh();
		}
	});

	$.cacheImage([
		'/media/img/bgs/main.png',
		'/media/img/bgcell.png'
	])

	// Cufón
	if (!$.browser.msie || ($.browser.msie && parseInt($.browser.version) >= 9))
	{
		Cufon.replace('h1', {hover: true, fontFamily: 'ze'});
		Cufon.replace('h2, h3, h4', {hover: true, fontFamily: 'al'});
		Cufon.replace('.txt', {hover: true, fontFamily: 'al'});
		Cufon.replace('#menu a, #right_menu a', {hover: true, fontFamily: 'ze'});
	}

	// Slider
	var mask = $('#slidermask');
	var slider = $('#slider');
	mask.css({'overflow': 'hidden', 'overflow-x': 'hidden'});

	if ($('#slider > div').length > 0)
	{
		slider_width = 901 * $('#slider > div').length;
		$('#slider').css({width: slider_width});

		// Get menu width
		var mask_width = mask.width();

		var last_div = slider.find('div:last');
		slider_width = last_div[0].offsetLeft + last_div.outerWidth() + 1;
		$('#slider').css({width: slider_width});
		mask.autoscroll(AUTOSCROLL_X);
	}
	else
	{
		$('#slidermask').hide();
	}

	blankspacer_width = 815;

	// Content starts hidden
	content_active = false;

	// Click binds
	$('a.language').live('click', function()
	{
		alert('Em manutenção');
		return false;
	});

	$('#menu a.sub').click(function()
	{
		if ($(this).hasClass('active'))
		{
			$(this).animate({backgroundPosition:"(0 0)"}, 100).removeClass('active');
			$(this).siblings('div.sub').removeClass('active').slideToggle('medium');
		}
		else
		{
			$('#menu a.active').animate({backgroundPosition:"(0 0)"}, 100).removeClass('active').siblings('div.sub').removeClass('active').slideToggle('medium');

			$(this).animate({backgroundPosition:"(0 -90px)"}, 100, 'easeInQuad', function()
			{
				$(this).siblings('div.sub').addClass('active').slideToggle('medium', 'easeOutQuad');
			}).addClass('active');
		}

		return false;
	});

	$("#menu #logo a, a.voltar").live('click', function()
	{
		close_content();
		return false;
	});

	$(".jsc, #main_content a:not([rel])").live('click', function()
	{
		$.getJSON(this.href, function(data)
		{
			$("#main_content .content").html(data.content);

			if (data.right_menu == false)
			{
				blankspacer_width = 700;

				if (x < 1120)
				{
					$("#main").css({'left':'97px'});
					if (blankspacer_width > 612)
					{
						blankspacer_width = blankspacer_width - 203;
					}
				}
				else
				{
					$("#main").css({'left':'300px'});
				}
				$("#right_menu_mask").hide('slide', {direction: 'right'}, 500);
				$("#right_menu").html('');
				$("#blankspacer:visible").css({'min-width':blankspacer_width+'px'}).animate({'width':blankspacer_width+'px'}, 300);
			}
			else
			{
				blankspacer_width = 815;
				if (typeof data.spacer !== "undefined")
				{
					blankspacer_width = data.spacer;
				}
				$("#right_menu").html(data.right_menu);
				$("#right_menu_mask:hidden").show('slide', {direction: 'left'}, 500);
				$("#blankspacer:visible").css({'min-width':blankspacer_width+'px'}).animate({'width':blankspacer_width+'px'}, 300);
			}

			refresh();
			open_content(data.bg);
		});


		return false;
	});

	$('form#contact').live('submit', function(form)
	{
		var email = $('input#email').val();
		var name = $('input#name').val();
		var phone = $('input#phone').val();
		var message = $('textarea#message').val();

		if (email != '' && name != '' && message != '')
		{
			var box = $("div#form_box");
			box.html('<div id="ajax-loader"><img src="/media/img/ajax-loader.gif" /></div>');

			$('form#contact .submit').attr('disabled', 'disabled');

			$.ajax({
				type: "POST",
				url: "/contactos",
				data: "email=" + email + "&name=" + name + "&phone=" + phone + "&message=" + message,
				dataType: 'json',
				success: function(data)
				{
					box.html(data.html);
					refresh();
				}
			});
		}
		else
		{
			alert('Por favor preencha todos os campos.');
		}

		return false;
	});

	$('form#jobs').live('submit', function(form)
	{
		var email = $('input#email').val();
		var name = $('input#name').val();
		var phone = $('input#phone').val();
		var message = $('textarea#message').val();

		if (email != '' && name != '' && message != '')
		{
			var box = $("div#form_box");
			box.html('<div id="ajax-loader"><img src="/media/img/ajax-loader.gif" /></div>');

			$('form#contact .submit').attr('disabled', 'disabled');

			$.ajax({
				type: "POST",
				url: "/emprego",
				data: "email=" + email + "&name=" + name + "&phone=" + phone + "&message=" + message,
				dataType: 'json',
				success: function(data)
				{
					box.html(data.html);
					refresh();
				}
			});
		}
		else
		{
			alert('Por favor preencha todos os campos.');
		}

		return false;
	});

	$('form#contact_prod').live('submit', function(form)
	{
		var email = $('input#email').val();
		var name = $('input#name').val();
		var phone = $('input#phone').val();
		var message = $('textarea#message').val();

		var product = $('input#product').val();

		if (email != '' && name != '' && message != '')
		{
			var box = $("div#form_box");
			box.html('<div id="ajax-loader"><img src="/media/img/ajax-loader.gif" /></div>');

			$("form#contact_prod input[type='submit']").attr("disabled", true);

			$.ajax({
				type: "POST",
				url: "/contactos",
				data: "email=" + email + "&name=" + name + "&phone=" + phone + "&message=" + message + "&product=" + product,
				dataType: 'json',
				success : function(data)
				{
					box.html(data.html);
					refresh();
				}
			});
		}
		else
		{
			alert('Por favor preencha todos os campos.');
		}

		return false;
	});

	$('form#newsletter').live('submit', function(form)
	{
		var name = $('input#name').val();
		var email = $('input#email').val();

		if (email != '' && name != '')
		{
			var box = $("div#form_box");
			box.html('<div id="ajax-loader"><img src="/media/img/ajax-loader.gif" /></div>');

			$("form#newsletter input[type='submit']").attr("disabled", true);

			$.ajax({
				type: "POST",
				url: "/newsletter",
				data: "name=" + name + "&email=" + email,
				dataType: 'json',
				success : function(data)
				{
					box.html(data.html);
					refresh();
				}
			});
		}
		else
		{
			alert('Por favor preencha todos os campos.');
		}

		return false;
	});

	$('form#search').live('submit', function(form)
	{
		var query = $('input#query').val();

		if (query != '')
		{
			$.ajax({
				type: "POST",
				url: "/produtos/pesquisa",
				data: "query=" + query,
				dataType: 'json',
				success : function(data)
				{
					$("#main_content .content").html(data.content);

					if (data.right_menu == false)
					{
						blankspacer_width = 700;

						if (x < 1120)
						{
							$("#main").css({'left':'97px'});
							if (blankspacer_width > 612)
							{
								blankspacer_width = blankspacer_width - 203;
							}
						}
						else
						{
							$("#main").css({'left':'300px'});
						}
						$("#right_menu_mask").hide('slide', {direction: 'right'}, 500);
						$("#right_menu").html('');
						$("#blankspacer:visible").css({'min-width':blankspacer_width+'px'}).animate({'width':blankspacer_width+'px'}, 300);
					}
					else
					{
						blankspacer_width = 815;
						if (typeof data.spacer !== "undefined")
						{
							blankspacer_width = data.spacer;
						}
						$("#right_menu").html(data.right_menu);
						$("#right_menu_mask:hidden").show('slide', {direction: 'left'}, 500);
						$("#blankspacer:visible").css({'min-width':blankspacer_width+'px'}).animate({'width':blankspacer_width+'px'}, 300);
					}

					refresh();
					open_content(data.bg);
				}
			});
		}
		else
		{
			alert('Por favor insira um valor a pesquisar.');
		}

		return false;
	});

	$("a[rel='gallery']").live('click', function()
	{
		if ($('#img li.active').attr('id') != this.id)
		{
			new_id = this.id;
			old_id = $('#img ul li.active').attr('id');

			img = $(this).attr('name');

			$.cacheImage('/media/up/gal/' + img);

			$('#img li.active').hide().removeClass('active');
			$('#img li#' + new_id).show().addClass('active');
		}

		return false;
	});

	$('#cert').hover(function()
	{
		$('#cert_big').addClass('active').stop(false, true).fadeIn('medium', 'easeOutQuad');
	},
	function()
	{
		$('#cert_big').removeClass('active').stop(false, true).fadeOut('medium', 'easeOutQuad');
	});

	refresh();
});
