/* Search Box
---------------------------------------------------------------------------------------------------- */
/*
$(function(){
	$('#search_box input[value=""]').val("サイト内検索")
		.css("color","#999");   
    $("#search_box input").focus(function(){   
        if(this.value == "サイト内検索"){   
        	$(this).val("").css("color","#000");   
        }   
    });   
    $("#search_box input").blur(function(){   
        if(this.value == ""){   
            $(this).val("サイト内検索")
            	.css("color","#999");   
        }   
        if(this.value != "サイト内検索"){   
            $(this).css("color","#000");  
        }   
    });
    $("input.search_btn").click(function(){
		$('input[value="サイト内検索"]').val("");
	});
});
*/

/* Rollover
---------------------------------------------------------------------------------------------------- */
var imgRollover = {
main : function() {
var img = document.images, ipt = document.getElementsByTagName('input'), i, preLoadImg = [];
// img elements
for (i = 0; i <img.length; i++) {
if ((img[i].src.match(/.*_off\./))||(img[i].style.filter)){
preLoadImg[preLoadImg.length] = new Image;
preLoadImg[preLoadImg.length-1].src = img[i].src.replace('_off.', '_on.');

img[i].onmouseover = imgRollover.over;
img[i].onmouseout  = imgRollover.out;
try {img[i].addEventListener('click', imgRollover.click, false);}
catch(e){img[i].attachEvent('onclick', (function(el){return function(){imgRollover.click.call(el);};})(img[i]));}
}
}
// input[image] elements
for (i = 0; i <ipt.length; i++) {
if ((ipt[i].src.match(/.*_off\./))&&(ipt[i].getAttribute('type')=='image')){
preLoadImg[preLoadImg.length] = new Image;
preLoadImg[preLoadImg.length-1].src = ipt[i].src.replace('_off.', '_on.');

ipt[i].onmouseover = imgRollover.over;
ipt[i].onmouseout  = imgRollover.out;
try {ipt[i].addEventListener('click', imgRollover.click, false);}
catch(e){ipt[i].attachEvent('onclick', (function(el){return function(){imgRollover.click.call(el);};})(ipt[i]));}
}
}
}
,

over : function() {
var imgSrc, preLoadImgSrc;
if((this.style.filter)&&(this.style.filter.match(/_off\.png/)))//(IE5.5-6 && png)
this.style.filter = this.style.filter.replace('_off.png', '_on.png');
else
this.src = this.src.replace('_off.', '_on.');
},

out : function(){
if((this.style.filter)&&(this.style.filter.match(/_on\.png/)))//(IE5.5-6 && png)
this.style.filter = this.style.filter.replace('_on.png', '_off.png');
else
this.src = this.src.replace('_on.', '_off.');
},

click : function(){
if((this.style.filter)&&(this.style.filter.match(/_on\.png/)))//(IE5.5-6 && png)
this.style.filter = this.style.filter.replace('_on.png', '_off.png');
else
this.src = this.src.replace('_on.', '_off.');
},

addEvent : function(){
try {
window.addEventListener('load', this.main, false);
} catch (e) {
window.attachEvent('onload', this.main);
}
}
}

imgRollover.addEvent();


/* Global Navigation
---------------------------------------------------------------------------------------------------- */
/*
var arrG = location.href.split("/");
var thisGPath = arrG[3] + "/";
$(function(){
	$("#gnav img").each(function() {
		var globalNavURL = $(this).parents().attr("href");
		if(globalNavURL.indexOf(thisGPath) != -1) {
			 this.src = this.src.replace(/\_off.(gif|jpg|png)/,"_on.$1");
		}
	});
});
*/

/* Local Navigation
---------------------------------------------------------------------------------------------------- */
/*
var arrL = location.href.split("/");
var thisLPath = (arrL[4] != "") ? (arrL[3] + "/" + arrL[4]) : (arrL[3] + "/index.html");
$(function(){
	$("ul.lnav img.lower").each(function() {
		var localNavURL = $(this).parents().attr("href");
		if(localNavURL.indexOf(thisLPath) != -1) {
			 this.src = this.src.replace(/_off\.(gif|jpg|png)/,"_on.$1");
		}
	});
});

var arrLL = location.href.split("/");
var thisLLPath = (arrLL[5] != "") ? (arrLL[4] + "/" + arrLL[5]) : (arrLL[4] + "/index.html");
$(function(){
	$("ul.lnav ul img").each(function() {
		var localLNavURL = $(this).parents().attr("href");
		if(localLNavURL.indexOf(thisLLPath) != -1) {
			 this.src = this.src.replace(/_off\.(gif|jpg|png)/,"_on.$1");
		}
	});
});
*/

$(function() {
	//現在のURLを配列で取得	  	
	var now = location.href.split('/');
	//親のディレクトリ取得
	var dir = now.slice(now.length-2,now.length-1);
	var reg = new RegExp('(id=\"'+dir+'\"|id='+dir+')');
	$('ul.lnav').each(function(){
		var txt = $(this).html();
		$(this).html(
			txt.replace(reg,'$1 class=\"active\"')
		);
	});
});

$(document).ready(function(){
	//Hide (Collapse) the toggle containers on load
	$("ul.lnav li ul").hide();
	$("ul.lnav li ul.active").show(); 

	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	$("ul.lnav li .toggle").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
		return false; //Prevent the browser jump to the link anchor
	});

	$("ul.lnav li .toggle_on").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
		return false; //Prevent the browser jump to the link anchor
	});

	$("ul.lnav li .toggle_current").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
		return false; //Prevent the browser jump to the link anchor
	});
});


/* scrollsmoothly
---------------------------------------------------------------------------------------------------- */
$(function(){
   // #で始まるアンカーをクリックした場合に処理
   $('a[href^=#pagetop]').click(function() {
      // スクロールの速度
      var speed = 500;// ミリ秒
      // アンカーの値取得
      var href= $(this).attr("href");
      // 移動先を取得
      var target = $(href == "#" || href == "" ? 'html' : href);
      // 移動先を数値で取得
      var position = target.offset().top;
      // スムーススクロール
      $($.browser.safari ? 'body' : 'html').animate({scrollTop:position}, speed, 'swing');
      return false;
   });
});

