/**
  Copyright 2009 Tetrahex Syndicate <sam@ttx-syndicate.com> All rights reserved.
*/
(function($) { $(document).ready(function() {
    
    // Stretch the slider in width to be the sum of all image widths
    var current_scene = 0;
    var width_sum = 0;
    var user_alive = false;
    var scenes = $([0]);
    $(".slider img").each(function() {
      width_sum = width_sum + $(this).width();
      scenes.push(width_sum);
    });
    $(".slider").width(width_sum);
    
    // Monitor the left/right paddles and move the slider
    $("#left_wing a, #right_wing a").click(function(event) {
      event.preventDefault();
      this.blur();
      var direction = (($(this).parent().attr("id") == "left_wing") ? -1 : 1);
      current_scene = ((current_scene + direction) >= 0 ?
        ((current_scene + direction) >= (scenes.length - 1) ? 0 : (current_scene + direction))
        : (scenes.length - 2));
      $(".slider").animate({
        left: (scenes[current_scene]*-1) + 'px',
        easing: 'swing'
      }, 1500);
      user_alive = true;
    });
    
    // Now automatically scroll the images if the user doesn't take control
    var auto_scroll = null;
    auto_scroll = setInterval(function() {
      if(user_alive) { clearInterval(auto_scroll); return; }
      $("#right_wing a").click();
      user_alive = false;
    }, 5000);

}); })(jQuery);