// Copyright (c) 2007. Adobe Systems Incorporated.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//   * Redistributions of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//   * Redistributions in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//   * Neither the name of Adobe Systems Incorporated nor the names of its
//     contributors may be used to endorse or promote products derived from this
//     software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
var Spry;if(!Spry){Spry={}}if(!Spry.Widget){Spry.Widget={}}Spry.Widget.SlidingPanels=function(a,b){this.element=this.getElement(a);this.enableAnimation=true;this.currentPanel=null;this.enableKeyboardNavigation=true;this.hasFocus=false;this.previousPanelKeyCode=Spry.Widget.SlidingPanels.KEY_LEFT;this.nextPanelKeyCode=Spry.Widget.SlidingPanels.KEY_RIGHT;this.currentPanelClass="SlidingPanelsCurrentPanel";this.focusedClass="SlidingPanelsFocused";this.animatingClass="SlidingPanelsAnimating";Spry.Widget.SlidingPanels.setOptions(this,b);if(this.element){this.element.style.overflow="hidden"}if(this.defaultPanel){if(typeof this.defaultPanel=="number"){this.currentPanel=this.getContentPanels()[this.defaultPanel]}else{this.currentPanel=this.getElement(this.defaultPanel)}}if(!this.currentPanel){this.currentPanel=this.getContentPanels()[0]}if(Spry.Widget.SlidingPanels.onloadDidFire){this.attachBehaviors()}else{Spry.Widget.SlidingPanels.loadQueue.push(this)}};Spry.Widget.SlidingPanels.prototype.onFocus=function(a){this.hasFocus=true;this.addClassName(this.element,this.focusedClass);return false};Spry.Widget.SlidingPanels.prototype.onBlur=function(a){this.hasFocus=false;this.removeClassName(this.element,this.focusedClass);return false};Spry.Widget.SlidingPanels.KEY_LEFT=37;Spry.Widget.SlidingPanels.KEY_UP=38;Spry.Widget.SlidingPanels.KEY_RIGHT=39;Spry.Widget.SlidingPanels.KEY_DOWN=40;Spry.Widget.SlidingPanels.prototype.onKeyDown=function(b){var a=b.keyCode;if(!this.hasFocus||(a!=this.previousPanelKeyCode&&a!=this.nextPanelKeyCode)){return true}if(a==this.nextPanelKeyCode){this.showNextPanel()}else{this.showPreviousPanel()}if(b.preventDefault){b.preventDefault()}else{b.returnValue=false}if(b.stopPropagation){b.stopPropagation()}else{b.cancelBubble=true}return false};Spry.Widget.SlidingPanels.prototype.attachBehaviors=function(){var e=this.element;if(!e){return}if(this.enableKeyboardNavigation){var a=null;var d=e.attributes.getNamedItem("tabindex");if(d||e.nodeName.toLowerCase()=="a"){a=e}if(a){var b=this;Spry.Widget.SlidingPanels.addEventListener(a,"focus",function(f){return b.onFocus(f||window.event)},false);Spry.Widget.SlidingPanels.addEventListener(a,"blur",function(f){return b.onBlur(f||window.event)},false);Spry.Widget.SlidingPanels.addEventListener(a,"keydown",function(f){return b.onKeyDown(f||window.event)},false)}}if(this.currentPanel){var c=this.enableAnimation;this.enableAnimation=false;this.showPanel(this.currentPanel);this.enableAnimation=c}};Spry.Widget.SlidingPanels.prototype.getElement=function(a){if(a&&typeof a=="string"){return document.getElementById(a)}return a};Spry.Widget.SlidingPanels.prototype.addClassName=function(b,a){if(!b||!a||(b.className&&b.className.search(new RegExp("\\b"+a+"\\b"))!=-1)){return}b.className+=(b.className?" ":"")+a};Spry.Widget.SlidingPanels.prototype.removeClassName=function(b,a){if(!b||!a||(b.className&&b.className.search(new RegExp("\\b"+a+"\\b"))==-1)){return}b.className=b.className.replace(new RegExp("\\s*\\b"+a+"\\b","g"),"")};Spry.Widget.SlidingPanels.setOptions=function(d,c,a){if(!c){return}for(var b in c){if(a&&c[b]==undefined){continue}d[b]=c[b]}};Spry.Widget.SlidingPanels.prototype.getElementChildren=function(b){var a=[];var c=b.firstChild;while(c){if(c.nodeType==1){a.push(c)}c=c.nextSibling}return a};Spry.Widget.SlidingPanels.prototype.getCurrentPanel=function(){return this.currentPanel};Spry.Widget.SlidingPanels.prototype.getContentGroup=function(){return this.getElementChildren(this.element)[0]};Spry.Widget.SlidingPanels.prototype.getContentPanels=function(){return this.getElementChildren(this.getContentGroup())};Spry.Widget.SlidingPanels.prototype.getContentPanelsCount=function(){return this.getContentPanels().length};Spry.Widget.SlidingPanels.onloadDidFire=false;Spry.Widget.SlidingPanels.loadQueue=[];Spry.Widget.SlidingPanels.addLoadListener=function(a){if(typeof window.addEventListener!="undefined"){window.addEventListener("load",a,false)}else{if(typeof document.addEventListener!="undefined"){document.addEventListener("load",a,false)}else{if(typeof window.attachEvent!="undefined"){window.attachEvent("onload",a)}}}};Spry.Widget.SlidingPanels.processLoadQueue=function(c){Spry.Widget.SlidingPanels.onloadDidFire=true;var d=Spry.Widget.SlidingPanels.loadQueue;var a=d.length;for(var b=0;b<a;b++){d[b].attachBehaviors()}};Spry.Widget.SlidingPanels.addLoadListener(Spry.Widget.SlidingPanels.processLoadQueue);Spry.Widget.SlidingPanels.addEventListener=function(c,b,d,a){try{if(c.addEventListener){c.addEventListener(b,d,a)}else{if(c.attachEvent){c.attachEvent("on"+b,d)}}}catch(f){}};Spry.Widget.SlidingPanels.prototype.getContentPanelIndex=function(d){if(d){d=this.getElement(d);var b=this.getContentPanels();var a=b.length;for(var c=0;c<a;c++){if(b[c]==d){return c}}}return -1};Spry.Widget.SlidingPanels.prototype.showPanel=function(i){var g=-1;if(typeof i=="number"){g=i}else{g=this.getContentPanelIndex(i)}var e=this.getContentPanelsCount();if(e>0){g=(g>=e)?e-1:g}else{g=0}var a=this.getContentPanels()[g];var h=this.getContentGroup();if(a&&h){if(this.currentPanel){this.removeClassName(this.currentPanel,this.currentPanelClass)}this.currentPanel=a;var f=-a.offsetLeft;var d=-a.offsetTop;if(this.enableAnimation){if(this.animator){this.animator.stop()}var c=h.offsetLeft;var b=h.offsetTop;if(c!=f||b!=d){var j=this;this.addClassName(this.element,this.animatingClass);this.animator=new Spry.Widget.SlidingPanels.PanelAnimator(h,c,b,f,d,{duration:this.duration,fps:this.fps,transition:this.transition,finish:function(){j.removeClassName(j.element,j.animatingClass);j.addClassName(a,j.currentPanelClass)}});this.animator.start()}}else{h.style.left=f+"px";h.style.top=d+"px";this.addClassName(a,this.currentPanelClass)}}return a};Spry.Widget.SlidingPanels.prototype.showFirstPanel=function(){return this.showPanel(0)};Spry.Widget.SlidingPanels.prototype.showLastPanel=function(){return this.showPanel(this.getContentPanels().length-1)};Spry.Widget.SlidingPanels.prototype.showPreviousPanel=function(){return this.showPanel(this.getContentPanelIndex(this.currentPanel)-1)};Spry.Widget.SlidingPanels.prototype.showNextPanel=function(){return this.showPanel(this.getContentPanelIndex(this.currentPanel)+1)};Spry.Widget.SlidingPanels.PanelAnimator=function(e,b,a,g,f,d){this.element=e;this.curX=b;this.curY=a;this.dstX=g;this.dstY=f;this.fps=60;this.duration=500;this.transition=Spry.Widget.SlidingPanels.PanelAnimator.defaultTransition;this.startTime=0;this.timerID=0;this.finish=null;var c=this;this.intervalFunc=function(){c.step()};Spry.Widget.SlidingPanels.setOptions(this,d,true);this.interval=1000/this.fps};Spry.Widget.SlidingPanels.PanelAnimator.defaultTransition=function(d,b,a,c){d/=c;return b+((2-d)*d*a)};Spry.Widget.SlidingPanels.PanelAnimator.prototype.start=function(){this.stop();this.startTime=(new Date()).getTime();this.timerID=setTimeout(this.intervalFunc,this.interval)};Spry.Widget.SlidingPanels.PanelAnimator.prototype.stop=function(){if(this.timerID){clearTimeout(this.timerID)}this.timerID=0};Spry.Widget.SlidingPanels.PanelAnimator.prototype.step=function(){var c=(new Date()).getTime()-this.startTime;var b=c>=this.duration;var a,d;if(b){a=this.curX=this.dstX;d=this.curY=this.dstY}else{a=this.transition(c,this.curX,this.dstX-this.curX,this.duration);d=this.transition(c,this.curY,this.dstY-this.curY,this.duration)}this.element.style.left=a+"px";this.element.style.top=d+"px";if(!b){this.timerID=setTimeout(this.intervalFunc,this.interval)}else{if(this.finish){this.finish()}}};