$(function() {
	
	//サムネイルの回転　"#eventArticle article"であれば回転する
	(function (){
	$("#eventArticle article").each(
	function (){
		var degree = Math.ceil(Math.random()*10)-5;
		$(this).css("-webkit-transform","rotate("+degree+"deg)");
		$(this).css("-o-transform","rotate("+degree+"deg)");
		$(this).css("-moz-transform","rotate("+degree+"deg)");
		}
	)
	})();

	//bodyチェック
	/*checkBodyClass();*/
	
	//フォームの体裁
	formAppearance();
	
	//visualHead
	(function headVisual(cn){
		var entryObj = [];
		var currentTime = 0, totalTime = 0, timerId=null;
		var lastn = 5;
		
		var loopDisplay = function (){
					var newImg = new Image();
						//console.log($(entryObj[currentTime][1]).text());
					newImg.src = "/headvisual/img/"+$(entryObj[currentTime][1]).text(); //load Image
					newImg.onload = function (){
						//Display
						$("div.visualWrap p.vImg").fadeTo(300,0,function () {
							$("div.visualWrap p.vImg").empty();
							$("div.visualWrap p.vImg").append(newImg);
							$("div.visualWrap p.vImg").fadeTo(300,1,function () {
									//textChange
									$("div.visualWrap div article").fadeTo(300,0);
									$("div.visualWrap div h1").fadeTo(300,0,function (){
										$("div.visualWrap div h1").empty();
										if($(entryObj[currentTime][3]).text() != "") {
											$("div.visualWrap div h1").append("<a href='"+$(entryObj[currentTime][3]).text()+"'></a>");
											$("div.visualWrap div h1 a").text($(entryObj[currentTime][0]).text());
											$("div.visualWrap p.vImg").wrap("<a href='"+$(entryObj[currentTime][3]).text()+"'></a>")
										}else{
											$("div.visualWrap div h1").text($(entryObj[currentTime][0]).text());
										}
										$("div.visualWrap div h1").fadeTo(300,1,function (){
											$("div.visualWrap div article").fadeTo(1000, 1);
											$("div.visualWrap div article").html(entryObj[currentTime][2].firstChild.data);
												if($(entryObj[currentTime][3]).text() != "") {
													$("div.visualWrap div article").append("<p class='linkButton'><a href='"+$(entryObj[currentTime][3]).text()+"'>くわしくはこちら</a></p>");
												}
											});
										})
									//TimerStart
									timerId = setInterval(function (){
										clearInterval(timerId);
										if(totalTime-1 === currentTime) {
											currentTime = 0;
										}else{
											currentTime++;
										}
										loopDisplay();
									}, 10000);
								});
							})

						}
					};
					
		if(cn){
				$.ajax({
					url: "/headvisual/index.xml",
					cache: false,
					success: function(xml){
						$("p.vImg span.loadingBar").fadeTo(500,0,function (){
						$("p.vImg").empty();
						$("entry",xml).each(function (){
							var oneEntryArray = [];
							$(this).children().each(function (){
								oneEntryArray.push($(this).get(0));
								});
								entryObj.push(oneEntryArray);
							});
									
						//xmlLoaeded
						if(lastn<entryObj.length)totalTime = lastn;
						else totalTime = entryObj.length;
						loopDisplay();
						});
					}
				});
			//})
		};
	})($("body").hasClass("top"));
	//visualHead
	
	//logoMouseOver
	$("div#logo img").hover(function (){$(this).fadeTo(100,0.5);},function (){$(this).fadeTo(100,1);})
	
    $('input[title]').each(function() {
        if($(this).val() === '') {
            $(this).val($(this).attr('title'));
        }
          
        $(this).focus(function() {
            if($(this).val() == $(this).attr('title')) {
                $(this).val('').addClass('focused');
            }
        });
        $(this).blur(function() {
            if($(this).val() === '') {
                $(this).val($(this).attr('title')).removeClass('focused');
            }
        });
    });
});


/*function jumpToTop() {
	// logoClick 親階層のDOMに行くためparent
	window.parent.location.href = "/";
}*/


/*function checkBodyClass () {
	var bodyClassName = $("body").attr("class");
	if (bodyClassName == "top" || bodyClassName == "archive") {
		}else if(bodyClassName == "entry"){
		$("div.visualWrap").css("display", "none");
		$("div#logo").css("padding-bottom", "30px");
	}
	var photo = document.getElementById("eventArticle").getElementsByTagName("article");
	for (var i=0; i<photo.length; i++) {
		var degree = Math.ceil(Math.random()*10)-5;
		photo[i].style.WebkitTransform = "rotate("+degree+"deg)";
		photo[i].style.MozTransform = "rotate("+degree+"deg)";
	}
}*/


function formAppearance() {
	var cssPropValue = {"border-radius":"3px", "border":"1px solid #ccc", "font-size":"18px", "color":"#666", "height": "24px"};
	$("form#contactFormID input:text, form#contactFormID textarea").css(cssPropValue);
	$("form#contactFormID input:text, form#contactFormID textarea").focus(inputForcus);
	$("form#contactFormID input:text, form#contactFormID textarea").blur(inputBlur);
	$("div#errorMsg").hide();
}

function inputForcus() {
	$(this).css("background-position", "right bottom");
}

function inputBlur() {
	if($(this).attr("value") != "") {
	$(this).css("background-position", "center");
	}
}

function contactFormCheck () {
	var alertMgs = "";
	if($("#contactFormID input.name").attr("value") =="") {
		alertMgs +="お名前を入力してください。<br>";
	}
	
	if($("#contactFormID input.mail").attr("value") =="") {
		alertMgs +="メールアドレスを入力してください。<br>";
	}
	
	if($("#contactFormID textarea.msg").attr("value") =="") {
		alertMgs +="お問い合わせ内容を入力してください。<br>";
	}
	
	if($("#contactFormID input.kwd").attr("value") =="") {
		alertMgs +="『○○○ Nite in OSAKA』　○○○に入る3文字のアルファベットを入力して下さい。";
	}
	
	if(alertMgs != "") {
		$("#errorMsg").html(alertMgs);
		$("div#errorMsg").show(300);
		return false;
	}else{
		return true;
	}
	
}




































