/* Set */
var setFlash = new Array (7);
	setFlash[0] = "menu01";
	setFlash[1] = "menu02";
	setFlash[2] = "menu03";
	setFlash[3] = "menu04";
	setFlash[4] = "menu05";
	setFlash[5] = "menu06";
	setFlash[6] = "menu07";
for ( i=0; i < setFlash.length; i++) {
	var FlashId = setFlash[i];
	var setId = setFlash[i];
	FlashId = (navigator.appName.indexOf("Microsoft") != -1) ? setId : window.document.setId;
}

var MenuFlag;

var CookieColor = $.cookie('setColor');


/* Set Color function */

function setColorC() { 
	for ( i=0; i < setFlash.length; i++) {
		this._flv = window.document.getElementById(setFlash[i]);
		this._flv.SetVariable("_level0.app", 1);
	}
}
function setColorM() { 
	for ( i=0; i < setFlash.length; i++) {
		this._flv = window.document.getElementById(setFlash[i]);
		this._flv.SetVariable("_level0.app", 2);
	}
}
function setColorY() { 
	for ( i=0; i < setFlash.length; i++) {
		this._flv = window.document.getElementById(setFlash[i]);
		this._flv.SetVariable("_level0.app", 3);
	}
}
function setColorK() { 
	for ( i=0; i < setFlash.length; i++) {
		this._flv = window.document.getElementById(setFlash[i]);
		this._flv.SetVariable("_level0.app", 4);
	}
}

function pageload(hash) {
/*
	$("#Works .TopContents").load(/works/);
	$("#News .BlogWrap").load(/news/);
	$("#Basket .BlogWrap").load(/basket/);
	$("#Komimi .BlogWrap").load(/komimi/);
	var str;
	var hash = (hash)? hash : location.hash.replace(/^.*#/, ''); 
	str = hash.split("/");
	if (str[1] == "profile") {
		$("#Profile .TopContents").load(hash);
	} else if (str[1] == "works") {
		$("#Works .TopContents").load(hash);
	} else if (str[1] == "news") {
		$("#News .BlogWrap").load(hash);
	} else if (str[1] == "inquiry") {
		$("#Inquiry .TopContents").load(hash);
	} else if (str[1] == "basket") {
		$("#Basket .BlogWrap").load(hash);
	} else if (str[1] == "komimi") {
		$("#Komimi .BlogWrap").load(hash);
	}
*/
}

/* GoogleMap */
function initialize() {
	var centerPos = new google.maps.LatLng(35.676813,139.70589);
	var mapOptions = {
		zoom : 16,
		center : centerPos,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
	var markerOptions = {
		position : centerPos,
		map : map,
		title : ""
	};
	var marker = new google.maps.Marker(markerOptions);
//	clearTimeout();
}
	function GMA() {
		$("#Inquiry .Map #IF").replaceWith('<div id="IF" style="width:450px; height:300px;"><iframe width="450" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.jp/maps?f=q&amp;source=s_q&amp;hl=&amp;geocode=&amp;q=%E6%9D%B1%E4%BA%AC%E9%83%BD%E6%B8%8B%E8%B0%B7%E5%8C%BA%E5%8D%83%E9%A7%84%E3%83%B6%E8%B0%B73-13-22&amp;sll=35.676803,139.705882&amp;sspn=0.005325,0.009592&amp;brcurrent=3,0x60188cb937ebb9a1:0x114012b6a5a1444e,0,0x60188cb9258f74b3:0x2a267b595491b818&amp;ie=UTF8&amp;hq=&amp;hnear=%E6%9D%B1%E4%BA%AC%E9%83%BD%E6%B8%8B%E8%B0%B7%E5%8C%BA%E5%8D%83%E9%A7%84%E3%83%B6%E8%B0%B7%EF%BC%93%E4%B8%81%E7%9B%AE%EF%BC%91%EF%BC%93%E2%88%92%EF%BC%92%EF%BC%92&amp;ll=35.67832,139.705153&amp;spn=0.010458,0.019269&amp;z=15&amp;output=embed&amp;iwloc=B"></iframe></div>');
		clearTimeout();
	}


/* Document Ready */
$(document).ready(function () {
	var access = location.hostname;
	if (access.indexOf("www") == -1) {
		location.hostname = "www.watanabejunpei.jp"
		location.href = "http://www.watanabejunpei.jp/"
	}

	/* Set Color Reload  */

	if ( !CookieColor) {
		$("body").addClass("SetColorK");
		$('#ProfileSWF').flash({ swf: '/common/swf/k/menu01.swf',height:50,width:448,id:'menu01',name:'menu01',params: {wmode: 'transparent'} });
		$('#Profile2SWF').flash({ swf: '/common/swf/k/menu06.swf',height:50,width:448,id:'menu07',name:'menu07',params: {wmode: 'transparent'} });
		$('#WorksSWF').flash({ swf: '/common/swf/k/menu02.swf',height:50,width:448,id:'menu02',name:'menu02',params: {wmode: 'transparent'} });
		$('#NewsSWF').flash({ swf: '/common/swf/k/menu03.swf',height:50,width:448,id:'menu03',name:'menu03',params: {wmode: 'transparent'} });
		$('#InquirySWF').flash({ swf: '/common/swf/k/menu04.swf',height:50,width:448,id:'menu04',name:'menu04',params: {wmode: 'transparent'} });
		$('#BasketSWF').flash({ swf: '/common/swf/k/menu05.swf',height:50,width:448,id:'menu05',name:'menu05',params: {wmode: 'transparent'} });
		$('#KomimiSWF').flash({ swf: '/common/swf/k/komimi.swf',height:100,width:1000,id:'menu06',name:'menu06',params: {wmode: 'transparent'} });
	} else if ( CookieColor == "SetColorC" ) {
		$("body").removeAttr("class");
		$("body").addClass($.cookie('setColor'));
		$("#ColorChip").css({ "background-image":"url(/common/images/color_c.gif)" });
		$('#ProfileSWF').flash({ swf: '/common/swf/c/menu01.swf',height:50,width:448,id:'menu01',name:'menu01',params: {wmode: 'transparent'} });
		$('#Profile2SWF').flash({ swf: '/common/swf/c/menu06.swf',height:50,width:448,id:'menu07',name:'menu07',params: {wmode: 'transparent'} });
		$('#WorksSWF').flash({ swf: '/common/swf/c/menu02.swf',height:50,width:448,id:'menu02',name:'menu02',params: {wmode: 'transparent'} });
		$('#NewsSWF').flash({ swf: '/common/swf/c/menu03.swf',height:50,width:448,id:'menu03',name:'menu03',params: {wmode: 'transparent'} });
		$('#InquirySWF').flash({ swf: '/common/swf/c/menu04.swf',height:50,width:448,id:'menu04',name:'menu04',params: {wmode: 'transparent'} });
		$('#BasketSWF').flash({ swf: '/common/swf/c/menu05.swf',height:50,width:448,id:'menu05',name:'menu05',params: {wmode: 'transparent'} });
		$('#KomimiSWF').flash({ swf: '/common/swf/c/komimi.swf',height:100,width:1000,id:'menu06',name:'menu06',params: {wmode: 'transparent'} });
	} else if ( CookieColor == "SetColorM" ) {
		$("body").removeAttr("class");
		$("body").addClass($.cookie('setColor'));
		$("#ColorChip").css({ "background-image":"url(/common/images/color_m.gif)" });
		$('#ProfileSWF').flash({ swf: '/common/swf/m/menu01.swf',height:50,width:448,id:'menu01',name:'menu01',params: {wmode: 'transparent'} });
		$('#Profile2SWF').flash({ swf: '/common/swf/m/menu06.swf',height:50,width:448,id:'menu07',name:'menu07',params: {wmode: 'transparent'} });
		$('#WorksSWF').flash({ swf: '/common/swf/m/menu02.swf',height:50,width:448,id:'menu02',name:'menu02',params: {wmode: 'transparent'} });
		$('#NewsSWF').flash({ swf: '/common/swf/m/menu03.swf',height:50,width:448,id:'menu03',name:'menu03',params: {wmode: 'transparent'} });
		$('#InquirySWF').flash({ swf: '/common/swf/m/menu04.swf',height:50,width:448,id:'menu04',name:'menu04',params: {wmode: 'transparent'} });
		$('#BasketSWF').flash({ swf: '/common/swf/m/menu05.swf',height:50,width:448,id:'menu05',name:'menu05',params: {wmode: 'transparent'} });
		$('#KomimiSWF').flash({ swf: '/common/swf/m/komimi.swf',height:100,width:1000,id:'menu06',name:'menu06',params: {wmode: 'transparent'} });
	} else if ( CookieColor == "SetColorY" ) {
		$("body").removeAttr("class");
		$("body").addClass($.cookie('setColor'));
		$("#ColorChip").css({ "background-image":"url(/common/images/color_y.gif)" });
		$('#ProfileSWF').flash({ swf: '/common/swf/y/menu01.swf',height:50,width:448,id:'menu01',name:'menu01',params: {wmode: 'transparent'} });
		$('#Profile2SWF').flash({ swf: '/common/swf/y/menu06.swf',height:50,width:448,id:'menu07',name:'menu07',params: {wmode: 'transparent'} });
		$('#WorksSWF').flash({ swf: '/common/swf/y/menu02.swf',height:50,width:448,id:'menu02',name:'menu02',params: {wmode: 'transparent'} });
		$('#NewsSWF').flash({ swf: '/common/swf/y/menu03.swf',height:50,width:448,id:'menu03',name:'menu03',params: {wmode: 'transparent'} });
		$('#InquirySWF').flash({ swf: '/common/swf/y/menu04.swf',height:50,width:448,id:'menu04',name:'menu04',params: {wmode: 'transparent'} });
		$('#BasketSWF').flash({ swf: '/common/swf/y/menu05.swf',height:50,width:448,id:'menu05',name:'menu05',params: {wmode: 'transparent'} });
		$('#KomimiSWF').flash({ swf: '/common/swf/y/komimi.swf',height:100,width:1000,id:'menu06',name:'menu06',params: {wmode: 'transparent'} });
	} else {
		$("body").removeAttr("class");
		$("body").addClass($.cookie('setColor'));
		$("#ColorChip").css({ "background-image":"url(/common/images/color_bk.gif)" });
		$('#ProfileSWF').flash({ swf: '/common/swf/k/menu01.swf',height:50,width:448,id:'menu01',name:'menu01',params: {wmode: 'transparent'} });
		$('#Profile2SWF').flash({ swf: '/common/swf/k/menu06.swf',height:50,width:448,id:'menu07',name:'menu07',params: {wmode: 'transparent'} });
		$('#WorksSWF').flash({ swf: '/common/swf/k/menu02.swf',height:50,width:448,id:'menu02',name:'menu02',params: {wmode: 'transparent'} });
		$('#NewsSWF').flash({ swf: '/common/swf/k/menu03.swf',height:50,width:448,id:'menu03',name:'menu03',params: {wmode: 'transparent'} });
		$('#InquirySWF').flash({ swf: '/common/swf/k/menu04.swf',height:50,width:448,id:'menu04',name:'menu04',params: {wmode: 'transparent'} });
		$('#BasketSWF').flash({ swf: '/common/swf/k/menu05.swf',height:50,width:448,id:'menu05',name:'menu05',params: {wmode: 'transparent'} });
		$('#KomimiSWF').flash({ swf: '/common/swf/k/komimi.swf',height:100,width:1000,id:'menu06',name:'menu06',params: {wmode: 'transparent'} });
	};
	
/* SWF object

	$('#ProfileSWF').flash({ swf: '/common/swf/menu01.swf',height:50,width:448,id:'menu01',name:'menu01',params: {wmode: 'transparent'} });
	$('#WorksSWF').flash({ swf: '/common/swf/menu02.swf',height:50,width:448,id:'menu02',name:'menu02',params: {wmode: 'transparent'} });
	$('#NewsSWF').flash({ swf: '/common/swf/menu03.swf',height:50,width:448,id:'menu03',name:'menu03',params: {wmode: 'transparent'} });
	$('#InquirySWF').flash({ swf: '/common/swf/menu04.swf',height:50,width:448,id:'menu04',name:'menu04',params: {wmode: 'transparent'} });
	$('#BasketSWF').flash({ swf: '/common/swf/menu05.swf',height:50,width:448,id:'menu05',name:'menu05',params: {wmode: 'transparent'} });
	$('#KomimiSWF').flash({ swf: '/common/swf/komimi.swf',height:100,width:1000,id:'komimi',name:'komimi',params: {wmode: 'transparent'} });
 */


	/* Ajax.history */
	$.historyInit(pageload, "jquery_history.html", "");
		
	$("dt[rel='history']").click(function(){
		var hash = this.id;
		hash = hash.replace(/^.*#/, '');
		var toggle = location.hash;
		var path = location.pathname;
	
	var host = "http://" + location.hostname + "/";
	var str = hash.split("/");

	if ((jQuery.browser.msie) && (jQuery.browser.version < 8)) {
		toggle = location.search;
	}
//	alert("path="+ path +" - toggle="+ toggle +" - str[1]="+str[1]);

	if (str[1] == "profile") {
		if(toggle.indexOf("TopMenu=0")!=-1){
			location.hash = "#";
		} else {
			if (path.indexOf("profile")!=-1) {
				location.hash = "#";
			} else {
				search = "?TopMenu=0";
				$.historyLoad(hash,search,host);
			}
		}
	} else if (str[1] == "profile2") {
		if(toggle.indexOf("TopMenu=1")!=-1){
			location.hash = "#";
		} else {
			if (path.indexOf("profile2")!=-1) {
				location.hash = "#";
			} else {
				search = "?TopMenu=1";
				$.historyLoad(hash,search,host);
			}
		}
	} else if (str[1] == "works") {
		if(toggle.indexOf("TopMenu=2")!=-1){
			location.hash = "#";
		} else {
			if (path.indexOf("works")!=-1) {
				location.hash = "#";
			} else {
				search = "?TopMenu=2";
				$.historyLoad(hash,search,host);
			}
		}
	} else if (str[1] == "news") {
		if(toggle.indexOf("TopMenu=3")!=-1){
			location.hash = "#";
		} else {
			if (path.indexOf("news")!=-1) {
				location.hash = "#";
			} else {
				search = "?TopMenu=3";
				$.historyLoad(hash,search,host);
			}
		}
	} else if (str[1] == "inquiry") {
		if(toggle.indexOf("TopMenu=4")!=-1){
			location.hash = "#";
		} else {
			if (path.indexOf("inquiry")!=-1) {
				location.hash = "#";
			} else {
				search = "?TopMenu=4";
				$.historyLoad(hash,search,host);
			}
		}
	} else if (str[1] == "basket") {
		if(toggle.indexOf("TopMenu=5")!=-1){
			location.hash = "#";
		} else {
			if (path.indexOf("basket")!=-1) {
				location.hash = "#";
			} else {
				search = "?TopMenu=5";
				$.historyLoad(hash,search,host);
			}
		}
	} else if (str[1] == "komimi") {
		if(toggle.indexOf("TopMenu=6")!=-1){
			location.hash = "#";
		} else {
			if (path.indexOf("komimi")!=-1) {
				location.hash = "#";
			} else {
				search = "?TopMenu=6";
				$.historyLoad(hash,search,host);
			}
		}
	} else { search = ""; };
/*
	if (str[1] == "profile") {
		search = "?TopMenu=0";
	} else if (str[1] == "works") {
		search = "?TopMenu=1";
	} else if (str[1] == "news") {
		search = "?TopMenu=2";
	} else if (str[1] == "inquiry") {
		search = "?TopMenu=3";
	} else if (str[1] == "basket") {
		search = "?TopMenu=4";
	} else if (str[1] == "komimi") {
		search = "?TopMenu=5";
	}
	
		$.historyLoad(hash,search,host);
*/
		return false;
	});


	/* Blog Entry */

	$(".BlogContents .Block .EntryBody p:first-child").css({ "margin-top":"25px" });
	$(".BlogContents .Block:last-child").css({ "margin-bottom":"0px" });


	/* Menu Action */
	
	$("#Profile .TopMenu").hover(
		function () { 
			var menu01 = (navigator.appName.indexOf("Microsoft") != -1) ? menu01 : document.menu01;
			window.document.menu01.SetVariable("_level0.btnFlag", 1);
		}
		,
		function () { 
			var menu01 = (navigator.appName.indexOf("Microsoft") != -1) ? menu06 : document.menu01;
			window.document.menu01.SetVariable("_level0.btnFlag", 2);
		}
	);
	
	$("#Profile2 .TopMenu").hover(
		function () { 
			var menu07 = (navigator.appName.indexOf("Microsoft") != -1) ? menu07 : document.menu07;
			window.document.menu07.SetVariable("_level0.btnFlag", 1);
		}
		,
		function () { 
			var menu07 = (navigator.appName.indexOf("Microsoft") != -1) ? menu06 : document.menu07;
			window.document.menu07.SetVariable("_level0.btnFlag", 2);
		}
	);
	
	$("#Works .TopMenu").hover(
		function () { 
			var menu02 = (navigator.appName.indexOf("Microsoft") != -1) ? menu02 : document.menu02;
			window.document.menu02.SetVariable("_level0.btnFlag", 1);
		}
		,
		function () { 
			var menu02 = (navigator.appName.indexOf("Microsoft") != -1) ? menu06 : document.menu02;
			window.document.menu02.SetVariable("_level0.btnFlag", 2);
		}
	);
	
	$("#News .TopMenu").hover(
		function () { 
			var menu03 = (navigator.appName.indexOf("Microsoft") != -1) ? menu03 : document.menu03;
			window.document.menu03.SetVariable("_level0.btnFlag", 1);
		}
		,
		function () { 
			var menu03 = (navigator.appName.indexOf("Microsoft") != -1) ? menu06 : document.menu03;
			window.document.menu03.SetVariable("_level0.btnFlag", 2);
		}
	);
	
	$("#Inquiry .TopMenu").hover(
		function () { 
			var menu04 = (navigator.appName.indexOf("Microsoft") != -1) ? menu04 : document.menu04;
			window.document.menu04.SetVariable("_level0.btnFlag", 1);
		}
		,
		function () { 
			var menu04 = (navigator.appName.indexOf("Microsoft") != -1) ? menu06 : document.menu04;
			window.document.menu04.SetVariable("_level0.btnFlag", 2);
		}
	);

/*
	var open = $("#Inquiry .TopContents").css("display");
	if( open == "block" ){
		setTimeout("initialize()", 1000);
	}
	$("#Inquiry .TopMenu").click(
		function(){
			var open = $("#Inquiry .TopContents").css("display");
			if( open == "block" ){
				setTimeout("initialize()", 1000);
			}
		}
	);
*/
	var open = $("#Inquiry .TopContents").css("display");
	if( open == "block" ){
		setTimeout("GMA()", 1000);
	} else {
		$("#Inquiry .TopMenu").click(
			function(){
					setTimeout("GMA()", 1000);
			}
		);
	}

	
	$("#Basket .TopMenu").hover(
		function () { 
			var menu05 = (navigator.appName.indexOf("Microsoft") != -1) ? menu05 : document.menu05;
			window.document.menu05.SetVariable("_level0.btnFlag", 1);
		}
		,
		function () { 
			var menu05 = (navigator.appName.indexOf("Microsoft") != -1) ? menu06 : document.menu05;
			window.document.menu05.SetVariable("_level0.btnFlag", 2);
		}
	);
	
	$("#Komimi .TopMenu").click( function() {
		if (MenuFlag == "close") {
			var menu06 = (navigator.appName.indexOf("Microsoft") != -1) ? menu06 : document.menu06;
			window.document.menu06.SetVariable("_level0.btnFlag", 1);
			MenuFlag = "open";
		} else if (MenuFlag == "open")  {
			var menu06 = (navigator.appName.indexOf("Microsoft") != -1) ? menu06 : document.menu06;
			window.document.menu06.SetVariable("_level0.Flag", 2);
			MenuFlag = "close";
		} else {
			var menu06 = (navigator.appName.indexOf("Microsoft") != -1) ? menu06 : document.menu06;
			window.document.menu06.SetVariable("_level0.btnFlag", 1);
			MenuFlag = "open";
		}
	});
	
	$("#Profile .TopMenu").click(function () { 
		var menu06 = (navigator.appName.indexOf("Microsoft") != -1) ? menu06 : document.menu06;
		window.document.menu06.SetVariable("_level0.Flag", 2);
		MenuFlag = "close";
	});
	$("#Profile2 .TopMenu").click(function () { 
		var menu06 = (navigator.appName.indexOf("Microsoft") != -1) ? menu06 : document.menu06;
		window.document.menu06.SetVariable("_level0.Flag", 2);
		MenuFlag = "close";
	});
	$("#Works .TopMenu").click(function () { 
		var menu06 = (navigator.appName.indexOf("Microsoft") != -1) ? menu06 : document.menu06;
		window.document.menu06.SetVariable("_level0.Flag", 2);
		MenuFlag = "close";
	});
	$("#News .TopMenu").click(function () { 
		var menu06 = (navigator.appName.indexOf("Microsoft") != -1) ? menu06 : document.menu06;
		window.document.menu06.SetVariable("_level0.Flag", 2);
		MenuFlag = "close";
	});
	$("#Inquiry .TopMenu").click(function () { 
		var menu06 = (navigator.appName.indexOf("Microsoft") != -1) ? menu06 : document.menu06;
		window.document.menu06.SetVariable("_level0.Flag", 2);
		MenuFlag = "close";
	});
	$("#Basket .TopMenu").click(function () { 
		var menu06 = (navigator.appName.indexOf("Microsoft") != -1) ? menu06 : document.menu06;
		window.document.menu06.SetVariable("_level0.Flag", 2);
		MenuFlag = "close";
	});


	/* Set Color Click */

	$("#ChipC a").click(function () { 
		$("#ColorChip").css({ "background-image":"url(/common/images/color_c.gif)" });
		$("body").removeAttr("class");
		$("body").addClass("SetColorC");
		$.cookie("setColor","SetColorC",{expires:30,path:'/'});
	})
	.click(setColorC);
	$("#ChipC a").hover(
		function () { $("#ColorChip ul").addClass("ColorC"); },
		function () { $("#ColorChip ul").removeClass("ColorC"); }
	);

	$("#ChipM a").click(function () { 
		$("#ColorChip").css({ "background-image":"url(/common/images/color_m.gif)" });
		$("body").removeAttr("class");
		$("body").addClass("SetColorM");
		$.cookie("setColor","SetColorM",{expires:30,path:'/'});
	})
	.click(setColorM);
	$("#ChipM a").hover(
		function () { $("#ColorChip ul").addClass("ColorM"); },
		function () { $("#ColorChip ul").removeClass("ColorM"); }
	);
	
	$("#ChipY a").click(function () { 
		$("#ColorChip").css({ "background-image":"url(/common/images/color_y.gif)" });
		$("body").removeAttr("class");
		$("body").addClass("SetColorY");
		$.cookie("setColor","SetColorY",{expires:30,path:'/'});
	})
	.click(setColorY);
	$("#ChipY a").hover(
		function () { $("#ColorChip ul").addClass("ColorY"); },
		function () { $("#ColorChip ul").removeClass("ColorY"); }
	);

	$("#ChipK a").click(function () { 
		$("#ColorChip").css({ "background-image":"url(/common/images/color_bk.gif)" });
		$("body").removeAttr("class");
		$("body").addClass("SetColorK");
		$.cookie("setColor","SetColorK",{expires:30,path:'/'});
	})
	.click(setColorK);
	$("#ChipK a").hover(
		function () { $("#ColorChip ul").addClass("ColorK"); },
		function () { $("#ColorChip ul").removeClass("ColorK"); }
	);
	
});

$(window).load( function() {
	$(document.body).fadeIn("2000");
});

