/************************************************************
 * jQuery Styler 0.0.1
 *
 * This only works with browsers that support localStorage
 * This has been updated to use localStorage instead of cookies
 * Original code by Molokoloco at https://github.com/molokoloco/FRAMEWORK (it was called styleswitch)
 *
 * Plugin that loads and switches stylesheets:
 * Manage links to change style
 * Add stylesheet to head, if the stylesheet does not exist
 * If the stylsheet already exists, switch style with the disabled attribute
 * It will only deal with styles that have the "jquery-styler" class, so it doesn't mess with your other stylesheets
 *
 * Example:
 * 
 * <head>
 *   <link rel="stylesheet" type="text/css" media="all" href="css/styles.css" class="jquery-styler"/>
 * </head>
 * <body>
 *   <ul>
 *     <li><a href="javascript:void(0);" rel="css/styles.css" class="styler">Original</a></li>
 *     <li><a href="javascript:void(0);" rel="css/style_light.css" class="styler">Blanc</a></li>
 *     <li><a href="javascript:void(0);" rel="css/style_dark.css" class="styler">Sombre</a></li>
 *   </ul>
 * </body>
 * 
 * // JS USE CASE
 * $('a.styler').styler(); // When the user clicks, then the rel stylesheet will be swapped in
 * $.styler('swap', 'css/styles.css'); // Direct style change with JS call
 ************************************************************/
(function(a){var b={disable:function(b){setTimeout(function(){a(b).each(function(){a(this).attr("disabled","disabled")})},250)},load:function(b){a("head").append('<link rel="stylesheet" class="jquery-styler" type="text/css" href="'+b+'"/>')},swap:function(b){var c=!1,d=[];a.fn.styler("styles").each(function(){b==a(this).attr("href")?(a(this).removeAttr("disabled"),c=!0):d.push(this)}),c==0&&a.fn.styler("load",b),a.fn.styler("disable",d),localStorage["jquery.styler.style"]=b},init:function(){if(localStorage["jquery.styler.style"]){var b=!1;a.fn.styler("styles").each(function(){localStorage["jquery.styler.style"]==a(this).attr("href")&&(b=!0)}),b==0&&a.fn.styler("swap",localStorage["jquery.styler.style"])}return a(this).click(function(b){b.preventDefault(),a.fn.styler("swap",a(this).attr("rel")),a(this).blur()})},styles:function(){return a("link.jquery-styler[rel*=style]")}};a.fn.styler=function(c){if(b[c])return b[c].apply(this,Array.prototype.slice.call(arguments,1));if(typeof c=="object"||!c)return b.init.apply(this,arguments);a.error("Method "+c+" does not exist on jQuery.styler")}})(jQuery),function(a,b){function U(b,c){return b=b?' id="'+e+b+'"':"",c=c?' style="'+c+'"':"",a("<div"+b+c+"/>")}function V(a,b){return b=b==="x"?y.width():y.height(),typeof a=="string"?Math.round(/%/.test(a)?b/100*parseInt(a,10):parseInt(a,10)):a}function W(a){return O.photo||/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i.test(a)}function X(b){for(var c in b)a.isFunction(b[c])&&c.substring(0,2)!=="on"&&(b[c]=b[c].call(M));return b.rel=b.rel||M.rel||"nofollow",b.href=b.href||a(M).attr("href"),b.title=b.title||M.title,b}function Y(b,c){c&&c.call(M),a.event.trigger(b)}function Z(){var a,b=e+"Slideshow_",c="click."+e,d,f,j;O.slideshow&&x[1]&&(d=function(){E.text(O.slideshowStop).unbind(c).bind(h,function(){if(N<x.length-1||O.loop)a=setTimeout(S.next,O.slideshowSpeed)}).bind(g,function(){clearTimeout(a)}).one(c+" "+i,f),q.removeClass(b+"off").addClass(b+"on"),a=setTimeout(S.next,O.slideshowSpeed)},f=function(){clearTimeout(a),E.text(O.slideshowStart).unbind([h,g,i,c].join(" ")).one(c,d),q.removeClass(b+"on").addClass(b+"off")},O.slideshowAuto?d():f())}function $(b){if(!R){M=b,O=X(a.extend({},a.data(M,d))),x=a(M),N=0,O.rel!=="nofollow"&&(x=a("."+T).filter(function(){var b=a.data(this,d).rel||this.rel;return b===O.rel}),N=x.index(M),N===-1&&(x=x.add(M),N=x.length-1));if(!P){P=Q=!0,q.show();if(O.returnFocus)try{M.blur(),a(M).one(j,function(){try{this.focus()}catch(a){}})}catch(c){}p.css({opacity:+O.opacity,cursor:O.overlayClose?"pointer":"auto"}).show(),O.w=V(O.initialWidth,"x"),O.h=V(O.initialHeight,"y"),S.position(0),n&&y.bind("resize."+o+" scroll."+o,function(){p.css({width:y.width(),height:y.height(),top:y.scrollTop(),left:y.scrollLeft()})}).trigger("scroll."+o),Y(f,O.onOpen),D.add(G).add(F).add(E).add(C).hide(),H.html(O.close).show()}S.load(!0)}}var c={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,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},d="colorbox",e="cbox",f=e+"_open",g=e+"_load",h=e+"_complete",i=e+"_cleanup",j=e+"_closed",k=e+"_purge",l=e+"_loaded",m=a.browser.msie&&!a.support.opacity,n=m&&a.browser.version<7,o=e+"_IE6",p,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=!1,S,T=e+"Element";S=a.fn[d]=a[d]=function(b,e){var f=this,g;if(!f[0]&&f.selector)return f;b=b||{},e&&(b.onComplete=e);if(!f[0]||f.selector===undefined)f=a("<a/>"),b.open=!0;return f.each(function(){a.data(this,d,a.extend({},a.data(this,d)||c,b)),a(this).addClass(T)}),g=b.open,a.isFunction(g)&&(g=g.call(f)),g&&$(f[0]),f},S.init=function(){y=a(b),q=U().attr({id:d,"class":m?e+"IE":""}),p=U("Overlay",n?"position:absolute":"").hide(),r=U("Wrapper"),s=U("Content").append(z=U("LoadedContent","width:0; height:0; overflow:hidden"),B=U("LoadingOverlay").add(U("LoadingGraphic")),C=U("Title"),D=U("Current"),F=U("Next"),G=U("Previous"),E=U("Slideshow").bind(f,Z),H=U("Close")),r.append(U().append(U("TopLeft"),t=U("TopCenter"),U("TopRight")),U(!1,"clear:left").append(u=U("MiddleLeft"),s,v=U("MiddleRight")),U(!1,"clear:left").append(U("BottomLeft"),w=U("BottomCenter"),U("BottomRight"))).children().children().css({"float":"left"}),A=U(!1,"position:absolute; width:9999px; visibility:hidden; display:none"),a("body").prepend(p,q.append(r,A)),s.children().hover(function(){a(this).addClass("hover")},function(){a(this).removeClass("hover")}).addClass("hover"),I=t.height()+w.height()+s.outerHeight(!0)-s.height(),J=u.width()+v.width()+s.outerWidth(!0)-s.width(),K=z.outerHeight(!0),L=z.outerWidth(!0),q.css({"padding-bottom":I,"padding-right":J}).hide(),F.click(S.next),G.click(S.prev),H.click(S.close),s.children().removeClass("hover"),a("."+T).live("click",function(a){a.button!==0&&typeof a.button!="undefined"||a.ctrlKey||a.shiftKey||a.altKey||(a.preventDefault(),$(this))}),p.click(function(){O.overlayClose&&S.close()}),a(document).bind("keydown",function(a){P&&O.escKey&&a.keyCode===27&&(a.preventDefault(),S.close()),P&&O.arrowKey&&!Q&&x[1]&&(a.keyCode===37&&(N||O.loop)?(a.preventDefault(),G.click()):a.keyCode===39&&(N<x.length-1||O.loop)&&(a.preventDefault(),F.click()))})},S.remove=function(){q.add(p).remove(),a("."+T).die("click").removeData(d).removeClass(T)},S.position=function(a,b){function f(a){t[0].style.width=w[0].style.width=s[0].style.width=a.style.width,B[0].style.height=B[1].style.height=s[0].style.height=u[0].style.height=v[0].style.height=a.style.height}var c,d=Math.max(document.documentElement.clientHeight-O.h-K-I,0)/2+y.scrollTop(),e=Math.max(y.width()-O.w-L-J,0)/2+y.scrollLeft();c=q.width()===O.w+L&&q.height()===O.h+K?0:a,r[0].style.width=r[0].style.height="9999px",q.dequeue().animate({width:O.w+L,height:O.h+K,top:d,left:e},{duration:c,complete:function(){f(this),Q=!1,r[0].style.width=O.w+L+J+"px",r[0].style.height=O.h+K+I+"px",b&&b()},step:function(){f(this)}})},S.resize=function(a){if(P){a=a||{},a.width&&(O.w=V(a.width,"x")-L-J),a.innerWidth&&(O.w=V(a.innerWidth,"x")),z.css({width:O.w}),a.height&&(O.h=V(a.height,"y")-K-I),a.innerHeight&&(O.h=V(a.innerHeight,"y"));if(!a.innerHeight&&!a.height){var b=z.wrapInner("<div style='overflow:auto'></div>").children();O.h=b.height(),b.replaceWith(b.children())}z.css({height:O.h}),S.position(O.transition==="none"?0:O.speed)}},S.prep=function(b){function g(){return O.w=O.w||z.width(),O.w=O.mw&&O.mw<O.w?O.mw:O.w,O.w}function j(){return O.h=O.h||z.height(),O.h=O.mh&&O.mh<O.h?O.mh:O.h,O.h}function k(b){var g,i,j,k,n=x.length,o=O.loop;S.position(b,function(){function b(){m&&q[0].style.removeAttribute("filter")}if(!P)return;m&&c&&z.fadeIn(100),z.show(),Y(l),C.show().html(O.title),n>1&&(typeof O.current=="string"&&D.html(O.current.replace(/\{current\}/,N+1).replace(/\{total\}/,n)).show(),F[o||N<n-1?"show":"hide"]().html(O.next),G[o||N?"show":"hide"]().html(O.previous),g=N?x[N-1]:x[n-1],j=N<n-1?x[N+1]:x[0],O.slideshow&&E.show(),O.preloading&&(k=a.data(j,d).href||j.href,i=a.data(g,d).href||g.href,k=a.isFunction(k)?k.call(j):k,i=a.isFunction(i)?i.call(g):i,W(k)&&(a("<img/>")[0].src=k),W(i)&&(a("<img/>")[0].src=i))),B.hide(),O.transition==="fade"?q.fadeTo(f,1,function(){b()}):b(),y.bind("resize."+e,function(){S.position(0)}),Y(h,O.onComplete)})}if(!P)return;var c,f=O.transition==="none"?0:O.speed;y.unbind("resize."+e),z.remove(),z=U("LoadedContent").html(b),z.hide().appendTo(A.show()).css({width:g(),overflow:O.scrolling?"auto":"hidden"}).css({height:j()}).prependTo(s),A.hide(),a("#"+e+"Photo").css({cssFloat:"none",marginLeft:"auto",marginRight:"auto"}),n&&a("select").not(q.find("select")).filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one(i,function(){this.style.visibility="inherit"}),O.transition==="fade"?q.fadeTo(f,0,function(){k(0)}):k(f)},S.load=function(b){var c,f,h,i=S.prep;Q=!0,M=x[N],b||(O=X(a.extend({},a.data(M,d)))),Y(k),Y(g,O.onLoad),O.h=O.height?V(O.height,"y")-K-I:O.innerHeight&&V(O.innerHeight,"y"),O.w=O.width?V(O.width,"x")-L-J:O.innerWidth&&V(O.innerWidth,"x"),O.mw=O.w,O.mh=O.h,O.maxWidth&&(O.mw=V(O.maxWidth,"x")-L-J,O.mw=O.w&&O.w<O.mw?O.w:O.mw),O.maxHeight&&(O.mh=V(O.maxHeight,"y")-K-I,O.mh=O.h&&O.h<O.mh?O.h:O.mh),c=O.href,B.show(),O.inline?(U().hide().insertBefore(a(c)[0]).one(k,function(){a(this).replaceWith(z.children())}),i(a(c))):O.iframe?(q.one(l,function(){var b=a("<iframe frameborder='0' style='width:100%; height:100%; border:0; display:block'/>")[0];b.name=+(new Date),b.src=O.href,O.scrolling||(b.scrolling="no"),m&&(b.allowtransparency="true"),a(b).appendTo(z).one(k,function(){b.src="//about:blank"})}),i(" ")):O.html?i(O.html):W(c)?(f=new Image,f.onload=function(){var b;f.onload=null,f.id=e+"Photo",a(f).css({border:"none",display:"block",cssFloat:"left"}),O.scalePhotos&&(h=function(){f.height-=f.height*b,f.width-=f.width*b},O.mw&&f.width>O.mw&&(b=(f.width-O.mw)/f.width,h()),O.mh&&f.height>O.mh&&(b=(f.height-O.mh)/f.height,h())),O.h&&(f.style.marginTop=Math.max(O.h-f.height,0)/2+"px"),x[1]&&(N<x.length-1||O.loop)&&a(f).css({cursor:"pointer"}).click(S.next),m&&(f.style.msInterpolationMode="bicubic"),setTimeout(function(){i(f)},1)},setTimeout(function(){f.src=c},1)):c&&A.load(c,function(b,c,d){i(c==="error"?"Request unsuccessful: "+d.statusText:a(this).children())})},S.next=function(){Q||(N=N<x.length-1?N+1:0,S.load())},S.prev=function(){Q||(N=N?N-1:x.length-1,S.load())},S.close=function(){P&&!R&&(R=!0,P=!1,Y(i,O.onCleanup),y.unbind("."+e+" ."+o),p.fadeTo("fast",0),q.stop().fadeTo("fast",0,function(){Y(k),z.remove(),q.add(p).css({opacity:1,cursor:"auto"}).hide(),setTimeout(function(){R=!1,Y(j,O.onClosed)},1)}))},S.element=function(){return a(M)},S.settings=c,a(S.init)}(jQuery,this)
