$(function() {
  var btn    = $("#btn li");
  var img    = $("#images img");
  var count  = 1;
  var images = 4;
  var time   = 7000;
  $("#images img:not(:first)").hide();
  btn.click(function() {
    if (count != btn.index(this) + 1 && !(count == 0 && images == btn.index(this) + 1)) {
      count = btn.index(this);
      img.css('z-index', 0);
      img.eq(count).css('z-index', 1);
      img.fadeOut("slow");
      img.eq(count).fadeIn("slow");
      btn.removeClass();
      $(this).addClass('active');
      count++;
      if (count == images) {
        count = 0;
      }
    }
  });
  btn.mouseup(function() {
    clearInterval(timerID);
    timerID = setInterval(function() {
      btn.eq(count).click();
    }, time);
  });
  timerID = setInterval(function() {
    btn.eq(count).click();
  }, time);
});

