/*!
 * Waterwheel Carousel
 * Version 2.3.0
 * http://www.bkosborne.com
 *
 * Copyright 2011-2013 Brian Osborne
 * Dual licensed under GPLv3 or MIT
 * Copies of the licenses have been distributed
 * with this plugin.
 *
 * Plugin written by Brian Osborne
 * for use with the jQuery JavaScript Framework
 * http://www.jquery.com
 */
(function(n){"use strict";n.fn.waterwheelCarousel=function(t){function w(){i={itemsContainer:n(e),totalItems:n(e).find("img").length,containerWidth:n(e).width(),containerHeight:n(e).height(),currentCenterItem:null,previousCenterItem:null,items:[],calculations:[],carouselRotationsLeft:0,currentlyMoving:!1,itemsAnimating:0,currentSpeed:r.speed,intervalTimer:null,currentDirection:"forward",leftItemsCount:0,rightItemsCount:0,performingSetup:!0},i.itemsContainer.find("img").removeClass(r.activeClassName)}function u(n){clearTimeout(i.autoPlayTimer),n||r.autoPlay===0||(i.autoPlayTimer=setTimeout(function(){r.autoPlay>0?f("forward"):f("backward")},Math.abs(r.autoPlay)))}function p(t){if(r.preloadImages===!1){t();return}var f=i.itemsContainer.find("img"),u=0,e=f.length;f.each(function(){n(this).bind("load",function(){if(u+=1,u===e){t();return}}),n(this).attr("src",n(this).attr("src")),this.complete&&n(this).trigger("load")})}function y(){i.itemsContainer.find("img").each(function(){(n(this).data("original_width")==undefined||r.forcedImageWidth>0)&&n(this).data("original_width",n(this).width()),(n(this).data("original_height")==undefined||r.forcedImageHeight>0)&&n(this).data("original_height",n(this).height())})}function d(){r.forcedImageWidth&&r.forcedImageHeight&&i.itemsContainer.find("img").each(function(){n(this).width(r.forcedImageWidth),n(this).height(r.forcedImageHeight)})}function c(){var f=i.itemsContainer.find("img:first"),u,t,n;for(i.calculations[0]={distance:0,offset:0,opacity:1},u=r.horizonOffset,t=r.separation,n=1;n<=r.flankingItems+2;n++)n>1&&(u*=r.horizonOffsetMultiplier,t*=r.separationMultiplier),i.calculations[n]={distance:i.calculations[n-1].distance+t,offset:i.calculations[n-1].offset+u,opacity:i.calculations[n-1].opacity*r.opacityMultiplier};r.edgeFadeEnabled?i.calculations[r.flankingItems+1].opacity=0:i.calculations[r.flankingItems+1]={distance:0,offset:0,opacity:0}}function k(){i.items=i.itemsContainer.find("img");for(var t=0;t<i.totalItems;t++)i.items[t]=n(i.items[t]);r.horizon===0&&(r.horizon=r.orientation==="horizontal"?i.containerHeight/2:i.containerWidth/2),i.itemsContainer.css("position","relative").find("img").each(function(){var u,t;r.orientation==="horizontal"?(u=i.containerWidth/2-n(this).data("original_width")/2,t=r.horizon-n(this).data("original_height")/2):(u=r.horizon-n(this).data("original_width")/2,t=i.containerHeight/2-n(this).data("original_height")/2),n(this).css({left:u,top:t,visibility:"visible",position:"absolute","z-index":0,opacity:0}).data({top:t,left:u,oldPosition:0,currentPosition:0,depth:0,opacity:0}).show()})}function b(){var n,t;for(r.startingItem=r.startingItem===0?Math.round(i.totalItems/2):r.startingItem,i.rightItemsCount=Math.ceil((i.totalItems-1)/2),i.leftItemsCount=Math.floor((i.totalItems-1)/2),i.carouselRotationsLeft=1,o(i.items[r.startingItem-1],0),i.items[r.startingItem-1].css("opacity",1),n=r.startingItem-1,t=1;t<=i.rightItemsCount;t++)n<i.totalItems-1?n+=1:n=0,i.items[n].css("opacity",1),o(i.items[n],t);for(n=r.startingItem-1,t=-1;t>=i.leftItemsCount*-1;t--)n>0?n-=1:n=i.totalItems-1,i.items[n].css("opacity",1),o(i.items[n],t)}function v(n,t){var o=Math.abs(t),u,h,a;u=o<r.flankingItems+1?i.calculations[o]:i.calculations[r.flankingItems+1];var v=Math.pow(r.sizeMultiplier,o),f=v*n.data("original_width"),e=v*n.data("original_height"),w=Math.abs(n.width()-f),b=Math.abs(n.height()-e),l=u.offset,s=u.distance;if(t<0&&(s*=-1),r.orientation=="horizontal")var c=i.containerWidth/2,p=c+s-f/2,y=r.horizon-l-e/2;else var c=i.containerHeight/2,p=r.horizon-l-f/2,y=c+s-e/2;h=t===0?1:u.opacity,a=r.flankingItems+2-o,n.data("width",f),n.data("height",e),n.data("top",y),n.data("left",p),n.data("oldPosition",n.data("currentPosition")),n.data("depth",a),n.data("opacity",h)}function o(n,t){Math.abs(t)<=r.flankingItems+1?(v(n,t),i.itemsAnimating++,n.css("z-index",n.data().depth).animate({left:n.data().left,width:n.data().width,height:n.data().height,top:n.data().top,opacity:n.data().opacity},i.currentSpeed,r.animationEasing,function(){h(n,t)})):(n.data("currentPosition",t),n.data("oldPosition")===0&&n.css({left:n.data().left,width:n.data().width,height:n.data().height,top:n.data().top,opacity:n.data().opacity,"z-index":n.data().depth}))}function h(n,t){i.itemsAnimating--,n.data("currentPosition",t),t===0&&(i.currentCenterItem=n),i.itemsAnimating===0&&(i.carouselRotationsLeft-=1,i.currentlyMoving=!1,i.carouselRotationsLeft>0?s(0):(i.currentSpeed=r.speed,i.currentCenterItem.addClass(r.activeClassName),i.performingSetup===!1?(r.movedToCenter(i.currentCenterItem),r.movedFromCenter(i.previousCenterItem)):(i.performingSetup=!1,r.loaded()),u()))}function s(t){var e,s,f,u,h;if(i.currentlyMoving===!1)for(i.currentCenterItem.removeClass(r.activeClassName),i.currentlyMoving=!0,i.itemsAnimating=0,i.carouselRotationsLeft+=t,r.quickerForFurther===!0&&(t>1&&(i.currentSpeed=r.speed/t),i.currentSpeed=i.currentSpeed<100?100:i.currentSpeed),e=0;e<i.totalItems;e++)s=n(i.items[e]),f=s.data("currentPosition"),u=i.currentDirection=="forward"?f-1:f+1,h=u>0?i.rightItemsCount:i.leftItemsCount,Math.abs(u)>h&&(u=f*-1,i.totalItems%2==0&&(u+=1)),o(s,u)}function a(){var n=i.currentCenterItem.next();return n.length<=0&&(n=i.currentCenterItem.parent().children().first()),n}function l(){var n=i.currentCenterItem.prev();return n.length<=0&&(n=i.currentCenterItem.parent().children().last()),n}function f(n){i.currentlyMoving===!1&&(i.previousCenterItem=i.currentCenterItem,r.movingFromCenter(i.currentCenterItem),n=="backward"?(r.movingToCenter(l()),i.currentDirection="backward"):n=="forward"&&(r.movingToCenter(a()),i.currentDirection="forward")),s(1)}if(this.length>1)return this.each(function(){n(this).waterwheelCarousel(t)}),this;var e=this,r={},i={};return n(this).find("img").bind("click",function(t,f){var e=n(this).data().currentPosition,o;r.imageNav!=!1&&(Math.abs(e)>=r.flankingItems+1&&!f||i.currentlyMoving||(i.previousCenterItem=i.currentCenterItem,u(!0),r.autoPlay=0,o=Math.abs(e),e==0?r.clickedCenter(n(this)):(r.movingFromCenter(i.currentCenterItem),r.movingToCenter(n(this)),e<0?(i.currentDirection="backward",s(o)):e>0&&(i.currentDirection="forward",s(o)))))}),n(this).find("a").bind("click",function(t){var i=n(this).find("img").data("currentPosition")==0;if(r.linkHandling===1||r.linkHandling===2&&!i)return t.preventDefault(),!1}),n(document).keydown(function(n){if(r.keyboardNav&&(n.which===37&&r.orientation=="horizontal"||n.which===38&&r.orientation=="vertical"?(u(!0),r.autoPlay=0,f("backward")):(n.which===39&&r.orientation=="horizontal"||n.which===40&&r.orientation=="vertical")&&(u(!0),r.autoPlay=0,f("forward")),i.itemsContainer.is(":visible")&&r.keyboardNavOverride&&(r.orientation=="horizontal"&&(n.which===37||n.which===39)||r.orientation=="vertical"&&(n.which===38||n.which===40))))return n.preventDefault(),!1}),this.reload=function(t){var u;u=typeof t=="object"?t:{},r=n.extend({},n.fn.waterwheelCarousel.defaults,t),w(),i.itemsContainer.find("img").hide(),d(),p(function(){y(),c(),k(),b()})},this.redraw=function(){var f=n(e).width(),o=n(e).height(),t=(f-i.containerWidth)/2,u=(o-i.containerHeight)/2;i.containerWidth=f,i.containerHeight=o,r.horizon===0&&(r.horizon=r.orientation==="horizontal"?i.containerHeight/2:i.containerWidth/2),i.itemsContainer.find("img").each(function(){n(this).css({left:parseFloat(n(this).css("left"))+t,top:parseFloat(n(this).css("top"))+u}).data("top",n(this).data("top")+u).data("left",n(this).data("left")+t)})},this.next=function(){u(!0),r.autoPlay=0,f("forward")},this.prev=function(){u(!0),r.autoPlay=0,f("backward")},this.reload(t),this},n.fn.waterwheelCarousel.defaults={startingItem:1,separation:175,separationMultiplier:.6,horizonOffset:0,horizonOffsetMultiplier:1,sizeMultiplier:.7,opacityMultiplier:.8,horizon:0,flankingItems:3,speed:300,animationEasing:"linear",quickerForFurther:!0,edgeFadeEnabled:!1,linkHandling:2,autoPlay:0,orientation:"horizontal",activeClassName:"carousel-center",keyboardNav:!1,keyboardNavOverride:!0,imageNav:!0,preloadImages:!0,forcedImageWidth:0,forcedImageHeight:0,movingToCenter:n.noop,movedToCenter:n.noop,clickedCenter:n.noop,movingFromCenter:n.noop,movedFromCenter:n.noop,loaded:n.noop}})(jQuery)