Код:
var dInt="";
function init(duration) {
var i = -1;
startplay(duration,i);
}
function startplay(duration,i) {
i++;
window.clearInterval(dInt);
switch(i) {
case 0:
$('.container .img').fadeOut(300,function(){
$('.container .img').css('background','url("/images/image-1.jpg") no-repeat');
$('.container .img').fadeIn(300,function(){dInt=setInterval(function(){startplay(duration,i);}, duration);});
});
break;
case 1:
$('.container .img').fadeOut(300,function(){
$('.container .img').css('background','url("/images/image-2.jpg") no-repeat');
$('.container .img').fadeIn(300,function(){dInt=setInterval(function(){startplay(duration,i);}, duration);});
});
break;
case 2:
$('.container .img').fadeOut(300,function(){
$('.container .img').css('background','url("/images/image-3.jpg") no-repeat');
$('.container .img').fadeIn(300,function(){dInt=setInterval(function(){startplay(duration,i);}, duration);});
});
break;
case 3:
init(duration);
break;
}
}
$(document).ready(function()
{
$("button#button1").click(function(){$(this).blur();startplay(5000,-1);});
$("button#button2").click(function(){$(this).blur();startplay(5000,0);});
$("button#button3").click(function(){$(this).blur();startplay(5000,1);});
});
window.onload = init(5000);