// JavaScript Document
var sp;
var spBest;
var spRecommend;
function InitPage()
{
	if(document.getElementById("wnhons"))
	{
		sp = new Spry.Widget.SlidingPanels("wnhons");
	}
	if(document.getElementById("best-sellers"))
	{
		spBest = new Spry.Widget.SlidingPanels("best-sellers");
	}
	if(document.getElementById("recommends"))
	{
		spRecommend = new Spry.Widget.SlidingPanels("recommends");
	}
}
Spry.Utils.addLoadListener(InitPage);


// line 121 of SprySlidingPanels.js
Spry.Widget.SlidingPanels.prototype.attachBehaviors = function()
{
     var ele = this.element;
     if (!ele)
          return;
 
     if (this.enableKeyboardNavigation)
     {
          var focusEle = null;
          var tabIndexAttr = ele.attributes.getNamedItem("tabindex");
          if (tabIndexAttr || ele.nodeName.toLowerCase() == "a")
               focusEle = ele;
     
          if (focusEle)
          {
               var self = this;
               Spry.Widget.SlidingPanels.addEventListener(focusEle, "focus", function(e) { return self.onFocus(e || window.event); }, false);
               Spry.Widget.SlidingPanels.addEventListener(focusEle, "blur", function(e) { return self.onBlur(e || window.event); }, false);
               Spry.Widget.SlidingPanels.addEventListener(focusEle, "keydown", function(e) { return self.onKeyDown(e || window.event); }, false);
          }
     }
 
     if (this.currentPanel)
     {
          // Temporarily turn off animation when showing the
          // initial panel.
 
          var ea = this.enableAnimation;
          this.enableAnimation = false;
          this.showPanel(this.currentPanel);
          this.enableAnimation = ea;
     }
     
     if (this.automatic){
          this.start();
     }
};
 
// These are all new methods
Spry.Widget.SlidingPanels.prototype.start = function(){
     var self = this; // reference to this, so we can use it inside our function
     this.automaticStarted = setInterval(function(){
               var panels = self.getContentPanels(),
                    panelcount = panels.length,
                    current = self.getCurrentPanel(),
                    newpanel;
               
               // locate the current panel index, and check if we need to increase or decrease the panel
               for(var i = 0; i < panelcount; i++){
                    if(panels[i] == current){
                         
                         self.direction == 1 ? (i++) : (i--);
						 
						 Spry.Effect.DoFade(current, {duration: 1000, from: 100, to: 0, toggle: false, finish: function()
						{
							newpanel = panels[self.direction == 1 ? (i >= panels.length ? 0 : i) : (i < 0 ? panels.length -1 : i)]
							newpanel.style.opacity = '0';
							newpanel.style.filter = 'alpha(opacity=0)';
					
							self.showPanel( self.direction == 1 ? (i >= panels.length ? 0 : i) : (i < 0 ? panels.length -1 : i));
					
							current.style.opacity = '';
							current.style.filter = '';
							Spry.Effect.DoFade(newpanel, {duration: 1000, from: 0, to: 100, toggle: false, finish: function()
							{
								
							}});
						}});
											 
                              
                                   
                         break; // stop looping, we already found and are displaying our new panel
                    }
               }
     }, this.each || 3000);
};
 
Spry.Widget.SlidingPanels.prototype.stop = function(){
     if(this.automaticStarted && typeof this.automaticStarted == 'number'){
          clearInterval(this.automaticStarted);
          this.automaticStarted = null;
     }
};
 
Spry.Widget.SlidingPanels.prototype.setDirection = function(direction){
     this.direction = direction;
}
