/*===================================
 * js file for "(株)コタム"
 * file name : control.js
 * description : OPアニメーション処理
 * author : Koji Tamura
===================================== */

$(function(){
	/* 初回閲覧時の判断処理 */
	var dateFormat = new DateFormat("HH");
	var dateStr = dateFormat.format(new Date()); // Date(現在時刻)をStringに変換
	//var dateStr = "Cookie test用";
	
	if($.cookie("access") != dateStr){
		oneAnimate();
		ImgOvAnimeSlideTop();
		$.cookie("access",dateStr);
		//window.alert(dateStr);
	}else{
		/*test用*/
		/*
		oneAnimate();
		ImgOvAnimeSlideTop();
		*/
		
		$("#glayLayer").hide();
		$("#overLayer").hide();
		
	}
});

function oneAnimate(){
	//$("#container").append("<div id='glayLayer'></div>");
	//$("#container").append("<div id='overLayer'><img class='rollover' src='images/logo_OP.png'  width='81' height='199' /></div>");
	var toppos = $("div#header h1").position().top;
	var leftpos = $("div#logoWrap").position().left + $("div#header h1").position().left;
	$("#logoWrap h1").hide(0);
	$("#nav").hide(0);
	$("#contentsWrap").hide(0);
	//$("#gridWrap").hide(0);
	//$("p#mainslider img").hide(0);
	//$("#pagetop").hide(0);
	
	$("#overLayer").click(function(){
		//window.alert("click");
	});
	
	setTimeout("animate()", 2000);
}//Eo oneAnimate();

/*各コンテンツのアニメーション関数*/
function animate(){
	$("#glayLayer").fadeOut(3000);
	
	$("#overLayer").animate({opacity:0.0},
	{
		duration:1000,
		easing:"linear",
		queue:false,
		complete:function(e){
			$("#overLayer").hide(0);
			$("#logoWrap h1").show(1500);
			
			$("#nav").slideDown(800, function(e){
				$("#contentsWrap").slideDown(1000,'easeInExpo');
				});
			}
	});
}//Eo animate();


/*擬似ローディングバー関数*/
function ImgOvAnimeSlideTop(){
	var OvClass = "loading",
	OvStr = "_ov", //ロールオーバー後の画像に追加する文字列
	OvRrap = "ovRrap",
	OvImg = "ovImg",
	Speed = 0; //アニメーションの速度

	$("img."+OvClass).each(function(){ //classがrolloverのimg要素に対しての処理

		var This = $(this),
		UrlDef = This.attr("src"),
		UrlChange = UrlDef.replace(/^(.+)(\.[a-z]+)$/,"$1"+OvStr+"$2");

		function OvElm(){
			return This.prev("span."+OvImg);
		}
		function OvElmLen(){ //ロールオーバー画像表示確認関数
			return OvElm().length;
		}
		function Width(){
			return This.width()+"px";
		}
		function Height(){
			return This.height()+"px";
		}
		
		if(!This.attr("src").match(OvStr+".")){
				if(!OvElmLen()){
					This.css({opacity:"0",position:"relative"})
					.before("<img style='position:absolute;' class='"+OvImg+"' src='"+UrlDef+"' alt='' />")
					.before("<span style='width:"+Width()+";height:0;background-image:url("+UrlChange+");position:absolute;' class='"+OvImg+"'></span>");
				}
				OvElm().stop().animate({height:Height()},
					{
						duration:Speed,
						complete:function(e){
							/*callback*/
							OvElm().animate({height:"0"},Speed+2500,"easeOutQuart",function(){
								This.css({opacity:"1",position:"static"})
								.prevAll("."+OvImg).remove();
							});
						}
					}
				);
		}
	});//Eo .each function

}//Eo ImgOvAnimeSlideTop();
