$(document).ready(function(){
	var dn = new Date();
	var ds = new Date(parseInt(date[0]), parseInt(date[1]) - 1, parseInt(date[2]), dn.getHours(), dn.getMinutes(), dn.getSeconds());

	//image-size
	img_width = 228;
	img_height = 228;
	//img_height = Math.floor((img_width / 3) * 4);

	var diff = Math.round((ds.getTime() - dn.getTime()) / 86400000);

	//week
	var week = 0;
	if(diff < 0){
		diff = Math.abs(diff);
		week = Math.floor(diff / 7);
	}

	start = week * turn;
	end = start + turn;

	//alert(sprintf("%04d", start));
	$("#genki_start").html(sprintf("%04s", start + 1));
	$("#genki_end").html(sprintf("%04s", end));

	var min = dn.getMinutes();
	var sec = dn.getSeconds();

	/* 30 */
		//if(min > 30){
		//	min = min - 30;
		//}
		//image = start + min + 1;
	/* 15 */
		if(min >= 15){
			while(min >= 15){
				min = min - 15;
			}
		}
		image = start + min + 1;
	/* 50 */
		//var cycle = (60 / turn) * 60;
		//var SEC = min * 60 + sec;
		//var id = Math.floor((SEC / cycle)) + 1;
		//var next = id * cycle;
		//image = start + id;

	/* 60 */
		//image = start + min + 1;

	getImage(image);
	image++;

	//init-timer
	$.timer(((60 - sec) * 1000), function(init){
		getImage(image);
		image++;
		$.timer(60000, function(timer){
			getImage(image);
			image++;
			if(image > end) image = start + 1;
		});
		init.stop();
	});
});

function getImage(image){
	$("#genki_box").hide("fade", {}, 200, function(){
		$("#genki_load").show("fade", {}, 0, function(){
			$.getJSON("/?kids&id=" + image, function(res){
				$("#genki_photo img").attr("src", res.image);
				$("#genki_id").html(res.id)
				$("#genki_label").html(res.label);
				$("#genki_age").html(res.age)
				$("#genki_dream").html(res.dream);

				$("#genki_load").hide("fade", {}, 0, function(){
					setScroller();
					$("#genki_box").show("fade", {}, 1000);
				});
			});
		});
	});
}

function setScroller(){
	/*if(document.getElementById("clock")) return;
	$("#items").css({"width": width - 40});
	$("#item-name").prepend("なまえ：");
	$("#item-age").prepend("年令：");
	$("#item-dream").prepend("将来のゆめ：");
	$("#items").marquee({scrollSpeed: 12});
	$("#image img").wrap('<a href="http://kids.hughug-web.com" target="_parent"></a>');*/
	$("#genki_photo img").wrap('<a href="http://kids.hughug-web.com"></a>');

}
