/*!
 * @copyright Advanced Care Solutions, Inc.
 * @author Christopher Rahauiser <crahauiser@acs-web.com>
 * @depends jquery.ui.widget.js
 */
(function(a){a.widget("acs.slideshow",{options:{autoPlay:true,timerDuration:6000,prepareNext:function(b,c){},preparePrevious:function(b,c){},childrenSetup:function(b){},animateInNextEasing:"swing",animateInNextDuration:1200,animateInNextProperties:{opacity:"toggle"},animateInNextCallback:function(){a(this).css("z-index",2)},animateOutNextEasing:"swing",animateOutNextDuration:1200,animateOutNextProperties:{opacity:"toggle"},animateOutNextCallback:function(){a(this).css("z-index",1)},animateInPreviousEasing:"swing",animateInPreviousDuration:1200,animateInPreviousProperties:{opacity:"toggle"},animateInPreviousCallback:function(){a(this).css("z-index",2)},animateOutPreviousEasing:"swing",animateOutPreviousDuration:1200,animateOutPreviousProperties:{opacity:"toggle"},animateOutPreviousCallback:function(){a(this).css("z-index",1)},nextSelector:".acs-slideshow-next",previousSelector:".acs-slideshow-previous",playPauseSelector:".acs-slideshow-play-pause",playClass:"acs-slideshow-play",pauseClass:"acs-slideshow-pause"},timer:null,animating:false,children:a([]),playPauseControls:a([]),nextControls:a([]),previousControls:a([]),_current:0,_next:1,play:function(b){if(this.options.disabled){return}if(!b&&this._trigger("beforePlay")===false){return}this.playPauseControls.addClass(this.options.pauseClass).removeClass(this.options.playClass);this.timer=setInterval(a.proxy(this.next,this),this.options.timerDuration);if(!b){this._trigger("play")}},pause:function(b){if(this.options.disabled){return}if(!b&&this._trigger("beforePause")===false){return}clearInterval(this.timer);this.timer=null;this.playPauseControls.addClass(this.options.playClass).removeClass(this.options.pauseClass);if(!b){this._trigger("pause")}},next:function(){if(this.options.disabled){return}if(this.animating){return}if(this._trigger("beforeNext")===false){return}this.animating=true;this.pause(true);this._next=this._current+1;if(this._next==this.children.length){this._next=0}this.options.prepareNext(this.children.eq(this._next),this.children.eq(this._current));var b=this;this.children.eq(this._next).animate(this.options.animateInNextProperties,this.options.animateInNextDuration,this.options.animateInNextEasing,this.options.animateInNextCallback).end().eq(this._current).animate(this.options.animateOutNextProperties,this.options.animateOutNextDuration,this.options.animateOutNextEasing,function(){b.options.animateOutNextCallback.call(this);b.animating=false;b._trigger("next")});this._current=this._next;this.play(true)},previous:function(){if(this.options.disabled){return}if(this.animating){return}if(this._trigger("beforePrevious")===false){return}this.animating=true;this.pause(true);this._next=this._current-1;if(this._next<0){this._next=this.children.length-1}this.options.preparePrevious(this.children.eq(this._next),this.children.eq(this._current));var b=this;this.children.eq(this._next).animate(this.options.animateInPreviousProperties,this.options.animateInPreviousDuration,this.options.animateInPreviousEasing,this.options.animateInPreviousCallback).end().eq(this._current).animate(this.options.animateOutPreviousProperties,this.options.animateOutPreviousDuration,this.options.animateOutPreviousEasing,function(){b.options.animateOutPreviousCallback.call(this);b.animating=false;b._trigger("previous")});this._current=this._next;this.play(true)},enable:function(){a.Widget.prototype.enable.apply(this,arguments);this._init()},disable:function(){a.Widget.prototype.disable.apply(this,arguments);if(this.timer){clearInterval(this.timer);this.timer=null}},destroy:function(){if(this.timer){clearInterval(this.timer);this.timer=null}this.playPauseControls.hide().unbind(".slideshow");this.nextControls.hide().unbind(".slideshow");this.previousControls.hide().unbind(".slideshow");this.children.eq(0).show().end().not(":eq(0)").hide().end().css({top:0,left:0});a.Widget.prototype.destroy.apply(this,arguments)},_create:function(){this.children=this.element.children();if(this.children.length>1){this.options.childrenSetup(this.children)}this.playPauseControls=a(this.options.playPauseSelector).show().bind("click.slideshow",a.proxy(this._playPauseClick,this));this.nextControls=a(this.options.nextSelector).show().bind("click.slideshow",a.proxy(this._nextClick,this));this.previousControls=a(this.options.previousSelector).show().bind("click.slideshow",a.proxy(this._previousClick,this))},_init:function(){if(this.options.autoPlay){this.play()}},_playPauseClick:function(b){b.preventDefault();if(this.playPauseControls.hasClass(this.options.pauseClass)){this.pause()}else{this.play()}},_nextClick:function(b){b.preventDefault();this.next()},_previousClick:function(b){b.preventDefault();this.previous()}})})(jQuery);
