var image_num = 5;
var image_object = new Array();
var count = 0;

/* ready
----------------------------------------------- */
$(function() {

	for (var i = 0; i < image_num; i++) {
		var img = $(document.createElement("img"));
		img.attr({ src:"common/home/image" + i + ".jpg" });
		image_object[i] = img;
	}

	$(window).bind("load", loadComplete);

});

/* loadComplete
----------------------------------------------- */
function loadComplete() {
	$(window).unbind("load", loadComplete);	
	setTimeout(slideshow, 5000);
}

/* slideshow
----------------------------------------------- */
function slideshow() {

	clearTimeout();

	count++;
	
	if (count >= image_num) {
		return false;
	}

	$("#images img").animate({ opacity:0 }, 1000, "easeInOutSine", function() {
	
		$(this).remove();

		var new_image = $("#images p").append(image_object[count]);
		$("#images img").css({ opacity:0 });
		$("#images img").delay(1000).animate({ opacity:1 }, 3000, "easeInSine", function() {
			setTimeout(slideshow, 5000);
		});
	});
}

