$(function () {
	/*
	* 既存の表示ページはclassの属性値にcurrentを設定
	*/
	
	// li要素のクラス属性値currentを削除
	$("#nav li").each(function (i) {
		$(this).removeClass("current");
		var attrClass = $(this).attr("class");
		if(!attrClass) {
			$(this).removeAttr("class");
		}
	});
	// アクティブページ
	var nav = {
		"#nav_home"    : 0,
		"#nav_service" : 1,
		"#nav_results" : 2,
		"#nav_about"   : 3,
		"#nav_faq"     : 4,
		"#nav_contact" : 5
	}	
	var pathName = window.location.pathname;
	var path = pathName.split('/');
	var page = path[path.length-2];
	if( page =="") {
		page = "home";
	}
	var navID = '#nav_' + page;
	if ($(navID))
	{
		$(navID).addClass('currentnav');
		var n = nav[navID];
		$(navID).parent().addClass("current");
		var widthString = $(navID).parent().css("width");
		var widthValue = widthString.match(/\d+/);
		var leftValue=widthValue * n;
		$('li.back').css("left", leftValue);
	}
	// LavaLamp
	$("#nav").lavaLamp({ fx: "backout", speed: 700 });
	// 角丸
	$("#content").corner();
	// ページの上へ
	if (! $.browser.safari) {
		$('.pagetop').click(function () {
			$(this).blur();
			$('html,body').animate({ scrollTop: 0 }, 'slow');
			return false;
		});
	}
	// ホーム : FAQ
	$("div#faq dt").hover(
		function(){ $(this).css("cursor","pointer"); },
		function(){	$(this).css("cursor","default"); }
	);
	$("div#faq dd").css("display","none");
	//開閉処理 toggle(fn1, fn2, ..., fnN) 要素がクリックされる毎に、引数で渡した関数を順番に呼び出します。
	$("div#faq dt").toggle(
		function(){
			$(this).addClass("open");
		},
		function () {
			$(this).removeClass("open");
		}
	)
	$("div#faq dt").click(
		function(){
			$(this).next().slideToggle("normal");
		}
	);
	// ホーム : カスタムスライドショー
	var currentIndex = 0;
	var intervalld = null;
	$("#slide ul").width($("#slide").width() * $("#slide li").length);
	$("#next").click(function()
	{
		currentIndex += 1;
		if (currentIndex >= $("#slide li").length)
		{
			currentIndex = 0;
		}
		var movingLength = $("#slide").width() * currentIndex;
		$("#slide ul").animate(
		{
			marginLeft: -movingLength
		}, 1000)
	})
});

