
$(function () {
	$.actionSet.blankLink();
	$.actionSet.popUpLink();
	$.actionSet.windowClose();
	$.actionSet.pageScroll();
	$.actionSet.tableHover();	
});

$.actionSet = {

	
	blankLink: function(options) {
		$('a.external,a.pdf').click(function(){
			window.open(this.href, '_blank');
			return false;
		});
	},
	
	popUpLink: 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();
		});
	},
	
	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 targetOffset = $target.offset().top;
					var moveTime =500;
					var thisOffset = $("html").scrollTop();//
					var movePage = Math.abs(thisOffset-targetOffset)/3000;
					movePage = movePage.toFixed(1);
					if(1>=movePage)movePage=1;
					moveTime = moveTime * movePage;
					$('html,body')
					.animate({scrollTop: targetOffset}, moveTime, "quart");
					return false;
				}
			}
		});
	},
	
	tableHover: function(options) {
		//var className;
		
		$(".tableTypeA tr").hover(
			function (){
				var classNameA = $(this).attr("class");
				//alert( classNameA );
				if( classNameA != "")$("."+classNameA).children().addClass("tdHover");
			},function (){
				var classNameA =$(this).attr("class");
				if( classNameA != "")$("."+classNameA).children().removeClass("tdHover");
			}
		);
		
	}	
	
}


