Slideshow = function(id)
{
  var me = this;
  this.current_slide = 0;
  this.element = $(id)
  this.icon_width = 25;
  this.items = this.element.find(".drawers > li");
  this.opacity_hover = 1.0;
  this.opacity_start = 0.7;
  this.slides = this.element.find(".slide");
  this.slides.not(":first").css("zIndex", "-1").fadeOut(0);
  this.slideTimer = null;
  this.speed = 'fast';
  this.timer = null;
 
  this.animate = function(tabs, active)
  {
    var slide = tabs.find(".content");
    var shadow = tabs.find(".shadow");
    shadow.css("background-position", active ? "0 -70px" : "0 0");
  };
  
  this.items.each(function(i)
  {
    $(this).data("index", i);
  });

  this.onclick = function(e)
  {
    $(this).find("a").click();
    //e.preventDefault();
  }
  
  this.onmouseover = function(e)
  {
    var tab = $(this);
    var tabIndex = parseInt(tab.data("index"));
    
    tab.trigger("select");
    
    if (me.slideTimer != null)
    {
      clearTimeout(me.slideTimer);
    }
    
    me.slideTimer = setTimeout(function(){me.showSlide(tabIndex)}, 250);
    me.stop();
  };

  this.onselect = function(e)
  {
    var tab = $(this);
    var tabOther = me.items.not(tab);
    
    me.animate(tabOther, false);
    me.animate(tab, true);
  };
  
  this.showNextSlide = function()
  {
    me.showSlide(me.current_slide + 1);
  }
  
  this.showSlide = function(index)
  {
    if (index == me.current_slide)
    {
      return;
    }
    
    var i1 = me.current_slide;
    var i2 = index % me.slides.length;
    
    me.current_slide = i2;
    me.slides.eq(i1).css("zIndex", 1);
    me.slides.eq(i2).css("zIndex", 2).fadeIn(500, function()
    {
      me.slides.eq(i1).fadeOut(0);
    });
    
    me.items.eq(i2).trigger("select");
  }
  
  this.start = function()
  {
    me.timer = setInterval(me.showNextSlide, 5000);
  }
  
  this.stop = function()
  {
    me.timer = clearInterval(me.timer);
  }

  me.items.bind("select", me.onselect).click(me.onclick).mouseover(me.onmouseover).eq(0).trigger("select");
  me.start();
}

