$(function(){
	preLoad([
		"bg.jpg",
		"mainTitle_u.png",
		"mainTitle_l.png",
		"liveDate.png",
		"ajaxLoader.gif",
		"close.gif",
		"next.gif",
		"prev.gif"
	], preImgs, opening);
})

var preImgs = new Array();

function preLoad(obj, preAry, callback){
	$("body").append(
		"<div class='abslt canvas' id='please_wait' style='background: black url(img/please_wait.gif) no-repeat center'></div>"
	);
	var cnt = obj.length;
	for (var i=0; i<cnt; i++){
		preAry[i] = new Image();
		preAry[i].src = "img/" + obj[i];
	}
	var chk = function(){
		var comp = 0;
		for (var i=0; i<cnt; i++){
			if (preAry[i].complete) comp++;
		}
		if (comp == cnt){
			$("#please_wait").remove();
			callback();
		}else{
			setTimeout(chk, 1000);
		}
	};
	chk();
}

function opening(){
	addBgImg();
	setTimeout("titleMv()", 1000);
	setTimeout("setNavi()", 1400);
	naviColor();
	setTimeout("healing()", 4000);
}

function addBgImg(){
	$("#toshiCanvas").css({
		background: "url(" + preImgs[0].src + ") no-repeat center"
	});
	$("#toshiCanvas").fadeTo(2800, 1.0);
}

function titleMv(){
	$("#mainTitle").fadeTo(2800, 1.0);
	$("#mainTitle_u").animate({
		left: "0px"
		}, 2800, "easeOutCirc"
	);
	$("#mainTitle_l").animate({
		left: "0px"
		}, 2800, "easeOutCirc"
	);
	$("#liveDate").animate({
		left: "0px"
		}, 2800, "easeOutCirc"
	);
	$("#backTitle").fadeTo(2800, 0.6);
}

function naviMv(n){
	var y = $("#navi_" + n).css("top");
	var h = y.substring(0, (y.length) - 2) - 100;
	$("#navi_"+ n).animate({
		top: h + "px", opacity: 1.0, mozOpacity: 1.0, filter: "alpha(opacity=100)"
		}, 4000, "easeInOutCirc"
	);
}

function setNavi(){
	var num = 0;
	$.timer(400, function(tm){
		naviMv(num);
		num++;
		if (num > 8){ 
			tm.stop();
			return;
		}
	});
}

function naviColor(){
	$(".jap").mouseover(function(){
		$(this).css({color: "#ffffff", fontWeight: "bold"});
		$(this).prev().children().css({color: "#ffffcc", opacity: 1.0, mozOpacity: 1.0, filter: "alpha(opacity=100)"});
	});
	$(".eng").mouseover(function(){
		$(this).css({color: "#ffffcc", opacity: 1.0, mozOpacity: 1.0, filter: "alpha(opacity=100)"});
		$(this).parent().next().css({color: "#ffffff", fontWeight: "bold"});
	});
	$(".jap").mouseout(function(){
		$(this).css({color: "#dbdbff", fontWeight: "normal"});
		$(this).prev().children().css({color: "#cccc77", opacity: 0.4, mozOpacity: 0.4, filter: "alpha(opacity=40)"});
	});
	$(".eng").mouseout(function(){
		$(this).css({color: "#cccc77", opacity: 0.4, mozOpacity: 0.4, filter: "alpha(opacity=40)"});
		$(this).parent().next().css({color: "#dbdbff", fontWeight: "normal"});
	});
}

function healing(){
	$("#heal").fadeTo(8000, 0.8);
	$("#heal").colorBlend([{
		param: "color",
		random: true,
		duration: 4000
	}]);
}

