/* smooth scrolling for anchor link */

$(document).ready(function(){
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		&& location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target
			|| $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body')
				.animate({scrollTop: targetOffset}, 500, "swing" );
			 return false;
			}
		}
	});
});

/* lightbox activation with elements inside classname "lightbox" */

$(function() {
	$('.lightbox a').lightBox();  
});


/* Pulldown activation with secondary li elements inside id name "nav" */
$(function(){

  $("ul.dropdown li").hover(function(){

    $(this).addClass("hover");
    $('ul:first',this).show( 10, function() {
      $(this).removeAttr('filter');
    });

  }, function(){

    $(this).removeClass("hover");
    $('ul:first',this).hide(10);

  });

  $("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");

});


/* add class="active" for links to the same path with temporal page */

$(function(){

  var path = location.pathname.substring(1);
  var navpath = path.replace(/^(.+?)\/(.+?)\/.*$/,"$1\/$2\/");
  var sidepath = path.replace(/^(.+)\/.*.html$/,"$1\/");

// main navigation
  $('#nav li a[href$="' + navpath + '"]').attr('class', 'active');

// sidebar navigation
  if ( path == sidepath ) {
    $('#sidebar li a[href$="' + sidepath + '"]').attr('class', 'active');
  } else {
    $('#sidebar li a[href$="' + path + '"]').attr('class', 'active');
  }
});


// グローバルメニュー用
function addActiveGlobal(){
if (!document.getElementsByTagName){
return;
}
var gMenu = document.getElementById(“nav”);
if(!gMenu){
return;
}
var uri = location.href.split(‘#’)[0];
// index.html等ファイル名を無視する
var file= uri.substring(uri.lastIndexOf(‘/’,uri.length)+1,uri.length);
if(file.length>0){
uri = uri.split(file)[0];
}
var gLinks = gMenu.getElementsByTagName(“a”);
addActive(uri,gLinks.length, gLinks);
}

// クラス名付加共通パーツ
function addActive(uri,len,links){
for( var i=0; i<len ; i++){
if(links[i].href == uri){
var parentObj= links[i].parentNode;
if(parentObj.getAttribute(“class”)){
var oldClass = parentObj.getAttribute(“class”)
parentObj.setAttribute( “class”, “active ” + oldClass);
}
else if(parentObj.getAttribute(“className”)){
var oldClass = parentObj.getAttribute(“className”)
parentObj.setAttribute(“className”, “active ” + oldClass);
}
}
}
} 

