$(function() { function rnd(n){ return Math.floor(Math.random()*(n+1)); } function window_resize() { var window_height = window.innerHeight ? window.innerHeight: $(window).height(); var window_width = $(window).width(); var window_ratio = window_height / window_width; if( $("#container #index > div.slide")[0] ){ $("#container #index > div.slide > div.img > img").each(function(){ $(this).imagesLoaded(function(){ $(this).addClass("loaded"); var img_ratio = $(this).height() / $(this).width(); $(this).parent().removeClass("horizontal vertical"); if( window_ratio < img_ratio ){ $(this).parent().addClass("vertical"); }else{ $(this).parent().addClass("horizontal"); } }); }); } } function slide_start(target_wrapper) { window_resize(); var max_num = target_wrapper.children("div.img").length; target_wrapper.children("div.img").eq(rnd(max_num-1)).addClass("active"); if( typeof timerId_slide != "undefined" ){ clearInterval(timerId_slide); } timerId_slide = setInterval(function(){ if( max_num > 1 ){ var past_target = target_wrapper.children("div.img.active"); past_target.removeClass("active"); var next_target = ""; if( past_target.next("div.img")[0] ){ next_target = past_target.next("div.img"); }else{ next_target = target_wrapper.children("div.img").first(); } next_target.addClass("active"); }else{ clearInterval(timerId_slide); } },15000); } slide_start( $("#container #index > div.slide") ); });