//************************
//google analyitics
//************************
/*
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-20001890-1']);
_gaq.push(['_trackPageview']);

(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
*/

//************************
//実行
//************************
$(document).ready(function(){
	pageScroll(".to-top","#container");
	smartRollover();
	fragment();
	nav();
	frag();
	tabNavi();
	jqypopup();
	
});
	

//************************
//関数
//************************

//スマートロールオーバー http://css-happylife.com/archives/2007/0621_0010.php
//---------------------------
var smartRollover = function () {  
	if(document.getElementsByTagName) {  
		var images = document.getElementsByTagName("img");  
			for(var i=0; i < images.length; i++) {  
				if(images[i].getAttribute("src").match("_off.")){  
					images[i].onmouseover = function() {  
					this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));  
				}
				images[i].onmouseout = function(){
					this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));  
					}
				}
			}
		}  
}


//Fragment Navigation
var fragment = function(){
	$(".fragment-nav li a").click(function(){
		var target = $(this).attr("href");
		
		if(target.indexOf("#") != -1 ){
			$(this).blur();
			$('html,body').animate({ scrollTop: $(target).offset().top }, 'fast');
			return false;
		}
	});
}
var frag = function(){
	$(".fragment").click(function(){
		var target = $(this).attr("href");
		
		if(target.indexOf("#") != -1 ){
			$(this).blur();
			$('html,body').animate({ scrollTop: $(target).offset().top }, 'fast');
			return false;
		}
	});
}

//ナビゲションのカレント表示

var nav = function(){
	var docClass = $("body").attr("class");
	var loc = location.href;
	var replaceImg = [];
		
		if(loc.indexOf("/ja/") != -1){
					replaceImg = ["/ja/common/images/nav/nav0_cr.gif","/ja/common/images/nav/nav1_cr.gif","/ja/common/images/nav/nav2_cr.gif","/ja/common/images/nav/nav3_cr.gif","/ja/common/images/nav/nav4_cr.gif"];
		}else if(loc.indexOf("/en/") != -1){
					replaceImg = ["/en/common/images/nav/nav0_cr.gif","/en/common/images/nav/nav1_cr.gif","/en/common/images/nav/nav2_cr.gif","/en/common/images/nav/nav3_cr.gif"];
		}
		
		if(docClass == "products"){
		$("#nav li:eq(0) img").attr("src",replaceImg[0]);
		}
		if(docClass == "corporate"){
		$("#nav li:eq(1) img").attr("src",replaceImg[1]);
		}
		if(docClass == "ir"){
		$("#nav li:eq(2) img").attr("src",replaceImg[2]);
		}
		if(docClass == "recruit"){
		$("#nav li:eq(3) img").attr("src",replaceImg[3]);
		}
		if(docClass == "procurement"){
		$("#nav li:eq(4) img").attr("src",replaceImg[4]);
		}
}



//スマートスクロール
//---------------------------
var pageScroll = function (trg,target){
	$(trg).click(function () {
		$(this).blur();
		$('html,body').animate({ scrollTop: $(target).offset().top }, 'fast');
		return false;
	});
}


//タブナビゲーション
//---------------------------
var tabNavi = function (){
	// 初期設定

		// #nav直下の全li要素の中から最初のli要素に.selectを追加
		$("#lineup-navi > li:first").addClass("select");
		// #nav直下の全li要素にマウスオーバーしたらリンク要素に偽装
		$("#lineup-navi > li").hover(function(){
			$(this).css("cursor","pointer");
		},function(){
			$(this).css("cursor","default");
		});

		// #tab直下の全div要素を非表示
		$("div.lineup-data").hide();
		// #tab直下の全div要素の中から最初のdiv要素を表示
		$("div.lineup-data:first").show();

	// タブ切替処理
	$("#lineup-navi > li").click(function () {
		// #nav直下の全li要素のclass属性を削除
		$("#lineup-navi > li").removeClass("select");
		// クリックしたli要素に.selectを追加
		$(this).addClass("select");
		// #tab直下の全div要素を非表示
		$("div.lineup-data").hide();
		// クリックしたタブのインデックス番号と同じdiv要素をフェード表示
		$("div.lineup-data").eq($("#lineup-navi > li").index(this)).fadeIn();
	});

}



//ポップアップウィンドウ
//---------------------------
var jqypopup = function (){
//Select all anchor tag with rel set to tooltip
	$('a[rel=tooltip]').mouseover(function(e) {
		
		//Grab the title attribute's value and assign it to a variable
		var tip = $(this).attr('title');	
		
		//Remove the title attribute's to avoid the native tooltip from the browser
		$(this).attr('title','');
		
		//Append the tooltip template and its value
		$(this).append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div><div class="tipFooter"></div></div>');		
				
		//Show the tooltip with faceIn effect
		$('#tooltip').fadeIn('500');
		$('#tooltip').fadeTo('10',0.9);
		
	}).mousemove(function(e) {
	
		//Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
		$('#tooltip').css('top', e.pageY + 10 );
		$('#tooltip').css('left', e.pageX + 20 );
		
	}).mouseout(function() {
	
		//Put back the title attribute's value
		$(this).attr('title',$('.tipBody').html());
	
		//Remove the appended tooltip template
		$(this).children('div#tooltip').remove();
		
	});
}
