/*------------------------------------- 
 function.js
 1.ロールオーバー
 2.ページ内スクロール
 3.セルフリンク
-------------------------------------*/  

//1.ロールオーバー

function initRollOvers() {
	if (!document.getElementById){
		return;
	}
	
	var preLoads = new Array();
	var allImages = document.getElementsByTagName('img');

	for (var i = 0; i < allImages.length; i++) {		
		if (allImages[i].className == 'rollover') {
			var src = allImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var oSrc = src.replace(ftype, '_o'+ftype);

			//-- スワップ元、スワップ先画像の登録
			allImages[i].setAttribute('pSrc', src);
			allImages[i].setAttribute('oSrc', oSrc);

			//-- イメージのプリロード
			preLoads[i] = new Image();
			preLoads[i].src = oSrc;

			//-- イベントの設定
			allImages[i].onmouseover = function() {
				this.setAttribute('src', this.getAttribute('oSrc'));
			}
			allImages[i].onmouseout = function() {
				this.setAttribute('src', this.getAttribute('pSrc'));
			}
		}
	}
}


//2.ページ内スクロール

// Easingの追加  
jQuery.easing.quart = function (x, t, b, c, d) {  
    return -c * ((t=t/d-1)*t*t*t - 1) + b;  
};  
  
/*------------------------------------- 
 ページ読み込み中 
-------------------------------------*/  
jQuery(document).ready(function(){  
  
//
// <a href="#***">の場合、スクロール処理を追加  
//
jQuery('a[href*=#]').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
            var $target = jQuery(this.hash);
            $target = $target.length && $target || jQuery('[name=' + this.hash.slice(1) +']');
            if ($target.length) {  
                var targetOffset = $target.offset().top;
                jQuery('html,body').animate({ scrollTop: targetOffset }, 1200, 'quart');
                return false;  
            }
        }
				});

});

function addOnload(func){
	if ( typeof window.addEventListener != "undefined" ){
		window.addEventListener( "load", func, false );
	}else if ( typeof window.attachEvent != "undefined" ) {
		window.attachEvent( "onload", func );
	}else{
		if ( window.onload != null ){
			var oldOnload = window.onload;
			window.onload = function ( e ) {
			oldOnload( e );
			window[func]();
		};
	}else
		window.onload = func;
	}
}
addOnload(initRollOvers);


//3.セルフリンク

$(document).ready( function() {
    $("#assist_nav a").each( function() {
        var url = document.URL.split("#");

        if ( this == url[0] || this + "index.html" == url[0]) {
            $(this).parent().addClass("current");
        }
    });
});