$(function()
{
	var min_height = 600;
		
	$(".content_wrap")
		.css("overflow", "hidden")
	;
	
	$("#slider").css({
		"width" : $(".content_wrap").width() * $(".content_wrap .content").length,
		"height" : min_height,
		"background-image" : "url(\"/ref/images/salon/salon_bg.gif\")",
		"background-repeat" : "no-repeat",
		"background-position" : "-50px 0px"
	});
	
	$(".content_wrap .content").each(function(i, val)
	{
		$(this)	// タイル状に敷き詰め
			.css(
			{
				"width" : $(".content_wrap").width(),
//				"opacity" : 0.125,
				"float" : "left"/*,
				"height" : "auto",
				"z-index" : -1*/,
				"min-height" : min_height
			})
		;
	});
	
	$(".content_wrap .content:last")
		.css("clear", "both")
	;
	
	$(".content_wrap")
		.css("height", 0)
	;
	
	/* TODO: ラインの登場感
	$("#service_bg").animate({
	});
	*/
	
	var pos = 0;
	
	if ($.browser.safari)
	{
		$(".content p").css("text-shadow", "#ffffff 0 0 3px");
	}
	
	var overlayReposition = function()
	{
		var $content = $(".content:eq(" + pos + ")");
		
		$(".content_overlay_left, .content_overlay_right").css({
			"margin-top" : ($content.height() + 40) * -1,
			"height" : $content.height() + 40
		});
	};
	
	var redraw = function()
	{
		var ms = 750;
		var $active_content = $(".content_wrap .content:eq(" + pos + ")");
		
		/*
		var fg;
		
		if (pos == 3)
		{
			pos = 0;
			fg = true;
		}
		*/
		
		// 左右のグラデの再配置
/*
		$(".content_overlay_left, .content_overlay_right").css({
			"margin-top" : ($(".pricelist").height() + 40) * -1,
			"height" : $(".pricelist").height() + 40
		});
*/
		overlayReposition();
		
//		var marginTop = 0;
		
//		if (fg)
//		{
//			marginTop = $(".content:last").height()/* + 70*/;
//		}

		
		// コンテンツのスライド
		/*
		$("#slider")
			.stop().animate(
			{
				"marginLeft" : pos * $(".content_wrap").width() * -1,
				"marginTop" : marginTop * -1
			},
			ms, "easeOutExpo")
		;
		*/
		$("#slider")
			.stop().animate(
			{
				"marginLeft" : ($active_content.position().left  * -1) + parseInt($("#slider").css("margin-left")),
				"marginTop" : ($active_content.position().top * -1) + parseInt($("#slider").css("margin-top"))
			},
			ms, "easeOutExpo")
		;
		
		/*
		if (fg)
		{
			pos = 3;	
		}
		*/
		
		// 表示高さ変更
		var height = $active_content.outerHeight(true);
		if (height < min_height) height = min_height;
		
		$(".content_wrap")
			.stop().animate({
				"height" : height
			}, 500, "easeOutExpo")
		;
		
		if (!$.browser.msie)
		{
			// アクティヴなコンテンツ
			$active_content
				.stop().animate({
					"opacity" : 1
				}, ms, 'easeInQuint')
			;
			
			// 非アクティヴなコンテンツ
			$(".content_wrap .content:not(:eq(" + pos + "))")
				.stop().animate({
					"opacity" : 0.125
				}, ms, 'easeOutExpo')
			;
		}
	}
	
	var positionIncrease = function(i)
	{
		return (++pos % $(".content_wrap .content").length);
	}
	
	var positionDecrease = function(i)
	{
		return ((--pos % $(".content_wrap .content").length) + $(".content_wrap .content").length) % $(".content_wrap .content").length;
	}
	
	$(window).resize(function()
	{
		redraw();
	});
	
	/*
	$("#prev").click(function()
	{
		pos = positionDecrease(pos);
		redraw();
	});
	
	$("#next").click(function()
	{
		pos = positionIncrease(pos);
		redraw();
	});
	*/
	
	/*
	$(".snav li").click(function()
	{
		// pos = $(".snav li").index($(this)) % 5;
		redraw();
		return false;
	});
	*/
	
	$("a[href^=#]").click(function()
	{
//		console.log(this.hash);
		
		switch (this.hash)
		{
			case "#concept":
				pos = 0;
				break;
			case "#staff":
				pos = 1;
				break;
			case "#recruit":
				pos = 2;
				break;
			case "#gallery":
				pos = 3;
				break;
			default:
				return true;
		}
		
		redraw();
		return false;
	});
	
	$(".content_wrap").css({ 'visibility' : 'visible' });
	redraw();	// 初期設定
	$("#slider").animate({ "backgroundPosition" : "0px 0px" }, 500, "easeOutExpo");
});