﻿$(function () {
	var bodyID=$("body").attr("id");
	
	/* Intro **************************************************/
	if(bodyID=="intro") {
		$("#intro-logo").fadeOut(0);
		window.onresize = windowChange;
		windowChange();
		$("#intro-logo").fadeIn(1500);
	
	/* Collection **************************************************/
	} else if(bodyID=="collection") {
		$("#nav #nav-collection img").attr("src",$("#nav #nav-collection img").attr("src").replace(".gif", "_b.gif"));
		var current="image01";
		$("#thumb li img").fadeTo(0,"0.5");
		$("#image .image01 img").fadeIn(1500);
		$("#thumb li.image01 img").fadeTo(1500,"1");
		$("#thumb").delegate("li","click", function(e) {
			var className=$(this).attr("class");
			if(className!=current) {
				$("#image li img").fadeOut(500);
				$("#thumb li img").fadeTo(0,"0.5");
				$("#image li."+className+" img").fadeIn(500);
				$("#thumb li."+className+" img").fadeTo(0,"1");
				current=className;
				$("#contents").animate({height:$("#image li."+className+" img").height()},250);
			}
			return false;
		});
		$("#thumb").delegate("li","mouseover", function(e) {
			var className=$(this).attr("class");
			if(className!=current) {
				$("img",this).fadeTo(250,"0.75");
			}
		});
		$("#thumb").delegate("li","mouseout", function(e) {
			var className=$(this).attr("class");
			if(className!=current) {
				$("img",this).fadeTo(250,"0.5");
			}
		});
	
	/* Retailers **************************************************/
	} else if(bodyID=="optical" || bodyID=="clothes") {
		$("#retailers-area").delegate("a","click", function(e) {
			window.open($(this).attr("href"));
			return false;
		});
		$("#nav #nav-"+bodyID+" img").attr("src",$("#nav #nav-"+bodyID+" img").attr("src").replace(".gif", "_b.gif"));
		$("#nav-retailers").addClass("open");
		$("#nav-retailers").css({height:($("#nav-retailers").find("li").size())*15+5+16});
	
	/* Products **************************************************/
	} else if(bodyID=="products") {
		$("#nav #nav-products img").attr("src",$("#nav #nav-products img").attr("src").replace(".gif", "_b.gif"));
		$("#image-viewer .item").fadeOut(0);
		
		var currentItem="item01";
		var currentImage="image01";
		$("#thumb-list li img").fadeTo(0,"0.5");
		$("#image-viewer .item01").fadeIn(1500);
		$("#image-viewer .image .image02").fadeOut(0);
		$("#image-viewer .image .image03").fadeOut(0);
		$("#thumb-list li.item01 img").fadeTo(1500,"1");
		
		$("#viewer-btn").delegate("li","click", function(e) {
			var className=$(this).attr("class").replace(" current", "");
			if(className!=currentImage) {
				currentImage=className;
				$("."+currentItem+" .image li").fadeOut(500);
				$("."+currentItem+" .image ."+className).fadeIn(500);
				$("#viewer-btn li").removeClass("current");
				$(this).addClass("current");
			}
		});
		
		$("#thumb-list li").delegate("img","click", function(e) {
			var className=$(this).parent().attr("class");
			if(className!=currentItem) {
				currentItem=className;
				currentImage="image01";
				$("#image-viewer .item").not("."+currentItem).fadeOut(500);
				$("#image-viewer ."+className).fadeIn(500);
				$("#image-viewer ."+className+" .image01").fadeIn(0);
				$("#image-viewer ."+className+" .image02").fadeOut(0);
				$("#image-viewer ."+className+" .image03").fadeOut(0);
				$("#viewer-btn li").removeClass("current");
				$("#viewer-btn .image01").addClass("current");
				$("#thumb-list li").not("."+currentItem).children("img").fadeTo(500,"0.5");
				$(this).fadeTo(500,"1");
			}
		});
		$("#thumb-list li").delegate("img","mouseover", function(e) {
			var className=$(this).parent().attr("class");
			if(className!=currentItem) {
				$(this).fadeTo(250,"0.75");
			}
		});
		$("#thumb-list li").delegate("img","mouseout", function(e) {
			var className=$(this).parent().attr("class");
			if(className!=currentItem) {
				$(this).fadeTo(250,"0.5");
			}
		});
	/* Blog **************************************************/
	} else if(bodyID=="blog") {
		$(".post .txt img").each(function(i){
			var w=$(this).width();
			var h=$(this).height();
			if(w>350){
				$(this).width(350);
				$(this).height(Math.round(h/w*350));
			}
		});
		$("#nav #nav-blog img").attr("src",$("#nav #nav-blog img").attr("src").replace(".gif", "_b.gif"));
		$(document).ready(function(){
			
			$('#blog-nav dd.archives a').each(function() {
				var text = $(this).text().split("年");
				//[Month. Year]
				$(this).html(month_en(text[1])+" "+text[0]);
			});
			//yyyy年mm月の置換
			$('#wp-calendar caption').each(function() {
				var text = $(this).text().split("年");
				//[Month. Year]
				$(this).html(text[0]+"<br />"+month_en(text[1]));
			});
		
			//曜日の置換
			$('#wp-calendar th').each(function() {
				if ($(this).text() == "日") { $(this).addClass('sunday'); } 
				if ($(this).text() == "土") { $(this).addClass('saturday'); }
				$(this).text(day_en($(this).text()));
			});
		
			//前月の置換
			$('#wp-calendar #prev a').each(function() {
				var text = $(this).text().split(" ");
				//[< Month]
				$(this).text('< ' + month_en2(text[1]));
			});
		
			//次月の置換
			$('#wp-calendar #next a').each(function() {
				var text = $(this).text().split(" ");
				//[Month >]
				$(this).text(month_en2(text[0]) + ' >');
			});
		
			function day_en($text) {
				switch ($text) {
					case '日':  $text = 'S'; break;
					case '月':  $text = 'M'; break;
					case '火':  $text = 'T'; break;
					case '水':  $text = 'W'; break;
					case '木': $text = 'T'; break;
					case '金': $text = 'F'; break;
					case '土': $text = 'S'; break;
				}
				return $text;
			}
		
			function month_en($text) {
				switch ($text) {
					case '12月': $text = 'December'; break;
					case '11月': $text = 'November'; break;
					case '10月': $text = 'October'; break;
					case '9月': $text = 'September'; break;
					case '8月': $text = 'August'; break;
					case '7月': $text = 'July'; break;
					case '6月': $text = 'June'; break;
					case '5月': $text = 'May'; break;
					case '4月': $text = 'April'; break;
					case '3月': $text = 'March'; break;
					case '2月': $text = 'February'; break;
					case '1月': $text = 'January'; break;
				}
				return $text;
			}
			
			function month_en2($text) {
				switch ($text) {
					case '12月': $text = 'Dec'; break;
					case '11月': $text = 'Nov'; break;
					case '10月': $text = 'Oct'; break;
					case '9月': $text = 'Sep'; break;
					case '8月': $text = 'Aug'; break;
					case '7月': $text = 'Jul'; break;
					case '6月': $text = 'Jun'; break;
					case '5月': $text = 'May'; break;
					case '4月': $text = 'Apr'; break;
					case '3月': $text = 'Mar'; break;
					case '2月': $text = 'Feb'; break;
					case '1月': $text = 'Jan'; break;
				}
				return $text;
			}
		});
	/* Contact **************************************************/
	} else if(bodyID=="contact") {
		$("#nav #nav-contact img").attr("src",$("#nav #nav-contact img").attr("src").replace(".gif", "_b.gif"));
		$("#privacy-policy").fadeOut(0);
		$("#privacy-policy").height(1);
		var openFlg = false;
		$("#privacy-btn").click(function () {
			if(!openFlg) {
				$("#privacy-policy").fadeIn(250);
				$("#privacy-policy").animate({height:"180px"},500,function(){openFlg=true;});
			} else {
				
				$("#privacy-policy").animate({height:"1px"},500,function(){$("#privacy-policy").fadeOut(0);openFlg=false;});
			}
		});
	}
	
	$("#nav .acc").delegate(".tit","click", function(e) {
		var mFlg=false;
		if(!mFlg) {
			mFlg=true;
			if(!$(this).parent().hasClass("open")) {
				$(this).parent().children("ul").fadeOut(0);
				$(this).parent().animate({height:($(this).parent().find("li").size())*15+5+16},350,"easeOutCirc",function(){$(this).children("ul").delay(250).fadeIn(500); mFlg=false;});
				$(this).parent().addClass("open");
			} else {
				$(this).parent().children("ul").delay(250).fadeOut(500,function(){$(this).parent().animate({height:16},350,"easeOutCirc",function(){mFlg=false;});});
				$(this).parent().removeClass("open");
			}
		}
	});
	
})

function windowChange() {
	var bH=getBrowserHeight();
	$("#intro-logo").css({paddingTop:Math.round((bH-80)/2)+"px"});
}

function getBrowserHeight() {
	if ( window.innerHeight ) {
		return window.innerHeight;
	}
	else if ( document.documentElement && document.documentElement.clientHeight != 0 ) {
		return document.documentElement.clientHeight;
	}
	else if ( document.body ) {
		return document.body.clientHeight;
	}
	return 0;
}
function getBrowserWidth() {
	if ( window.innerWidth ) {
		return window.innerWidth;
	}
	else if ( document.documentElement && document.documentElement.clientWidth != 0 ) {
		return document.documentElement.clientWidth;
	}
	else if ( document.body ) {
		return document.body.clientWidth;
	}
	return 0;
}
