var currentPage = location.pathname;
var flag;

$(function(){

	/* ==
	
	　ローカルナビゲーション（.lnav）
	
	============================================================================================== */
	//URLが/できられてる場合の処理
	var fileName = new RegExp(".html", "i");
	if(!currentPage.match(fileName)){ currentPage = currentPage + "index.html"; }

	//賃貸－コラム
	var dRoomSupportColumn = new RegExp("/tochikatsu/d-room/support/column/column_", "i");
	if(currentPage.match(dRoomSupportColumn)){ currentPage = "/tochikatsu/d-room/support/column/index.html"; }


	//カレント処理
	var currentLnav = $("div.lnav").attr("id");
	
	//中ページのリンクは一旦全部隠す
	$("div.lnav > div li").find("ul").hide();

	var currentFlg = false;
	$("div.lnav > div > ul > li").children("a").each(function(){
		if(currentFlg == false){
			var thisUrl = $(this).attr("href");
			if(currentPage.indexOf(thisUrl) != -1){
				$(this).parent().addClass("current");
				currentFlg = true;
			}
		}
	});
	
	if(currentFlg != true){
		$("div.lnav > div > ul > li > ul > li").children("a").each(function(){
			var thisUrl = $(this).attr("href");
			if(currentPage.indexOf(thisUrl) != -1){
				$(this).parent().parent().parent("li").addClass("current");
				currentFlg = true;
			}	
		});
	}
	
	if(currentFlg != true){
		$("div.lnav > div > ul > li > ul > li > ul > li").children("a").each(function(){
			var thisUrl = $(this).attr("href");
			if(currentPage.indexOf(thisUrl) != -1){
				$(this).parent().parent().parent().parent().parent("li").addClass("current");
				currentFlg = true;
			}	
		});
	}

	//カレントの子ども<ul>を表示させる。
	if(currentLnav != ""){ $("li.current").find("ul").show(); }

	//展開された子どものカレントが一番目だった時の処理
	//$("div.lnav > div > ul").children("li:first").css("marginTop", "1px");
	$("div.lnav > div").each(function(){
		$(this).children("ul").children("li").eq(0).css("marginTop", "1px");
	});

	//リスト一番下の背景処理
	$("div.lnav > div").children("ul").find("li:last").addClass("lastChild");
	
	//注文住宅：中ページ（/jutaku/lifestyle/以下）－ブログ紹介
	$("body#jutaku div.lnav > div.blog > ul").children("li:last").css("backgroundImage", "none");




	/* ==
	
	　活用方法一覧
	
	============================================================================================== */
	$("div.nav li.btnUselist a").hover(function(){
		$("div#uselist").show();
		$("div.nav li.btnUselist a").css({ backgroundPosition: "0 -21px" });
	},function(){
		flag = "on";
		setTimeout(function(){ chkUseList(); },100);
	});

	$("div#uselist").hover(function(){
		flag = "off";
		$("div#uselist").show();
		$("div.nav li.btnUselist a").css({ backgroundPosition: "0 -21px" });
	},function(){
		flag = "on";
		chkUseList();		
		/*
		$("div#uselist").fadeOut();
		$("div.nav li.btnUselist a").css({ backgroundPosition: "0 0" });
		*/
	});



});


function chkUseList(){

	if(flag == "on"){
		$("div#uselist").fadeOut();
		$("div.nav li.btnUselist a").css({backgroundPosition: "0 0"});
		flag = "off";
	}

}
