(function($){
	$(function(){
		//ポップアップしたページは印刷用スタイルを適用
		printStyleSet();
		//プリンタフレンドリー処理
		$.styleChanger();
		// ページの先頭へ処理
		$.backtoTop();
		// ウィンドウクローズ処理
		$.winClose();
	});

	//印刷用スタイル
	function printStyleSet(){
		var str = String(window.location);
		//for IE6用。基本的には/os/file/50OS/css/global/print.cssに定義。
		if(str.match(/\?mode=print/)){
			var cssHref = "/os/file/50OS/css/global/print.css";
			$("head").append('<link rel="stylesheet" href="' + cssHref +'" type="text/css" media="all" />');
			$("body").css("zoom","1");
			$("#funcNav").remove();
			$("#globalNav").remove();
			$("#subNav").remove();
			$("#wrapper").css("width","670px");
			$("#header").css("width","670px");
			$("#header").css("height","85px");
			$("#header h1").css("margin-left","0");
			//$("#header #logo").css("margin-right","15px");
			//プリントボタンを挿入
			$("#goTop").before("<div id=\"mode-print\">");
			$("#mode-print").html("<p><a onclick=\"window.print();\" onkeypress=\"window.print();\" title=\"現在表示されているページを印刷します\">このページをプリント<\/a><\/p>");
			$("#footer dl").remove();
			$("#footer address").css("text-align","center");
			//クローズボタンを挿入
			$("#footer").after("<div id=\"windowclose\">");
			$("#windowclose").html("<p><a title=\"現在表示されているページを閉じます\"><img src=\"/os/image/50OS/global/icon_close.gif\" width=\"139\" height=\"23\" alt=\"このウィンドウを閉じる\" /><\/a><\/p>");
		}
		function removeCss(){
			$('link[href='+cssHref+']').remove();
		}
	}
	
	//プリンタフレンドリー
	$.styleChanger = function(settings){
		var c = $.extend({
						cssSelector: '#print'
		}, settings);
		
		// var cssHref = "/os/file/50OS/css/global/print.css";
		
		$(c.cssSelector).click(function(){
			//ポップアップで印刷用ページを表示
			var href = window.location;
			href = href + "?mode=print";
			window.open(href,"","width=740,location=yes,toolbar=yes,menubar=yes,scrollbars=yes,status=yes,resizable=yes");
			return false;
		});
		
		function removeCss(){
			$('link[href='+cssHref+']').remove();
		}
	}
	
	// ページの先頭へ
	$.backtoTop = function(settings){
		var c = $.extend({
						cssSelector: '#goTop a'
		}, settings);
		
		$(c.cssSelector).click(function(){
			backToTop();
			return false;
		});
	
	}
	
// ウィンドウクローズ
	$.winClose = function(settings){
		var c = $.extend({
						cssSelector: '#windowclose a'
		}, settings);
		
		$(c.cssSelector).click(function(){
			closeWin();
			return false;
		});
	
	}	
	
})(jQuery);

// ページの先頭へ
	function backToTop() {
		var x1 = x2 = x3 = 0;
		var y1 = y2 = y3 = 0;
			if (document.documentElement) {
			x1 = document.documentElement.scrollLeft || 0;
			y1 = document.documentElement.scrollTop || 0;
		}
		if (document.body) {
			x2 = document.body.scrollLeft || 0;
			y2 = document.body.scrollTop || 0;
		}
		x3 = window.scrollX || 0;
		y3 = window.scrollY || 0;
		var x = Math.max(x1, Math.max(x2, x3));
		var y = Math.max(y1, Math.max(y2, y3));
		window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));
		if (x > 0 || y > 0) {
		window.setTimeout("backToTop()", 30);
		}
}	

// ウィンドウクローズ
function closeWin(){
	window.opener = window;
	var win = window.open(location.href,"_self");
	win.close();
}


