(function(a){a.movingBoxes=function(c,b){var d=this;d.$el=a(c).addClass("movingBoxes");d.el=c;d.$el.data("movingBoxes",d);d.init=function(){d.options=a.extend({},a.movingBoxes.defaultOptions,b);d.$el.css({width:d.options.width}).wrapInner('<div class="mb-scrollContainer" />').wrapInner('<div class="mb-scroll" />').prepend('<a class="mb-scrollButtons mb-left"></a>').append('<a class="mb-scrollButtons mb-right"></a>').find(".mb-scrollContainer "+d.options.panelType).addClass("mb-panel").wrapInner('<div class="mb-inside" />');d.$container=d.$el.find(".mb-scrollContainer");d.$window=d.$el.find(".mb-scroll");d.runTime=a(".movingBoxes").index(d.$el)+1;d.regex=new RegExp("slider"+d.runTime+"=(\\d+)","i");d.$navLinks={};d.$panels=d.$el.find(".mb-panel").css({width:d.options.width*d.options.panelWidth});d.totalPanels=d.$panels.length;d.curWidth=d.$panels.outerWidth();d.curImgWidth=d.$panels.find("img").outerWidth(true);d.curImgHeight=d.curImgWidth/d.options.imageRatio;d.regWidth=d.curWidth*d.options.reducedSize;d.regImgWidth=d.curImgWidth*d.options.reducedSize;d.regImgHeight=d.curImgHeight*d.options.reducedSize;d.$panels.find("img").css({height:d.curImgHeight});d.heights=d.$panels.map(function(f,g){return a(g).outerHeight(true)}).get();d.$container.css({position:"absolute",width:(d.curWidth+50)*d.totalPanels,height:Math.max.apply(this,d.heights)});d.$window.css({height:Math.max.apply(this,d.heights)});d.$panels.eq(0).css({"margin-left":(d.options.width-d.curWidth)/2});var e=(d.options.hashTags)?d.getHash()||d.options.startPanel:d.options.startPanel;d.initialized=false;d.currentlyMoving=false;d.curPanel=1;d.change(1);d.buildNav();d.$el.find(".mb-right").click(function(){d.goForward();return false}).end().find(".mb-left").click(function(){d.goBack();return false});d.$panels.click(function(){d.change(d.$panels.index(a(this))+1)});d.$el.click(function(){d.active()});d.$panels.find("a").focus(function(){var f=d.$el.find(".mb-panel").index(a(this).closest(".mb-panel"))+1;if(f!==d.curPanel){d.change(d.$el.find(".mb-panel").index(a(this).closest(".mb-panel"))+1,{},false)}});a(document).keyup(function(f){switch(f.which){case 39:case 32:if(d.$el.is(".mb-active-slider")){d.goForward()}break;case 37:if(d.$el.is(".mb-active-slider")){d.goBack()}break}});setTimeout(function(){d.change(e,function(){a.each("initialized.movingBoxes initChange.movingBoxes beforeAnimation.movingBoxes completed.movingBoxes".split(" "),function(g,h){var f=h.split(".")[0];if(a.isFunction(d.options[f])){d.$el.bind(h,d.options[f])}});d.initialized=true;d.$el.trigger("initialized.movingBoxes",[d,e])})},d.options.speed*2)};d.buildNav=function(){if(d.options.buildNav&&(d.totalPanels>1)){d.$nav=a('<div class="mb-controls"><a class="mb-testing"></a></div>').appendTo(d.$el);var f,e="",g=a.isFunction(d.options.navFormatter),h=parseInt(d.$nav.find(".mb-testing").css("text-indent"),10)<0;d.$panels.each(function(k){f=k+1;e+='<a href="#" class="mb-panel'+f;if(g){var j=d.options.navFormatter(f,a(this));e+=(h)?" "+d.options.tooltipClass+'" title="'+j:"";e+='">'+j+"</a> "}else{e+='">'+f+"</a> "}});d.$navLinks=d.$nav.html(e).find("a").bind("click",function(){d.change(d.$navLinks.index(a(this))+1);return false})}};d.returnToNormal=function(e){d.$panels.not(":eq("+(e-1)+")").removeClass(d.options.currentPanel).animate({width:d.regWidth,fontSize:d.options.reducedSize+"em"},d.options.speed).find("img").animate({width:d.regImgWidth,height:d.regImgHeight},d.options.speed);d.$panels.not(":eq("+(e-1)+")").find("h2").css({width:d.regImgWidth})};d.growBigger=function(e){d.$panels.eq(e-1).addClass(d.options.currentPanel).animate({width:d.curWidth,fontSize:"1em"},d.options.speed).find("img").animate({width:d.curImgWidth,height:d.curImgHeight},d.options.speed,function(){if(d.initialized){d.$el.trigger("completed.movingBoxes",[d,e])}});d.$panels.eq(e-1).find("h2").css({width:d.curImgWidth})};d.goForward=function(){d.change(d.curPanel+1)};d.goBack=function(){d.change(d.curPanel-1)};d.change=function(g,i,f){g=parseInt(g,10);if(d.initialized){d.active();d.$el.trigger("initChange.movingBoxes",[d,g])}if(d.options.wrap){if(g<1){g=d.totalPanels}if(g>d.totalPanels){g=1}}else{if(g<1){g=1}if(g>d.totalPanels){g=d.totalPanels}}if(d.initialized&&d.curPanel==g&&!f){return false}if(!d.currentlyMoving){d.currentlyMoving=true;var e,h=d.$panels.eq(g-1).position().left-(d.options.width-d.curWidth)/2;if(g>d.curPanel){h-=(d.curWidth-d.regWidth)}e=(d.options.fixedHeight)?{scrollLeft:h}:{scrollLeft:h,height:d.heights[g-1]};if(d.initialized){d.$el.trigger("beforeAnimation.movingBoxes",[d,g])}d.$window.animate(e,{queue:false,duration:d.options.speed,easing:d.options.easing,complete:function(){d.curPanel=g;if(d.initialized){d.$panels.eq(g-1).find("a").focus();d.$window.scrollTop(0)}d.currentlyMoving=false;if(typeof(i)==="function"){i(d)}}});d.returnToNormal(g);d.growBigger(g);if(d.options.hashTags){d.setHash(g)}}d.$el.find(".mb-controls a").removeClass(d.options.currentPanel).eq(g-1).addClass(d.options.currentPanel)};d.getHash=function(){var e=window.location.hash.match(d.regex);return(e===null)?"":parseInt(e[1],10)};d.setHash=function(g){var f="slider"+d.runTime+"=",e=window.location.hash;if(typeof e!=="undefined"){window.location.hash=(e.indexOf(f)>0)?e.replace(d.regex,f+g):e+"&"+f+g}};d.active=function(e){a(".mb-active-slider").removeClass("mb-active-slider");d.$el.addClass("mb-active-slider")};d.currentPanel=function(e,f){if(typeof(e)!=="undefined"){d.change(e,f)}return d.curPanel};d.init()};a.movingBoxes.defaultOptions={startPanel:1,width:800,panelWidth:0.5,reducedSize:0.8,imageRatio:4/3,fixedHeight:false,speed:500,hashTags:true,wrap:false,buildNav:false,navFormatter:null,easing:"swing",currentPanel:"current",tooltipClass:"tooltip",panelType:"> div",initialized:null,initChange:null,beforeAnimation:null,completed:null};a.fn.movingBoxes=function(b){return this.each(function(){(new a.movingBoxes(this,b))})};a.fn.getMovingBoxes=function(){return this.data("movingBoxes")}})(jQuery);
