/* Set */
var setFlash = new Array (6);
	setFlash[0] = "menu01";
	setFlash[1] = "menu02";
	setFlash[2] = "menu03";
	setFlash[3] = "menu04";
	setFlash[4] = "menu05";
	setFlash[5] = "menu06";
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);
	}
*/
}

/* 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'} });
		$('#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'} });
		$('#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'} });
		$('#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'} });
		$('#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'} });
		$('#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] == "works") {
		if(toggle.indexOf("TopMenu=1")!=-1){
			location.hash = "#";
		} else {
			if (path.indexOf("works")!=-1) {
				location.hash = "#";
			} else {
				search = "?TopMenu=1";
				$.historyLoad(hash,search,host);
			}
		}
	} else if (str[1] == "news") {
		if(toggle.indexOf("TopMenu=2")!=-1){
			location.hash = "#";
		} else {
			if (path.indexOf("news")!=-1) {
				location.hash = "#";
			} else {
				search = "?TopMenu=2";
				$.historyLoad(hash,search,host);
			}
		}
	} else if (str[1] == "inquiry") {
		if(toggle.indexOf("TopMenu=3")!=-1){
			location.hash = "#";
		} else {
			if (path.indexOf("inquiry")!=-1) {
				location.hash = "#";
			} else {
				search = "?TopMenu=3";
				$.historyLoad(hash,search,host);
			}
		}
	} else if (str[1] == "basket") {
		if(toggle.indexOf("TopMenu=4")!=-1){
			location.hash = "#";
		} else {
			if (path.indexOf("basket")!=-1) {
				location.hash = "#";
			} else {
				search = "?TopMenu=4";
				$.historyLoad(hash,search,host);
			}
		}
	} else if (str[1] == "komimi") {
		if(toggle.indexOf("TopMenu=5")!=-1){
			location.hash = "#";
		} else {
			if (path.indexOf("komimi")!=-1) {
				location.hash = "#";
			} else {
				search = "?TopMenu=5";
				$.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);
		}
	);
	
	$("#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);
		}
	);
	
	$("#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";
	});
	$("#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");
});
