// rollOvers
function rollOvers() {

	// グローバルナビのnow表示
	globalNav();

	// 下層ページのサイドナビ部分のnow表示
	var whereSide = $("body").attr("class");
	if(whereSide === "secondaries") {
		contentsNav();	
	};

	var image_cache = new Object();
	$("img.swap, input.swap").each(function(i) {
		var imgsrc = this.src;
		var dot = this.src.lastIndexOf('.');
		var imgsrc_ov = this.src.substr(0, dot) + '_ov' + this.src.substr(dot, 4);
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_ov;
		$(this).hover(function() { this.src = imgsrc_ov; },function() { this.src = imgsrc; });
	});
};





// globalNav now グローバルナビのnow表示
function globalNav() {
	$("#globalNavi ul").each(function() {
		var where = $("body").attr("id");
		var here = "glbl_" + where;
		$("li", this).each(function(index){
			//var $this = $(this);
			var hereIs = $(this).attr("id");
			var hereIsId = "#" + hereIs;
			if (hereIs === here) {
				$(hereIsId + " img").removeClass();
				var imgsrc = $(hereIsId + " img").attr("src");
				var dot = imgsrc.lastIndexOf('.');
				var imgsrc_ov = imgsrc.substr(0, dot) + '_ov' + imgsrc.substr(dot, 4);
				$(hereIsId+" img").attr("src", imgsrc_ov);
			}
			else {
				return;
			}
		});
	});
};





// contentsNav now 下層ページのサイドナビ部分のnow表示
function contentsNav() {
	// タイトルのnow表示
	ttlNav();

	// 子リストのオープン
	//openChildList();

	$(".sideNavi ul.sideNaviList").each(function() {
		var here = "navi_" + $(".sideNavi").attr("id");
		$("li", this).each(function(index){
			var hereIs = $(this).attr('id');
			var hereIsId = "#" + hereIs;

			// now表示
			if (hereIs === here) {
				$(hereIsId + " a img").removeClass();
				var imgsrc = $(hereIsId + " a img").attr("src");
				var dot = imgsrc.lastIndexOf('.');
				var imgsrc_now = imgsrc.substr(0, dot) + '_now' + imgsrc.substr(dot, 4);
				$(hereIsId + " img").attr("src", imgsrc_now);
				if(here == "navi_side_message"||here == "navi_side_safetyguidlines"||here == "navi_side_recruit"){
					$(".sideNavi h2 a img").removeClass();
					var imgsrch2 = $(".sideNavi h2 a img").attr("src");
					var dot = imgsrch2.lastIndexOf('.');
					var imgsrc_ovh2 = imgsrch2.substr(0, dot) + '_ov' + imgsrch2.substr(dot, 4);
					$(".sideNavi h2 a img").attr("src", imgsrc_ovh2);
				} else {
					return;
				};
			} else {
				return;
			};

		});
	});
};





// ttlNav タイトルのnow表示
function ttlNav(){
	var here = "navi_" + $(".sideNavi").attr("id");
	var hereIs = $(".sideNavi h2").attr("id");
	var hereIsId = "#" + hereIs;

	// now表示
	if (hereIs === here) {
		$(hereIsId + " a img").removeClass();
		var imgsrc = $(hereIsId + " a img").attr("src");
		var dot = imgsrc.lastIndexOf('.');
		var imgsrc_ov = imgsrc.substr(0, dot) + '_ov' + imgsrc.substr(dot, 4);
		$(hereIsId + " img").attr("src", imgsrc_ov);
	} else {
		return;
	};
};





// bannerRollOvers ファイル名に「bnr_」が含まれる画像でロールオーバする
function bannerRollOvers(){
	$("a img").mouseover(function(){
		if ($(this).attr("src").match(/bnr_/)) {
					$(this).stop().fadeTo("fast", 0.7);
				}
				else {
					return;
				}
	});
	$("a img").mouseout(function(){
		if ($(this).attr("src").match(/bnr_/)) {
					$(this).stop().fadeTo("slow", 1);
				}
				else {
					return;
				}
	});
};





// thisYear 今年（西暦）の取得
function thisYear(){
	var day = new Date();
	var year = day.getFullYear();
	$('span.year').text(year);
};





// windowPopup
function windowPopup(URL,windowName,features) {
  window.open(URL,windowName,features);
};





// printThis
function printThis() {
	this.print();
};





// drivenTopMv
function drivenTopMv(){
	var bdyId = $("body").attr("id");
	if(bdyId === "toppage"){
		var linkTxt = new Array(3);
		linkTxt[0] = "ケミカル船";
		linkTxt[1] = "LPG船";
		linkTxt[2] = "航海図";
		$('.carrousel').cycle({
			fx: 'fade',
			pager: '#nav',
			timeout: 7000,
			pagerAnchorBuilder: function(index, DOMelement) {
				return '<li id="mvNav-'+(index+1)+'"><a id="mvNavA-'+(index+1)+'" href="#">'+(linkTxt[index])+'</a></li>';
			}
		});
	} else {
		return;
	}
};





// ページ読込時に実行
$(document).ready(function() {

	// トップスクリプト処理の読み込み
	drivenTopMv();

	// rollover
	rollOvers();

	// bannerRollOver
	bannerRollOvers();

	// year
	thisYear();

});

