// library.js
// InternetExplorer 6 ->
// Firefox 1.5 ->
// Safari 2 ->
// Opera 9 ->

var Library = function(eid){
	// コンテンツサイズ
	this.box = null;
	this.box_mg = 50;
	// その他
	this.eid = eid;
	this.na = navigator.userAgent;
	this.tg = null;
	
};
var lb = new Library("lb");

window.onload = function() {
	window.onresize = lb.setPosW;
}

Library.prototype.setBG = function(){
	document.getElementById(lb.eid).style.width = document.body.clientWidth + "px";
	document.getElementById(lb.eid).style.height = document.documentElement.scrollHeight + "px";
	if(lb.na.indexOf("MSIE 7") >= 0) {
		if(document.documentElement.clientHeight <= document.documentElement.scrollHeight){
			document.getElementById(lb.eid).style.height = document.documentElement.scrollHeight + "px";
		} else {
			document.getElementById(lb.eid).style.height = document.documentElement.clientHeight + "px";
		}
	} else if(lb.na.indexOf("MSIE") >= 0 || lb.na.indexOf("Opera") >= 0) {
		if(document.body.clientHeight <= document.body.scrollHeight){
			document.getElementById(lb.eid).style.height = document.body.scrollHeight + "px";
		} else {
			document.getElementById(lb.eid).style.height = document.body.clientHeight + "px";
		}
	} else {
		if(window.innerHeight >= document.body.clientHeight){
			document.getElementById(lb.eid).style.height = window.innerHeight + "px";
		} else {
			document.getElementById(lb.eid).style.height = document.body.clientHeight + "px";
		}
	}
};

Library.prototype.getWindowParm = function(){
	return {
		//[BodySize]
		body_w: document.documentElement.scrollWidth || document.body.clientWidth,
		body_h: document.documentElement.scrollHeight || document.body.clientHeight,
		//[ViewSize]
		view_w: document.documentElement.clientWidth || document.body.clientWidth,
		view_h: document.documentElement.clientHeight || document.body.clientHeight,
		//[ScrollPosition]
		scroll_x: document.body.scrollLeft || document.documentElement.scrollLeft,
		scroll_y: document.body.scrollTop || document.documentElement.scrollTop
	};
};

Library.prototype.setPosH = function(){
	if(lb.tg){
		if (lb.box.height > Library.prototype.getWindowParm().view_h - 50) { 
			document.getElementById(lb.tg).style.top = Library.prototype.getWindowParm().scroll_y + 50 + "px";
		} else {
			document.getElementById(lb.tg).style.top = (Library.prototype.getWindowParm().view_h/2 - lb.box.height/2) + Library.prototype.getWindowParm().scroll_y + "px";
		}
		lb.setPosW();
	}
}
Library.prototype.setPosW = function(){
	lb.setBG();
	if(lb.tg){
		document.getElementById(lb.tg).style.left = (Library.prototype.getWindowParm().body_w/2 - lb.box.width/2) + "px";
	}
}

Library.prototype.showBox = function(tg){
	lb.tg = tg;
	document.getElementById(lb.eid).style.display = "block";
	lb.setBG();
	document.getElementById(lb.eid).onclick = function(){
		lb.close();
	};
	lb.box = Element.getDimensions($(lb.tg));
	document.getElementById(lb.tg).style.position = "absolute";
	document.getElementById(lb.tg).style.height = lb.box.height + "px";
	document.getElementById(lb.tg).style.display = "block";
	lb.setPosH();
};

Library.prototype.close = function(){
	document.getElementById(lb.tg).style.display = "none";
	document.getElementById(lb.eid).style.width = "0";
	document.getElementById(lb.eid).style.height = "0";
	document.getElementById(lb.eid).style.display = "none";
	lb.tg = null;
}