$(document).ready(function(){ firstSlider(); function firstSlider() { var set_time = 8000; function line_animation() { $('.slide-ul li.active_n .time-bloks-line').animate({width:'100%'}, set_time, function() { $(this).css({width:0}); }); } line_animation(); function for_interval() { var slide_active = $('.slide-ul').find('li.active_n'); slide_active.removeClass('active_n'); slide_active.next().addClass('active_n'); var lengs = $('.slide-ul li').index($('li.active_n')); if (lengs == -1){ $('.slide-ul li:first-child').addClass('active_n') } var img_bg = $('.slide-ul li.active_n').find('img'); img_bg = img_bg.attr('src').split('/'); img_bg = img_bg[img_bg.length - 1]; if (device.mobile() || device.tablet()){ $('.slider-bg').attr('style', 'background-image: url("images/slider/big-' + img_bg + '")'); } else { $('.slider-bg').attr('style', 'background-image: url("images/slider/big-' + img_bg + '")'); } line_animation(); } var stop_interval = setInterval(function(){ for_interval() },set_time); $('.slide-ul li').click(function(){ $('.slide-ul li.active_n .time-bloks-line').stop().css({width:0}); $('.slide-ul li').removeClass('active_n'); $(this).addClass('active_n'); var img_bg = $('.slide-ul li.active_n').find('img'); img_bg = img_bg.attr('src').split('/'); img_bg = img_bg[img_bg.length - 1]; if (device.mobile() || device.tablet()){ $('.slider-bg').attr('style', 'background-image: url("images/slider/big-' + img_bg + '")'); } else { $('.slider-bg').attr('style', 'background-image: url("images/slider/big-' + img_bg + '")'); } clearInterval(stop_interval); stop_interval = setInterval(function(){ for_interval() },set_time); line_animation(); }); } });