// to make images rotate, supply their names as arguments e.g.
// rotate2("03", "04", "05"); 
// rotate2("short1", "short2", "short3", "short4", "short5");
// the assuption is the files have .jpg extension

function rotate2() {
	// copy arguments for recursive call later
	a = [];
	for (i = 0; i < arguments.length; i++) {
		a.push(arguments[i]);
	}
	
	var images = new Array();
	var r = Math.floor(Math.random() * arguments.length);
	
	
	// pick 3 images
	for (i = 0; i < 3; i++) {
		while (arguments[r] == 0) {
			r = Math.floor(Math.random() * arguments.length);
		}
		images[i] = arguments[r];
		arguments[r] = 0;
	}
	
	//replace image and background-image of the container div
	$("#rotation div").each(
		function(i) {
			$(this).css("background-image", "url('images/short/" + images[i] + ".jpg')");
			$(this).find("img").fadeOut(2000, function() {
				// path and extension of rotation images
				$(this).attr("src", "images/short/" + images[i] + ".jpg").show();
			});
		}
	);
	
	// call rotate2() again with the same arguments (saved in a)
	setTimeout(function() {rotate2.apply(this, a)}, 4000); 
	
}

