var cookieName = "NIMSIntraFontSize";

var sizeCSS = {
	"s":"/nsnet/common/css/fontsize_s.css",
	"m":"/nsnet/common/css/fontsize_m.css",
	"l":"/nsnet/common/css/fontsize_l.css"
};


function Initialize(){
	initLightbox();
	initFuncButton();
}

function PrintPage(){
	if(document.getElementById || document.layers){
		window.print();
	}
}

function initFuncButton(){
	$("li.print a").click(function(event){
	PrintPage();});
	$("a.scrollTop").click(function(event){
	scrollToTop(); return false;});
	$("a.fontChg").click(function(event){
	chgFontSize($(this).attr('id').substr(5));});
}


function chgFontSize(size){
	if(size){
		document.cookie = cookieName+"="+size+";path=/;";
	}else{
		size = 'm';
	}
	//$("body").addClass(sizeCSS[size]);
	$('#fontSizeCSS').attr('href',sizeCSS[size]);
}



function initFontsize(){
	var cookie = document.cookie+";";
	if(cookie.indexOf(cookieName) != -1){
		var buf = cookie.substring(cookie.indexOf(cookieName),cookie.length);
		var start = buf.indexOf("=");
		var end = buf.indexOf(";");
		var size = buf.substring(start+1,end);
		chgFontSize(size);
	}else{
		chgFontSize();
	}
}

initFontsize();

function initLightbox(){
	if($("div.textset .lightbox").size() > 0){
		$('div.textset .lightbox').lightBox();
	}
	if($("div.imageset .lightbox").size() > 0){
		$("div.imageset .lightbox").lightBox();
	}
	if($("div.tableset .lightbox").size() > 0){
		$("div.tableset .lightbox").lightBox();
	}
}

function scrollToTop() {
	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 / 1.4), Math.floor(y / 1.4));
	if (x > 0 || y > 0) {
		window.setTimeout("scrollToTop()", 10);
	}
}

$(document).ready(Initialize);


