
$(function () {
	$.actionSet.copyright();
	$.actionSet.naviHover();
	$.actionSet.blanklink();
	$.actionSet.pageScroll();
	$.actionSet.popUpWindow();
	$.actionSet.windowClose();
	$.actionSet.ie6PicCatch();
});

$.actionSet = {
	
	copyright:function(options){
		var data = new Date();
		var now_year = data.getFullYear();
		//var now_year = "getFullYear";
		$("#NowYear").text(now_year);
	},
	
	naviHover: function(options) {
		$(".jsRollOver img, #navGlobal ul a img.hover, #navLocal a img.hover, ul.navInfo a img, #navAssistFooter a img, .sectionFrameC ul li img, #knowIndex img, #navTrd img").each(function() {
			var off = this.src;
			var dot = this.src.lastIndexOf('.');
			var on = this.src.substr(0, dot) +
				'_on' + this.src.substr(dot, 4);
			$(this).hover(
				function() { this.src = on; },
				function() { this.src = off; });
		});
	},
	
	blanklink: function(options) {
		$('a.external,a.pdf').click(function(){
			window.open(this.href, '_blank');
			return false;
		});
	},
	
	pageScroll: function(options) {
		jQuery.easing.quart = function (x, t, b, c, d) {
			return -c * ((t=t/d-1)*t*t*t - 1) + b;
		};
		
		$('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 pos = $target;
					scrollAction("Anchor",pos);
				}
			}
		});
		
		$('#navPage .navDown').click(function() {scrollAction("down");});
		$('#navPage .navUp').click(function() {scrollAction("up");});
		
		function scrollAction(updown,target){
			//alert(target);
			var moveTime =500;
			var movePos = $("html").attr("clientHeight");
			var thisOffset = $("html").scrollTop();
			var get_posWin = $(window).scrollTop();
			if(updown=="Anchor")var targetOffset = target.offset().top;
			if(updown=="up")var targetOffset = get_posWin - (movePos+50);
			if(updown=="down")var targetOffset = get_posWin + (movePos-50);
			var movePage = Math.abs(thisOffset-targetOffset)/3000;
			movePage = movePage.toFixed(1);
			if(1>=movePage)movePage=1;
			moveTime = moveTime * movePage;
				if(!jQuery.browser["opera"])$('html,body').animate({scrollTop: targetOffset}, moveTime, "quart");
				if(jQuery.browser["opera"])$('html,body').scrollTop(targetOffset);
			return false;
		}
		
	},
	
	popUpWindow: function(options) {
		//memo:.html?name=popupName&scroll=1&width=555&height=555
		$('a.popup').click(function(){
			var queryString = this.href.replace(/^[^\?]+\??/, "");
			var params = parseQuery(queryString);
			var url = this.href.split("?")[0];
			var winName = String(params["name"]);
			var winScroll = Number(params["scroll"]);
			var winWidth = Number(params["width"]);
			var winHeight = Number(params["height"]);
			if(isNaN(winWidth)) {
				if(document.all) {
					if(document.documentElement && document.documentElement.clientHeight) { //for IE6 Strict Mode
						winWidth = document.documentElement.clientWidth;
					} else if(document.body) {
						winWidth = document.body.clientWidth;
					}
				} else if(document.layers || document.getElementById) {
					winWidth = window.innerWidth;
				}
			}
			if(isNaN(winHeight)) {
				if(document.all) {
					if(document.documentElement && document.documentElement.clientHeight) { //for IE6 Strict Mode
						winHeight = document.documentElement.clientHeight;
					} else if(document.body) {
						winHeight = document.body.clientHeight;
					}
				} else if(document.layers || document.getElementById) {
					winHeight = window.innerHeight;
				}
			}
		
			var centerW = (window.screen.width-winWidth)/2;
			var centerH = (window.screen.height-winHeight)/2;
			var newWindow;
			newWindow = window.open(url, winName, "toolbar=0, location=0, directories=0, status=0, menubar=1, resizable=yes, scrollbars=" + winScroll + ", width=" + winWidth + ", height=" + winHeight + ", left=" + centerW + ", top=" + centerH + "");
			newWindow.focus();
			return false; 
		});
		function parseQuery ( query ) {
		   var Params = {};
		   if ( ! query ) {return Params;}// return empty object
		   var Pairs = query.split(/[;&]/);
		   for ( var i = 0; i < Pairs.length; i++ ) {
			 var KeyVal = Pairs[i].split('=');
			 if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
			 var key = unescape( KeyVal[0] );
			 var val = unescape( KeyVal[1] );
			 val = val.replace(/\+/g, ' ');
			 Params[key] = val;
		   }
		   return Params;
		}
	},
	
	windowClose: function(options) {
		$("a.close").click(function(){
			window.close();
		});		
	},
	
	ie6PicCatch: function(options){//IE画像表示処理
		try {
		document.execCommand('BackgroundImageCache', false, true);
		} catch(e) {}
	}
	
}


