﻿(function(){if(typeof Spry=="undefined"||!Spry.Widget||!Spry.Widget.Base){alert("SpryPanelSet.js requires SpryWidget.js!");return}Spry.Widget.PanelSet=function(b,c){Spry.Widget.Base.call(this);this.elements=b?Spry.$$(b):[];this.currentPanel=null;this.displayTimerID=0;this.setOptions(this,Spry.Widget.PanelSet.config);this.setOptions(this,c);if(typeof this.defaultPanel=="number")if(this.defaultPanel<0)this.defaultPanel=0;else{var a=this.getPanelCount();if(this.defaultPanel>=a)this.defaultPanel=a>1?a-1:0}this.initialize()};Spry.Widget.PanelSet.prototype=new Spry.Widget.Base;Spry.Widget.PanelSet.prototype.constructor=Spry.Widget.PanelSet;Spry.Widget.PanelSet.config={defaultPanel:0,autoPlay:false,displayInterval:4e3,visibleClass:"PanelVisible",hiddenClass:"PanelHidden"};Spry.Widget.PanelSet.prototype.initialize=function(){var b=new Spry.Widget.Event(this);this.notifyObservers("onPreInitialize",b);if(!b.performDefaultAction)return;this.defaultPanel=this.indexToElement(this.defaultPanel);var f=this.getPanels();for(var c=0;c<f.length;c++){var a=f[c],e=this.hiddenClass,d=this.visibleClass;if(a==this.defaultPanel){e=this.visibleClass;d=this.hiddenClass;this.currentPanel=this.defaultPanel}Spry.Utils.addClassName(a,e);Spry.Utils.removeClassName(a,d)}if(this.autoPlay)this.play();this.notifyObservers("onPostInitialize",b)};Spry.Widget.PanelSet.prototype.getPanels=function(){return this.elements.slice(0)};Spry.Widget.PanelSet.prototype.getPanelCount=function(){return this.getPanels().length};Spry.Widget.PanelSet.prototype.getCurrentPanel=function(){return this.currentPanel};Spry.Widget.PanelSet.prototype.getCurrentPanelIndex=function(){return this.getPanelIndex(this.getCurrentPanel())};Spry.Widget.PanelSet.prototype.getPanelIndex=function(c){var b=this.getPanels();for(var a=0;a<b.length;a++)if(c==b[a])return a;return -1};Spry.Widget.PanelSet.prototype.getPanel=function(a){return this.getPanels()[a]};Spry.Widget.PanelSet.prototype.indexToElement=function(a){if(typeof a=="number")return this.getPanels()[a];return a?Spry.$$(a)[0]:a};Spry.Widget.PanelSet.prototype.elementToIndex=function(a){var b=this.getPanels();if(typeof a=="number")return b[a];if(typeof a=="string")a=Spry.$$(a)[0];return !a?-1:b.indexOf(a)};Spry.Widget.PanelSet.prototype.createEvent=function(a,c){var b={target:a,targetIndex:this.getPanelIndex(a)};return new Spry.Widget.Event(this,this.setOptions(b,c))};Spry.Widget.PanelSet.prototype.showPanel=function(c){var a=this.indexToElement(c);if(a&&a!=this.currentPanel){var b=this.createEvent(a,{currentPanel:this.currentPanel});this.notifyObservers("onPreShowPanel",b);if(b.performDefaultAction){if(this.currentPanel)this.hidePanel(this.currentPanel);this.currentPanel=a;Spry.Utils.addClassName(a,this.visibleClass);Spry.Utils.removeClassName(a,this.hiddenClass);this.notifyObservers("onPostShowPanel",b)}}};Spry.Widget.PanelSet.prototype.hidePanel=function(){var a=this.createEvent(this.currentPanel);this.notifyObservers("onPreHidePanel",a);if(a.performDefaultAction){var b=this.currentPanel;Spry.Utils.addClassName(b,this.hiddenClass);Spry.Utils.removeClassName(b,this.visibleClass);this.currentPanel=null;this.notifyObservers("onPostHidePanel",a)}};Spry.Widget.PanelSet.prototype.showPreviousPanel=function(){var a=new Spry.Widget.Event(this);this.notifyObservers("onPreShowPreviousPanel",a);if(!a.performDefaultAction)return;var b=this.getCurrentPanelIndex();this.showPanel((b<1?this.getPanelCount():b)-1);this.notifyObservers("onPostShowPreviousPanel",a)};Spry.Widget.PanelSet.prototype.showNextPanel=function(){var a=new Spry.Widget.Event(this);this.notifyObservers("onPreShowNextPanel",a);if(!a.performDefaultAction)return;this.showPanel((this.getCurrentPanelIndex()+1)%this.getPanelCount());this.notifyObservers("onPostShowNextPanel",a)};Spry.Widget.PanelSet.prototype.showFirstPanel=function(){var a=new Spry.Widget.Event(this);this.notifyObservers("onPreShowFirstPanel",a);if(!a.performDefaultAction)return;this.showPanel(0);this.notifyObservers("onPostShowFirstPanel",a)};Spry.Widget.PanelSet.prototype.showLastPanel=function(){var a=new Spry.Widget.Event(this);this.notifyObservers("onPreShowLastPanel",a);if(!a.performDefaultAction)return;var b=this.getPanelCount();this.showPanel(b>0?b-1:0);this.notifyObservers("onPostShowLastPanel",a)};Spry.Widget.PanelSet.prototype.startTimer=function(){this.stopTimer();var a=this;this.displayTimerID=setTimeout(function(){a.showNextPanel();a.startTimer()},this.displayInterval)};Spry.Widget.PanelSet.prototype.stopTimer=function(){if(this.displayTimerID)clearTimeout(this.displayTimerID);this.displayTimerID=0};Spry.Widget.PanelSet.prototype.isPlaying=function(){return this.displayTimerID!=0};Spry.Widget.PanelSet.prototype.play=function(){var a=new Spry.Widget.Event(this);this.notifyObservers("onPreStartSlideShowMode",a);if(!a.performDefaultAction)return;this.startTimer();this.notifyObservers("onPostStartSlideShowMode",a)};Spry.Widget.PanelSet.prototype.stop=function(){var a=new Spry.Widget.Event(this);this.notifyObservers("onPreStopSlideShowMode",a);if(!a.performDefaultAction)return;this.stopTimer();this.notifyObservers("onPostStopSlideShowMode",a)}})()
