﻿var arrayId = new Array();

function showRandomOnLoad(){		
	$("div.random-images").each(function(index){
		arrayId.push($(this).attr('id'));
	});

	for(var i=0;i<arrayId.length;i++){
		var id = arrayId[i];
		var $first = $("#"+id).children("div.single-image:eq(0)")
		$first.addClass("img-active");
		if($("#"+id).children("div.single-image").size() > 1){
			setInterval("showRandom('"+id+"')", Math.floor(Math.random()*10000)+3000);
		}
	}
}

function showRandom(id){
	var $active = $("#"+id).children("div.img-active");
	var size = $("#"+id).children("div.single-image").size();
	var value = Math.floor(Math.random()*(size - 1));
	var $next = $("#"+id).children("div.single-image:eq("+ value +")");
	
	$active.addClass('img-last-active');
	$next.css({opacity: 0.0});
	$next.addClass('img-active');
	$next.animate({opacity: 1.0}, 2000, function() {
		$active.removeClass('img-active img-last-active');
	});
}
