// custom transition effect for slideshow
$.tools.tabs.addEffect("myEffect", function(tabIndex, done)
{
  // get the currently visible slide and the next one
  var currTab = this.getCurrentPane();
  var nextTab = this.getPanes().eq(tabIndex);
  
  if (currTab.length > 0)
  {
    // 1. move the current slide out
    // 2. fade the slide's content out
    // 3. fade the new slide in
    // 4. fade the new slide's content in
    $.animating = true;
    currTab.animate({
      marginLeft: -960
    }, 1000, function()
    {
      currTab.hide().css("margin-left", 0);
      nextTab.fadeIn(1000, function()
      {
        nextTab.parent().find("#slide" + (tabIndex + 1)).fadeIn(1000, function()
        {
          done.call();
          $.animating = false;
        });
      });
    }).parent().find("#slide" + (this.getIndex() + 1)).fadeOut(1000);
  }
  else
    done.call();
});

$(window).load(function()
{
  // hide the appropriate slideshow elements
  $("img.slide").first().show();
  $("div.slide-content").first().show();
  
  // make the background image fade work in IE
  if (!$.support.cssFloat)
  {
    $("div.slide-content[id]").each(function()
    {
      var el = $(this);
      var padding = el.css("padding-top") + " " + el.css("padding-right") + " " + el.css("padding-bottom") + " " + el.css("padding-left");
      var html = el.html();
      
      el.width(el.outerWidth()).css({
        padding: 0,
        background: "none"
      });
      el.html('<div style="padding:' + padding + '; zoom:1; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=\'scale\',src=\'/images/common/splashtext-background.png\');">' + html + '</div>');
    });
  }
  
  // create a global property to keep the slideshow animation in sync
  $.extend({
    animating: false
  });
  
  // initialize the slideshow
  var slides = $("ul.slides").tabs("img.slide", {
    effect: "myEffect",
    rotate: true
  }).slideshow({
    autoplay: true,
    clickable: false,
    interval: $("div.slide-content[id]").length > 0 ? 7000 : 4000
  });
  
  // initialize the slideshow's next button
  $("div.slide-controls a.next").click(function()
  {
    if (!$.animating) slides.data("tabs").next();
    return false;
  });
  
  // initialize the slideshow's pause button
  $("div.slide-controls a.pause").click(function()
  {
    slides.data("slideshow").stop();
    return false;
  });
  
  // initialize the slideshow's play button
  $("div.slide-controls a.play").click(function()
  {
    slides.data("slideshow").play();
    return false;
  });
  
  // initialize the slideshow's previous button
  $("div.slide-controls a.prev").click(function()
  {
    if (!$.animating) slides.data("tabs").prev();
    return false;
  });
  
  // initialize the timers for hiding and showing the slideshow controls
  /*var controls = $("div.slide-controls");
  controls.data("showTimer", null);
  controls.data("hideTimer", null);
  
  $("#splash").hover(function()
  {
    clearTimeout(controls.data("showTimer"));
    clearTimeout(controls.data("hideTimer"));
    
    // show the slideshow controls
    controls.data("showTimer", setTimeout(function()
    {
      controls.fadeIn(250);
    }, 250));
  }, function()
  {
    clearTimeout(controls.data("showTimer"));
    clearTimeout(controls.data("hideTimer"));
    
    // hide the slideshow controls
    controls.data("hideTimer", setTimeout(function()
    {
      controls.fadeOut(250);
    }, 500));
  });*/
});
