var current_index = 0; var interval = 5; //seconds var duration = 750; var timerID = 0; jQuery(document).ready(function(){ if (typeof(images) != "undefined") { jQuery('#next_image').attr('src', images[nextIndex()]); jQuery('#current_image').attr('src', images[current_index]); setTimeout(function() { doTransition( nextIndex() ); }, interval*1000); fixRotatingImages(); } }); function nextIndex() { return (current_index==max_index) ? 0 : current_index+1; } function doTransition(newid) { jQuery('#next_image').attr( 'src', images[newid] ); jQuery('#current_image').fadeTo( duration, 0, function(){ jQuery(this).attr( 'src', images[current_index] ).fadeTo(duration, 1); }); current_index = newid; setTimeout(function() { doTransition( nextIndex() ); }, interval*1000); } function fixRotatingImages(){ jQuery('#rotating_images').css('height',jQuery('#rotating_images').width()+"px"); jQuery('#rotating_images img').css('height',jQuery('#rotating_images img').width()+"px"); } jQuery(window).resize(function(){ fixRotatingImages(); });