﻿/*************************************************
* functions with jQuery
* since:	2010-11-25
* last update: 2011-01-11
* create: morita
*************************************************/
/*====================================================================


 ■　function.js


--------------------------------------------------------------------*/


/*====================================================================

 □　初期設定

--------------------------------------------------------------------*/
/*----- 現在のURLを取得 ------*/
var url=document.URL
var protocol=document.location.protocol
var domain=document.domain
var path=protocol+"//"+domain
var onHref=url.substring(path.length,url.lastIndexOf("/")+1);

/*====================================================================

 □　処理リスト

--------------------------------------------------------------------*/

$(document).ready(function(){
	//実行する処理を記述
	funcHighlightPages();
	funcRollOver();
	funcPageScroll();
	funcSideNav();
	funcPopup();
	funcPageScrollAncher()
	//funcCrossBrowser()
});
/*--------------------------------------------
	HighlightPages [グローバルナビ制御]
--------------------------------------------*/
function funcHighlightPages(){
	
	//
	$('#g-nav a[href]').each(function(){
		var a=$(this);
    var hrefSrc=a.attr('href');
		var href=hrefSrc.substring(0,hrefSrc.lastIndexOf("/")+1)
		//
		if(href==onHref){
    	a.each(function(){
					var onSrc=$(this).find('img').attr('src').replace('_off.','_on.')
					$(this).find('img').attr('src',onSrc)
					//
					var tags=$(this).find('img');
					$(this).replaceWith(tags);
      })
		}
	});
};
/*--------------------------------------------
	funcRollOver [ロールオーバー制御]
--------------------------------------------*/
function funcRollOver(){
	var cache = [];
	$('img[src*=_off.],input[src*=_off.]').hover(function(){
           var onSrc=$(this).attr('src').replace('_off.','_on.')
           $(this).attr('src',onSrc)
       },function(){
           var offSrc=$(this).attr('src').replace('_on.','_off.')
           $(this).attr('src',offSrc)
       }).each(function(){
		var cacheImage = $(this)
		var cacheSrc=cacheImage.attr('src').replace('_off.','_on.')
		cacheImage.src = cacheSrc;
		cache.push(cacheImage);
	})
};

/*--------------------------------------------
	funcPageScroll [ページスクロール制御]
--------------------------------------------*/

function funcPageScroll(){
	$(".pagetop a").click(function(e){
		e.preventDefault(); 																
		$((navigator.userAgent.indexOf("Opera") != -1) ? document.compatMode == 'BackCompat' ? 'body' : 'html' :'html,body').animate({scrollTop:0}, 'normal');
	});
}

/*-----------------  スムーズスクロールの読み込み  ------------------------*/
//
$.easing.quart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};
function funcPageScrollAncher(){
	/*
	alert(location.hash)
	if(document.location.hash.length){
		ancherMove(location.hash)
	}
	*/
	$('a[href*=#]').click(function() {
			if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
				ancherMove(this.hash)
				return false;
			} 
  });
}

function ancherMove(t){
	var target = t;
	target = target.length && target || $('[name=' + this.hash.slice(1) +']');
	if (target.length) {
		var targetOffset = $(target).offset().top;
		$('html,body').animate({ scrollTop: targetOffset }, 1000, 'quart');
		
	}
}

/*--------------------------------------------
	funcSideNav [サイドナビ制御]
--------------------------------------------*/
function funcSideNav(){
	$("#side .side-nav dd[class!=n-open]").hide();
	//
	var sideHref=url.substring(path.length,url.length);
	//
	$('#side .side-nav a[href]').each(function(){
			var a=$(this);
    	var hrefSrc=a.attr('href');
			//
			if(hrefSrc.indexOf(".html")>-1){
				if(sideHref.match(hrefSrc)){
					a.each(function(){
						$(this).parent().next().show()
						$(this).parent().parent().parent().show()
						$(this).parent().parent().parent().prev().find('a').css('backgroundColor','#f0faff')
						//
						var tags=$(this).html()
						$(this).replaceWith('<span class="active">'+tags+'</span>');
						//
	      	})
				}
				
			}else{
				if(sideHref==hrefSrc){
					a.each(function(){
						$(this).parent().next().show()
						//
						var tags=$(this).html()
						$(this).replaceWith("<span>"+tags+"</span>");
	      	})
				}
			}
	})
}
/*--------------------------------------------
	funcTab [タブ制御]
--------------------------------------------*/
var tabActId
var tabOldId
var tabOldNav
function funcTab(){
	//tab-boxを隠す
	$('.tab-box').fadeTo(0,0).hide()
	//初期
	$('.tab-box').eq(0).fadeTo(0,1).show()
	tabOldId=$('.tab-box').eq(0).attr('id')
	tabOldNav=$('.tab-nav ul li').eq(0)
	//tab-nav click
	$('.tab-nav ul li a').click(function(){
		if($(this).parent().attr('class')!="active"){
			$(tabOldNav).removeClass('active')
			$(tabOldNav).css('backgroundColor','#ffffff')
			$(this).parent().addClass('active')
			$(this).parent().css('backgroundColor','#004293')
			tabOldNav=$(this).parent()
			tabActId=$(this).attr('href')
			ShowTab()
		}
		//
		return false;
	})
	$('.tab-nav ul li a').hover(function(){
		if($(this).parent().attr('class')!="active"){
			$(this).parent().css('backgroundColor','#e0ecfa')
		}
	},function(){
		if($(this).parent().attr('class')!="active"){
			$(this).parent().css('backgroundColor','#ffffff')
		}
	})
	//
}
function ShowTab(){
	$('#'+tabOldId).fadeTo(0,0).hide()
	$('#'+tabActId).show().stop().fadeTo('fast',1)
	tabOldId=tabActId
}
/*--------------------------------------------
	funcPopup [ポップアップ]
--------------------------------------------*/
function funcPopup(){
	$(".popup").click(function(){	
		var w=window.open(this.href, "popup","width=670,height=600,resizable=yes,scrollbars=yes");
		w.focus();
		return false;
	});
}

/*--------------------------------------------
	funcBgLine [リストの背景]
--------------------------------------------*/
function funcBgLine(){
	$('.bg-line ul li:odd').css('backgroundColor','#f5f5f5')
}

/*--------------------------------------------
	funcCrossBrowser [ブラウザバグ調整]
--------------------------------------------*/
/*
function funcCrossBrowser(){

	if(navigator.userAgent.indexOf("Firefox/3.0") != -1 || navigator.userAgent.indexOf("Firefox/3.5") != -1){
		;	
	}
	
	if(navigator.userAgent.indexOf("Opera") != -1){ 
		
	}
	
	if(navigator.userAgent.indexOf("Mac") != -1 && navigator.userAgent.indexOf("Safari") != -1 ){ 
		
	}
	
	if(navigator.userAgent.indexOf("Mac") != -1 && navigator.userAgent.indexOf("Firefox") != -1 ){
		
	}	
	
	if(navigator.userAgent.indexOf("iPad") != -1){
		
	}	

}
*/
