var s = new Slider(); s.interval = 4500; var sliderInterval; function Slider() { this.speed = 500; this.interval = 1800; this.obj; this.Slide = function() { id = $(this.obj).html(); //alert(id); if (!$(this.obj).hasClass('active')) { $('#counter label.active').removeClass('active'); $(this.obj).addClass('active'); $('#slider .item.active').removeClass('active').fadeOut(this.speed); $('#slide-'+id).addClass('active').fadeIn(this.speed); } } this.autoSlide = function() { this.obj = $('#slider #counter li label.active').parent().next('li').children('label'); if ($(this.obj).html()) { this.Slide(); } else { this.obj = $('#slider #counter li:first label'); this.Slide(); } } } $(document).ready(function() { s.autoSlide(); sliderInterval = setInterval('s.autoSlide()',s.interval); $('#counter label').click(function() { clearInterval(sliderInterval); s.obj = this; s.Slide(); }); })