
/*	===============================================
		初期値設定
	===============================================		*/

var tgt_nav = '.subarea dl a';
var tgt_cate = '.subarea dl dl.category';
var cls_act = 'active';
var html_code = 'index.';
//var myurl = window.location;
var myurl = document.URL;
var mypath = '';
var root_dir = 'sitemap';
var mylink = '';
var ary_s = -1;			//	start of array
var ary_e = -1;			//	end of array

/*	===============================================
		関数定義
	===============================================		*/

function analizeURL()	{
//	alert('URL = ' + myurl);

	var buf0 = myurl.split('http://');
	var buf1 = buf0[1].split('#');
	mypath = buf1[0].split('/');
//	alert('mypath = ' + mypath);

	for(var i = 0; i< mypath.length; i++)	{
		if(mypath[i].indexOf(root_dir) != -1)	ary_s = i;
		if(mypath[i].indexOf('.html') != -1)		ary_e = i;
	}

	if(ary_e == -1)	ary_e = mypath.length - 1;		//	パスが「スラ切り」の場合

//	alert('ary_s = ' + ary_s);
//	alert('ary_e = ' + ary_e);

	for(var i = ary_s; i<= ary_e; i++)	{
		mylink += '/' + mypath[i];
	}

	if(mylink.indexOf(html_code) < 0) {		//	htmlファイル名が特定されていなければ、index.(拡張子はナシ)を付加
//		alert('indexOf: html_code = ' + html_code);
//		mylink += html_code;
		mylink = mylink + html_code;
	}

//	alert('mylink = '+ mylink);

}




function setActiveMenu()	{
	var this_href0 = '';
	var act0 = '';

	//	メニューのアクティブ処理
		$(tgt_nav).each(function(idx0) {
			this_href0 = $(this).attr('href');
	
	//		alert('this_href0 = ' + this_href0);
	
	//		alert('indexOf = ' + this_href0.indexOf(html_code));
			if(this_href0.indexOf(html_code) < 0) {		//	htmlファイル名が特定されていなければ、index.(拡張子はナシ)を付加
				this_href0 += html_code;
	//			alert('this_href0 = ' + this_href0);
			}
	

			if(	(mylink.indexOf(this_href0) != -1)
			||	(this_href0.indexOf(mylink) != -1) )	{
//				alert('this_href0 = ' + this_href0);
				$(this).parent().addClass(cls_act);
				act0 = $(this);
			}
	
		});



	//	カテゴリーの展開処理
		var depth0 = ary_e - ary_s;
//		var cate_act = '.cate-' + mypath[2];
	
	//	alert('depth0 = ' + depth0);
	
		//	まず全カテゴリーを非表示
		$(tgt_cate).each(function(idx0) {
//			$(this).children('dd').addClass('hdn');
			$(this).addClass('noSub');
		});

		var buf0 = act0.attr('href');
//		alert(buf0);
	
	//	var code_str0 = 'act0';
	
		//	現在ページの階層が2階層以降なら、該当カテゴリーは展開
		if(depth0 == 2) {
			act0.parent().parent().removeClass('noSub');
		}else if(depth0 == 3) {
			act0.parent().parent().parent().parent().removeClass('noSub');
		}



}

/*
function displayCategory(act0)	{
	var depth0 = ary_e - ary_s;
	var cate_act = '.cate-' + mypath[2];

	alert('depth0 = ' + depth0);

	//	まず全カテゴリーを非表示
	$(tgt_cate).each(function(idx0) {
		$(this).children('dd').addClass('hdn');
	});

	act0.attr('href');
	alert(act0);

}
*/

/*	===============================================
		処理実行
	===============================================		*/
$(function(){ 

	analizeURL();
	setActiveMenu();
//	displayCategory(act_menu1);

});
