(function($) { 
jQuery.fn.SlideViewer = function(options) {
 var defaults = {  
    width: 835,  
    scrollInterval: 5000,
    slideSpeed:1500,
    autoscroll:true
   };  
   var options = $.extend(defaults, options); 
    
    return this.find("ul").each(function(){
       if ($(this).attr("class") =="buttons")
       {
         var count = $(".buttons li").size();
         //$(this).parent().attr("style", "width:" + (options.width * count) + 20 + "px")
         var slideShow;
         if (options.autoscroll == true)
         {
            slideShow = setInterval('autoScroll(' + options.width + ', ' + options.slideSpeed + ' )',options.scrollInterval);
         }
         //pause
         $(this).parent().find(".pause").click(function(){
           clearInterval(slideShow);
         });
         //restart
         $(this).parent().find(".restart").click(function(){
           slideShow = setInterval('autoScroll(' + options.width + ', ' + options.slideSpeed + ' )',options.scrollInterval);
         });
         //button clicks
         $(this).find("li").click(function(){
            clearInterval(slideShow);
            $(this).parent().find("li").each(function(){
              $(this).attr("class", "")
            });
            $(this).attr("class", "on")
            var index = $("ul.buttons li").index(this);
            var moveLeft = -(options.width * index)
            $(this).parent().parent().find("ul.image").animate({left: moveLeft + 'px'}, options.slideSpeed)
            if (options.autoscroll == true)
            {
            slideShow = setInterval('autoScroll(' + options.width + ', ' + options.slideSpeed + ' )',options.scrollInterval);
            }
         });
       }
    });
    };
})(jQuery); 
function autoScroll(width, slideSpeed)
{
    var activeButton = $("ul.buttons").find("li.on");
    var index = $(".buttons li").index(activeButton );
    var count = $(".buttons li").size();
    if (index == (count -1))
      index = -1;
    index = index + 1;
    var moveLeft = -(width * index)
    $("ul.buttons").find("li").each(function(){
      if ($("ul.buttons li").index(this) == index)
      {
        $(this).attr("class", "on")
      }
      else
      {
        $(this).attr("class", "")
      }
    });
    $("ul.image").animate({left: moveLeft + 'px'}, slideSpeed)
}

