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

