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