(function(a){a.movingBoxes=function(b,c){var d,e=this;e.$el=a(b).addClass("mb-slider");e.el=b;e.$el.data("movingBoxes",e);e.init=function(){e.options=d=a.extend({},a.movingBoxes.defaultOptions,c);e.$el.wrap('<div class="movingBoxes mb-wrapper"><div class="mb-scroll" /></div>');e.$window=e.$el.parent();e.$wrap=e.$window.parent().css({width:d.width}).prepend('<a class="mb-scrollButtons mb-left"></a>').append('<a class="mb-scrollButtons mb-right"></a><div class="mb-left-shadow"></div><div class="mb-right-shadow"></div>');e.$panels=e.$el.children().addClass("mb-panel");e.runTime=a(".mb-slider").index(e.$el)+1;e.regex=new RegExp("slider"+e.runTime+"=(\\d+)","i");e.initialized=false;e.currentlyMoving=false;e.curPanel=1;e.$left=e.$wrap.find(".mb-left").click(function(){e.goBack();return false});e.$right=e.$wrap.find(".mb-right").click(function(){e.goForward();return false});e.update();a(window).load(function(){e.update(false)});e.$el.delegate(".mb-panel","click",function(){e.change(e.$panels.index(a(this))+1)});e.$wrap.click(function(){e.active()});e.$panels.delegate("a","focus",function(){var b=e.$panels.index(a(this).closest(".mb-panel"))+1;if(b!==e.curPanel){e.change(e.$panels.index(a(this).closest(".mb-panel"))+1,{},false)}});a(document).keyup(function(a){if(a.target.tagName.match("TEXTAREA|INPUT|SELECT")){return}switch(a.which){case 39:case 32:if(e.$wrap.is(".mb-active-slider")){e.goForward()}break;case 37:if(e.$wrap.is(".mb-active-slider")){e.goBack()}break}});var b=d.hashTags?e.getHash()||d.startPanel:d.startPanel;a.each("initialized.movingBoxes initChange.movingBoxes beforeAnimation.movingBoxes completed.movingBoxes".split(" "),function(b,c){var f=c.split(".")[0];if(a.isFunction(d[f])){e.$el.bind(c,d[f])}});setTimeout(function(){e.change(b,function(){e.initialized=true;e.$el.trigger("initialized.movingBoxes",[e,b])})},d.speed*2)};e.update=function(b){var c;e.$panels=e.$el.children().addClass("mb-panel").css({width:d.width*d.panelWidth,margin:5}).each(function(){if(a(this).find(".mb-inside").length===0){a(this).wrapInner('<div class="mb-inside" />')}});e.totalPanels=e.$panels.length;c=e.$panels.eq(e.curPanel-1);e.curWidth=e.curWidth||c.outerWidth();e.regWidth=e.curWidth*d.reducedSize;e.$panels.css({width:e.curWidth,fontSize:"1em"});e.$panels.eq(e.curPanel-1).addClass(d.currentPanel);e.heights=e.$panels.map(function(b,c){return a(c).outerHeight(true)}).get();e.returnToNormal(e.curPanel,0);e.growBigger(e.curPanel,0,b);if(!d.wrap){e.updateArrows(e.curPanel)}e.$el.css({position:"absolute",width:(e.curWidth+100)*e.totalPanels+(d.width-e.curWidth)/2,height:Math.max.apply(this,e.heights)+10});e.$window.css({height:d.fixedHeight?Math.max.apply(this,e.heights):e.heights[e.curPanel-1]});e.$panels.eq(0).css({"margin-left":(d.width-e.curWidth)/2});e.buildNav();e.change(e.curPanel,{},false)};e.buildNav=function(){e.$navLinks={};if(e.$nav){e.$nav.remove()}if(d.buildNav&&e.totalPanels>1){e.$nav=a('<div class="mb-controls"><a class="mb-testing"></a></div>').appendTo(e.$wrap);var b,c="",f=a.isFunction(d.navFormatter),g=parseInt(e.$nav.find(".mb-testing").css("text-indent"),10)<0;e.$panels.each(function(e){b=e+1;c+='<a href="#" class="mb-panel'+b;if(f){var h=d.navFormatter(b,a(this));c+=g?" "+d.tooltipClass+'" title="'+h:"";c+='">'+h+"</a> "}else{c+='">'+b+"</a> "}});e.$navLinks=e.$nav.html(c).find("a").bind("click",function(){e.change(e.$navLinks.index(a(this))+1);return false})}};e.returnToNormal=function(a,b){var c=e.$panels.not(":eq("+(a-1)+")").removeClass(d.currentPanel);if(d.reducedSize===1){c.css({width:e.regWidth})}else{c.animate({width:e.regWidth,fontSize:d.reducedSize+"em",top:15+"px"},b===0?b:d.speed)}};e.growBigger=function(a,b,c){var f=e.$panels.eq(a-1);if(d.reducedSize===1){f.css({width:e.curWidth});if(e.initialized){e.completed(a,c)}}else{f.animate({width:e.curWidth,fontSize:"1em",top:0},b===0?b:d.speed,function(){if(e.initialized){e.completed(a,c)}})}};e.completed=function(a,b){e.$panels.eq(a-1).addClass(d.currentPanel);if(b!==false){e.$el.trigger("completed.movingBoxes",[e,a])}};e.goForward=function(){if(e.initialized){e.change(e.curPanel+1)}};e.goBack=function(){if(e.initialized){e.change(e.curPanel-1)}};e.change=function(a,b,c){a=parseInt(a,10);if(e.initialized){e.active();e.$el.trigger("initChange.movingBoxes",[e,a])}if(d.wrap){if(a<1){a=e.totalPanels}if(a>e.totalPanels){a=1}}else{if(a<1){a=1}if(a>e.totalPanels){a=e.totalPanels}}if(e.initialized&&e.curPanel===a&&!c){return false}if(!e.currentlyMoving||!e.initialized){e.currentlyMoving=true;var f,g=e.$panels.eq(a-1).position().left-(d.width-e.curWidth)/2;if(a>e.curPanel){g-=e.curWidth-e.regWidth}f=d.fixedHeight?{scrollLeft:g}:{scrollLeft:g,height:e.heights[a-1]};if(e.initialized){e.$el.trigger("beforeAnimation.movingBoxes",[e,a])}e.$window.animate(f,{queue:false,duration:d.speed,easing:d.easing,complete:function(){e.curPanel=a;if(e.initialized){e.$window.scrollTop(0)}e.currentlyMoving=false;if(typeof b==="function"){b(e)}}});e.returnToNormal(a);e.growBigger(a);if(!d.wrap){e.updateArrows(a)}if(d.hashTags&&e.initialized){e.setHash(a)}}e.$wrap.find(".mb-controls a").removeClass(d.currentPanel).eq(a-1).addClass(d.currentPanel)};e.updateArrows=function(a){e.$left.toggleClass(d.disabled,a===1);e.$right.toggleClass(d.disabled,a===e.totalPanels)};e.getHash=function(){var a=window.location.hash.match(e.regex);return a===null?"":parseInt(a[1],10)};e.setHash=function(a){var b="slider"+e.runTime+"=",c=window.location.hash;if(typeof c!=="undefined"){window.location.hash=c.indexOf(b)>0?c.replace(e.regex,b+a):c+"&"+b+a}};e.active=function(b){a(".mb-active-slider").removeClass("mb-active-slider");e.$wrap.addClass("mb-active-slider")};e.currentPanel=function(a,b){if(typeof a!=="undefined"){e.change(a,b)}return e.curPanel};e.init()};a.movingBoxes.defaultOptions={startPanel:1,width:800,panelWidth:.5,reducedSize:.8,fixedHeight:false,speed:500,hashTags:true,wrap:false,buildNav:false,navFormatter:null,easing:"swing",currentPanel:"current",tooltipClass:"tooltip",disabled:"disabled",initialized:null,initChange:null,beforeAnimation:null,completed:null};a.fn.movingBoxes=function(b,c){var d,e=this.data("movingBoxes");return this.each(function(){if((typeof b).match("object|undefined")){if(e){e.update()}else{new a.movingBoxes(this,b)}}else if(/\d/.test(b)&&!isNaN(b)&&e){d=typeof b==="number"?b:parseInt(a.trim(b),10);if(d>=1&&d<=e.totalPanels){e.change(d,c)}}})};a.fn.getMovingBoxes=function(){return this.data("movingBoxes")}})(jQuery)
