﻿(function(){if(typeof Spry=="undefined"||!Spry.Widget||!Spry.Widget.Base){alert("SpryPanelSelector.js requires SpryWidget.js!");return}Spry.Widget.PanelSelector=function(b,c,d){Spry.Widget.Base.call(this);this.buttons=Spry.$$(b);this.panel=c;this.disablePanelCallbacks=0;this.currentButton=null;this.setOptions(this,Spry.Widget.PanelSelector.config);this.setOptions(this,d);if(typeof this.defaultButton=="number")if(this.defaultButton<0)this.defaultButton=0;else{var a=this.getButtonCount();if(this.defaultButton>=a)this.defaultButton=a>1?a-1:0}this.attachBehaviors()};Spry.Widget.PanelSelector.config={event:"click",defaultButton:0,selectionStopsSlideShow:true,useHrefs:false,selectedClass:"PanelSelectorButtonSelected",unselectedClass:"PanelSelectorButtonUnselected",downClass:"PanelSelectorButtonDown",disabledClass:"PanelSelectorButtonDisabled",hoverClass:"PanelSelectorButtonHover",focusedClass:"PanelSelectorButtonFocused"};Spry.Widget.PanelSelector.prototype=new Spry.Widget.Base;Spry.Widget.PanelSelector.prototype.constructor=Spry.Widget.PanelSelector;Spry.Widget.PanelSelector.prototype.getPanelIDFromHREF=function(b){if(b){var a=b.getAttribute("href");if(a!=undefined&&a.search(/^#\w/)!=-1)return a.replace(/.*#/,"#")}return null};Spry.Widget.PanelSelector.prototype.getButtonCount=function(){return this.buttons.length};Spry.Widget.PanelSelector.prototype.getCurrentButton=function(){return this.currentButton};Spry.Widget.PanelSelector.prototype.getCurrentButtonIndex=function(){return this.elementToIndex(this.getCurrentButton())};Spry.Widget.PanelSelector.prototype.elementToIndex=function(c){var b=this.buttons,d=b.length;for(var a=0;a<d;a++)if(b[a]==c)return a;return -1};Spry.Widget.PanelSelector.prototype.indexToElement=function(a){return typeof a=="number"?this.buttons[a]:a};Spry.Widget.PanelSelector.prototype.enableButton=function(b){var a=this.indexToElement(b);if(a&&a.psButton)a.psButton.enable()};Spry.Widget.PanelSelector.prototype.disableButton=function(b){var a=this.indexToElement(b);if(a&&a.psButton)a.psButton.disable()};Spry.Widget.PanelSelector.prototype.focusButton=function(b){var a=this.indexToElement(b);if(a&&a.psButton)a.psButton.focus()};Spry.Widget.PanelSelector.prototype.selectButton=function(g,f){++this.disablePanelCallbacks;var d=this.buttons,a=this.indexToElement(g);for(var c=0;c<d.length;c++){var b=d[c];this.removeClassName(b,b==a?this.unselectedClass:this.selectedClass);this.addClassName(b,b==a?this.selectedClass:this.unselectedClass)}this.currentButton=a;if(!f&&this.panel){var e=this.useHrefs?this.getPanelIDFromHREF(a):null;this.panel.showPanel(e?e:this.elementToIndex(a))}--this.disablePanelCallbacks};Spry.Widget.PanelSelector.prototype.selectPreviousButton=function(){var a=new Spry.Widget.Event(this);this.notifyObservers("onPrePanelSelectorSelectPreviousButton",a);if(!a.performDefaultAction)return;var b=this.getCurrentButtonIndex();this.handleActivate((b<1?this.getButtonCount():b)-1);this.notifyObservers("onPostPanelSelectorSelectPreviousButton",a)};Spry.Widget.PanelSelector.prototype.selectNextButton=function(){var a=new Spry.Widget.Event(this);this.notifyObservers("onPrePanelSelectorSelectNextButton",a);if(!a.performDefaultAction)return;this.handleActivate((this.getCurrentButtonIndex()+1)%this.getButtonCount());this.notifyObservers("onPostPanelSelectorSelectNextButton",a)};Spry.Widget.PanelSelector.prototype.selectFirstButton=function(){var a=new Spry.Widget.Event(this);this.notifyObservers("onPrePanelSelectorSelectFirstButton",a);if(!a.performDefaultAction)return;this.handleActivate(0);this.notifyObservers("onPostPanelSelectorSelectFirstButton",a)};Spry.Widget.PanelSelector.prototype.selectLastButton=function(){var a=new Spry.Widget.Event(this);this.notifyObservers("onPrePanelSelectorSelectLastButton",a);if(!a.performDefaultAction)return;var b=this.getButtonCount();this.handleActivate(b>0?b-1:0);this.notifyObservers("onPostPanelSelectorSelectLastButton",a)};Spry.Widget.PanelSelector.prototype.handleActivate=function(a){if(typeof a=="string")a=document.getElementById(a);var b=new Spry.Widget.Event(this,{target:a,targetIndex:this.elementToIndex(a)});this.notifyObservers("onPrePanelSelectorClick",b);if(!b.performDefaultAction)return;if(this.selectionStopsSlideShow&&this.panel)this.panel.stop();this.selectButton(a);this.notifyObservers("onPostPanelSelectorClick",b)};Spry.Widget.PanelSelector.prototype.handlePanelChange=function(e){if(this.disablePanelCallbacks)return;var h=e.target,g=e.targetIndex;if(!this.panel)return;var d=h.id,b=this.buttons,a=b[g];if(d)for(var c=0;!a&&c<b.length;c++){var f=b[c],i=this.getPanelIDFromHREF(f);if(i==d){a=f;break}}if(a)this.selectButton(a,true)};Spry.Widget.PanelSelector.prototype.attachButtonBehaviors=function(a){var c=this,b=function(){c.handleActivate(a);return false};a.psButton=new Spry.Widget.Button(a,{onclick:b,downClass:this.downClass,hoverClass:this.hoverClass,disabledClass:this.disabledClass,focusedClass:this.focusedClass});if(this.event!="click")this.addEventListener(a,this.event,b,false)};Spry.Widget.PanelSelector.prototype.attachBehaviors=function(){var c=this,b=this.buttons;for(var a=0;a<b.length;a++)this.attachButtonBehaviors(b[a]);if(this.panel)this.panel.addObserver({onPostShowPanel:function(b,a){c.handlePanelChange(a)}});this.selectButton(this.defaultButton)}})()
