/*! * 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($){'use strict';$.fn.waterwheelCarousel=function(startingOptions){if(this.length>1){this.each(function(){$(this).waterwheelCarousel(startingOptions)});return this} var carousel=this;var options={};var data={};function initializeCarouselData(){data={itemsContainer:$(carousel),totalItems:$(carousel).find('img').length,containerWidth:$(carousel).width(),containerHeight:$(carousel).height(),currentCenterItem:null,previousCenterItem:null,items:[],calculations:[],carouselRotationsLeft:0,currentlyMoving:!1,itemsAnimating:0,currentSpeed:options.speed,intervalTimer:null,currentDirection:'forward',leftItemsCount:0,rightItemsCount:0,performingSetup:!0};data.itemsContainer.find('img').removeClass(options.activeClassName)} function autoPlay(stop){clearTimeout(data.autoPlayTimer);if(!stop&&options.autoPlay!==0){data.autoPlayTimer=setTimeout(function(){if(options.autoPlay>0){moveOnce('forward')}else{moveOnce('backward')}},Math.abs(options.autoPlay))}} function preload(callback){if(options.preloadImages===!1){callback();return} var $imageElements=data.itemsContainer.find('img'),loadedImages=0,totalImages=$imageElements.length;$imageElements.each(function(){$(this).bind('load',function(){loadedImages+=1;if(loadedImages===totalImages){callback();return}});$(this).attr('src',$(this).attr('src'));if(this.complete){$(this).trigger('load')}})} function setOriginalItemDimensions(){data.itemsContainer.find('img').each(function(){if($(this).data('original_width')==undefined||options.forcedImageWidth>0){$(this).data('original_width',$(this).width())} if($(this).data('original_height')==undefined||options.forcedImageHeight>0){$(this).data('original_height',$(this).height())}})} function forceImageDimensionsIfEnabled(){if(options.forcedImageWidth&&options.forcedImageHeight){data.itemsContainer.find('img').each(function(){$(this).width(options.forcedImageWidth);$(this).height(options.forcedImageHeight)})}} function preCalculatePositionProperties(){var $firstItem=data.itemsContainer.find('img:first');data.calculations[0]={distance:0,offset:0,opacity:1} var horizonOffset=options.horizonOffset;var separation=options.separation;for(var i=1;i<=options.flankingItems+2;i++){if(i>1){horizonOffset*=options.horizonOffsetMultiplier;separation*=options.separationMultiplier} data.calculations[i]={distance:data.calculations[i-1].distance+separation,offset:data.calculations[i-1].offset+horizonOffset,opacity:data.calculations[i-1].opacity*options.opacityMultiplier}} if(options.edgeFadeEnabled){data.calculations[options.flankingItems+1].opacity=0}else{data.calculations[options.flankingItems+1]={distance:0,offset:0,opacity:0}}} function setupCarousel(){data.items=data.itemsContainer.find('img');for(var i=0;i=data.leftItemsCount*-1;pos--){(itemIndex>0)?itemIndex-=1:itemIndex=data.totalItems-1;data.items[itemIndex].css('opacity',1);moveItem(data.items[itemIndex],pos)}} function performCalculations($item,newPosition){var newDistanceFromCenter=Math.abs(newPosition);if(newDistanceFromCenter0){rotateCarousel(0)}else{data.currentSpeed=options.speed;data.currentCenterItem.addClass(options.activeClassName);if(data.performingSetup===!1){options.movedToCenter(data.currentCenterItem);options.movedFromCenter(data.previousCenterItem)} data.performingSetup=!1;autoPlay()}}} function rotateCarousel(rotations){if(data.currentlyMoving===!1){data.currentCenterItem.removeClass(options.activeClassName);data.currentlyMoving=!0;data.itemsAnimating=0;data.carouselRotationsLeft+=rotations;if(options.quickerForFurther===!0){if(rotations>1){data.currentSpeed=options.speed/rotations} data.currentSpeed=(data.currentSpeed<100)?100:data.currentSpeed} for(var i=0;i0)?data.rightItemsCount:data.leftItemsCount;if(Math.abs(newPosition)>flankingAllowance){newPosition=currentPosition*-1;if(data.totalItems%2==0){newPosition+=1}} moveItem($item,newPosition)}}} $(this).find('img').bind("click",function(){var itemPosition=$(this).data().currentPosition;if(options.imageNav==!1){return} if(Math.abs(itemPosition)>=options.flankingItems+1){return} if(data.currentlyMoving){return} data.previousCenterItem=data.currentCenterItem;autoPlay(!0);options.autoPlay=0;var rotations=Math.abs(itemPosition);if(itemPosition==0){options.clickedCenter($(this))}else{options.movingFromCenter(data.currentCenterItem);options.movingToCenter($(this));if(itemPosition<0){data.currentDirection='backward';rotateCarousel(rotations)}else if(itemPosition>0){data.currentDirection='forward';rotateCarousel(rotations)}}});$(this).find('a').bind("click",function(event){var isCenter=$(this).find('img').data('currentPosition')==0;if(options.linkHandling===1||(options.linkHandling===2&&!isCenter)){event.preventDefault();return!1}});function nextItemFromCenter(){var $next=data.currentCenterItem.next();if($next.length<=0){$next=data.currentCenterItem.parent().children().first()} return $next} function prevItemFromCenter(){var $prev=data.currentCenterItem.prev();if($prev.length<=0){$prev=data.currentCenterItem.parent().children().last()} return $prev} function moveOnce(direction){if(data.currentlyMoving===!1){data.previousCenterItem=data.currentCenterItem;options.movingFromCenter(data.currentCenterItem);if(direction=='backward'){options.movingToCenter(prevItemFromCenter());data.currentDirection='backward'}else if(direction=='forward'){options.movingToCenter(nextItemFromCenter());data.currentDirection='forward'}} rotateCarousel(1)} $(document).keydown(function(e){if(options.keyboardNav){if((e.which===37&&options.orientation=='horizontal')||(e.which===38&&options.orientation=='vertical')){autoPlay(!0);options.autoPlay=0;moveOnce('backward')}else if((e.which===39&&options.orientation=='horizontal')||(e.which===40&&options.orientation=='vertical')){autoPlay(!0);options.autoPlay=0;moveOnce('forward')} if(options.keyboardNavOverride&&((options.orientation=='horizontal'&&(e.which===37||e.which===39))||(options.orientation=='vertical'&&(e.which===38||e.which===40)))){e.preventDefault();return!1}}});this.reload=function(newOptions){if(typeof newOptions==="object"){var combineDefaultWith=newOptions}else{var combineDefaultWith={}} options=$.extend({},$.fn.waterwheelCarousel.defaults,newOptions);initializeCarouselData();data.itemsContainer.find('img').hide();forceImageDimensionsIfEnabled();preload(function(){setOriginalItemDimensions();preCalculatePositionProperties();setupCarousel();setupStarterRotation()})} this.next=function(){autoPlay(!0);options.autoPlay=0;moveOnce('forward')} this.prev=function(){autoPlay(!0);options.autoPlay=0;moveOnce('backward')} this.reload(startingOptions);return this};$.fn.waterwheelCarousel.defaults={startingItem:1,separation:175,separationMultiplier:0.6,horizonOffset:0,horizonOffsetMultiplier:1,sizeMultiplier:0.7,opacityMultiplier:0.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:$.noop,movedToCenter:$.noop,clickedCenter:$.noop,movingFromCenter:$.noop,movedFromCenter:$.noop}})(jQuery)