/*============================================================================================*
/* 確認用のデータ読み込み
/*============================================================================================*/
function confingSetup() {
	document.write('<script type="text/javascript" src="http://test2.localhost/add_note/dump.js" charset="utf-8"></script>');
	document.write('<link rel="stylesheet" type="text/css" href="../../../css/print.css"  media="all" />');
	document.write('<link rel="stylesheet" type="text/css" href="../../css/print.css"  media="all" />');
	document.write('<link rel="stylesheet" type="text/css" href="../css/print.css"  media="all" />');
	document.write('<link rel="stylesheet" type="text/css" href="css/print.css"  media="all" />');
}
//confingSetup();
/*============================================================================================*/
/*============================================================================================*/

$(function () {
	/**/
	//$.actionSet.copyright();
	//$.actionSet.naviHover();
	$.actionSet.blanklink();
	$.actionSet.pageScroll();
	$.actionSet.popUpWindow();
	$.actionSet.windowClose();
	$.actionSet.ie6PicCatch();
	$.actionSet.naviAction();
	$.actionSet.boxAction();
	$.actionSet.topicsAction();
	/**/
	$.actionSet.tab();
});

$.actionSet = {
	
	copyright:function(options){
		var data = new Date();
		var now_year = data.getFullYear();
		//var now_year = "getFullYear";
		$("#NowYear").text(now_year);
	},
	
	naviHover: function(options) {
		$("#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);
					return false;
				}
			}
		});
		
		$('#navPage .navDown').click(function() {scrollAction("down");});
		$('#navPage .navUp').click(function() {scrollAction("up");});
		
		var yScroll = document.body.offsetHeight;
		if( yScroll <= 800){ $('#navPage').css({'display':'none'});}
		 
		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.popUpWindow').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) {}
	},
	
	naviAction: function(options){
			$('#navGlobal > li.hover,.subMenu > li.hover').css({backgroundPosition: "0 0"})
			.mouseover(function(){$(this).stop().animate({backgroundPosition:"(242px 0)"}, {duration:300})})
			.mouseout(function(){$(this).stop().animate({backgroundPosition:"(0 0)"},{duration:300, complete:function(){
				$(this).css({backgroundPosition: "0 0"})
			}})})
	},
	
	boxAction: function(options){
		$('#categoryInfo .sectionItem').css({backgroundColor:'#FFF'});
		$("#categoryInfo .sectionItem ,.cgiBox")
		.mouseover(function(){
			$(this).stop().animate( { backgroundColor: '#CECECE'}, 300);
		})
		.mouseout(function(){
			$(this).stop().animate( { backgroundColor: '#FFFFFF'}, 300);
		});
	},
	
	topicsAction: function(options){
		var openFlag;
		openFlag=true;

		$().oneTime(5555, function closeTopic(){
				$("#topics .topicsBox").animate({ width: "1px", height: "65px", opacity: 1 }, 1000 );
				$('#navTab').css({ background: 'url(img/nav/topic-active.gif) 0 12px'});
				openFlag=false;
		});
		
		$('#navTab').click(function(){
			//console.log("トピックスクリック:"+openFlag);
			if(openFlag){
				$("#topics .topicsBox").animate({ width: "1px", height: "65px", opacity: 1 }, 800 );
				$('#navTab').css({ background: 'url(img/nav/topic-active.gif) 0 12px'});
				openFlag=false;
				}else{
				$("#topics .topicsBox").animate({ width: "480px", height: "65px", opacity: 1 }, 800 );
				$('#navTab').css({ background: 'url(img/nav/topic.gif) 0 12px'});
				openFlag=true;
				}
			//return false;
		});
	},
	
	Uri: function(path){
		this.originalPath = path;
		//絶対パスを取得
		this.absolutePath = (function(){
			var e = document.createElement('span');
			e.innerHTML = '<a href="' + path + '" />';
			return e.firstChild.href;
		})();
		//絶対パスを分解
		var fields = {'schema' : 2, 'username' : 5, 'password' : 6, 'host' : 7, 'path' : 9, 'query' : 10, 'fragment' : 11};
		var r = /^((\w+):)?(\/\/)?((\w+):?(\w+)?@)?([^\/\?:]+):?(\d+)?(\/?[^\?#]+)?\??([^#]+)?#?(\w*)/.exec(this.absolutePath);
		for (var field in fields) {
			this[field] = r[fields[field]]; 
		}
	},
	
	tab: function(options) {		
		//$('.showArea').css({overflow:'hidden'});
		var c = $.extend({
			tabNavSelector:'.tabNav',
			activeTabClass:'active'
		}, options);
		$(c.tabNavSelector).each(function(){
			var tabNavList = $(this).find('a[href^=#], area[href^=#]');
			var tabBodyList;
			tabNavList.each(function(){
				this.hrefdata = new $.actionSet.Uri(this.getAttribute('href'));
				//alert(this.hrefdata['fragment']);
				var selecter = '#'+this.hrefdata.fragment;
				if (tabBodyList) {
					tabBodyList = tabBodyList.add(selecter);
				} else {
					tabBodyList = $(selecter);
				}
				$(this).unbind('click');
				$(this).click(function(){
					tabNavList.removeClass(c.activeTabClass);
					$(this).addClass(c.activeTabClass);
					tabBodyList.hide();
					$(selecter).show();
					return false;
				});
			});
			tabBodyList.hide();
			$("#tab1").show();
			//tabNavList.filter(':first').trigger('click');
			//$("body").append("<pre>"+$.dump(tabBodyList)+"</pre>");
		});
	}
	
}

