$(document).ready(function(){

	// **************************************************
	// 初期設定
	$(function(){

		$("#idHeader").append("<div id='idSlideshow'></div><div id='idSlideshow_wrap'></div>");
		$("#idHeaderS").append("<div id='idSlideshow'></div><div id='idSlideshow_wrap'></div>");

		$("#idMenu1").append("<div id='idCursor1'></div>");
		$("#idMenu2").append("<div id='idCursor2'></div>");
		$("#idMenu2").append("<div id='idCursor3'></div>");
		$("#idMenu2").append("<div id='idCursor4'></div>");

		$(".clsMenuBtn1, .clsMenuBtn2, .clsMenuBtn3, .clsMenuBtn4").css("background","none");

		MoveCursor("#idCursor1", "#idMenuDefault1");
		MoveCursor("#idCursor2", "#idMenuDefault2");

		$("#idSlideshow_wrap").animate({opacity:0}, {duration:0});
	});

	// **************************************************
	var xx;
	ranimg = new Array();
	params = new Array();
	ranimg[0]="http://to-r-m.hp.infoseek.co.jp/pic/top1.jpg"; params[0]="#ff0000";
	ranimg[1]="http://to-r-m.hp.infoseek.co.jp/pic/top2.jpg"; params[1]="#ff0000";
	ranimg[2]="http://to-r-m.hp.infoseek.co.jp/pic/top3.jpg"; params[2]="#ffffff";
	ranimg[3]="http://to-r-m.hp.infoseek.co.jp/pic/top4.jpg"; params[3]="#ffffff";
	ranimg[4]="http://to-r-m.hp.infoseek.co.jp/pic/top5.jpg"; params[4]="#ff0000";
	ranimg[5]="http://to-r-m.hp.infoseek.co.jp/pic/top6.jpg"; params[5]="#ffffff";
	ranimg[6]="http://to-r-m.hp.infoseek.co.jp/pic/top7.jpg"; params[6]="#000000";
	ranimg[8]="http://to-r-m.hp.infoseek.co.jp/pic/top8.jpg"; params[7]="#000000";
	ranimg[9]="http://to-r-m.hp.infoseek.co.jp/pic/top9.jpg"; params[8]="#ffffff";
	ranimg[11]="http://to-r-m.hp.infoseek.co.jp/pic/top10.jpg"; params[9]="#ffffff";
	ranimg[12]="http://to-r-m.hp.infoseek.co.jp/pic/top12.jpg"; params[10]="#ff0000";
	xx = Math.floor(ranimg.length * Math.random());

	// スライドショー処理
	function timer1(){
		//imageURL設定
		xx = Math.floor(ranimg.length * Math.random());
		
		//ラッパー画像切り替え
		$("#idSlideshow_wrap").css("background-image","url('" + ranimg[Math.floor(xx)] + "')");

		//ラッパー フェイド・イン
		$("#idSlideshow_wrap").animate({opacity:1}, {duration:1000, easing:"linear", complete:function(){timer2();}});

		//タイトル文字色変更
		$(".clsTitleText1").animate({color:params[Math.floor(xx)]}, {duration:1000});
		$(".clsTitleText2").animate({color:params[Math.floor(xx)]}, {duration:1000});
	};
	function timer2(){
		//元画像切り替え
		$("#idSlideshow").css("background-image","url('" + ranimg[Math.floor(xx)] + "')");

		//ラッパー フェイド・アウト
		$("#idSlideshow_wrap").animate({opacity:0}, {duration:1000, easing:"linear", complete:function(){timer3();}});
	};
	function timer3(){
		setTimeout(timer1, 9999);
	};
	timer1();
	
	// **************************************************
	// メニュー処理
	function MoveCursor(pCursor, pMoveTo){
		$(pCursor).queue([]);
		$(pCursor).stop();
		$(pCursor).animate({
			top   : $(pMoveTo).parent().position().top  + $(pMoveTo).position().top  - $(pCursor).parent().position().top,
			left  : $(pMoveTo).parent().position().left + $(pMoveTo).position().left - $(pCursor).parent().position().left,
			width : $(pMoveTo).width(),
			height: $(pMoveTo).height(),
			opacity: 0.5
		}, "fast", "easeOutBounce");
	}

	// メニューhover
	$(".clsMenuBtn1, .clsMenuBtn2, .clsMenuBtn3, .clsMenuBtn4").hover(
		function(){

			//トップページ
			if( ($(this).text() == "top/news") ||
			    ($(this).text() == "concept/profile") ||
			    ($(this).text() == "works") ||
			    ($(this).text() == "workshop") ||
			    ($(this).text() == "contact") ||
			    ($(this).text() == "link") ){
				MoveCursor("#idCursor1", this);
				MoveCursor("#idCursor2", "#idMenuDefault2");

			//ブログ・サイトマップ
			}else if( ($(this).text() == "blog 「to R mansion Journal」") ||
			          ($(this).text() == "site map") ){
				MoveCursor("#idCursor1", this);
				MoveCursor("#idCursor2", this);

			//メニュー2
			}else{
				MoveCursor("#idCursor1", "#idMenuDefault1");
				MoveCursor("#idCursor2", this);
			};
		}, 
		function(){
			MoveCursor("#idCursor1", "#idMenuDefault1");
			MoveCursor("#idCursor2", "#idMenuDefault2");
		}
	);

});
