var SLB_cnt = 0;

function SLB_show(url, type) {
	try {
		var a = $('SLB_film');
		var b = $('SLB_content');
		var c = $('SLB_loading');
//		var a = document.getElementById('SLB_film');
//		var b = document.getElementById('SLB_content');
//		var c = document.getElementById('SLB_loading');

		if(url) {
			a.setStyle({
				top: '0',
				left: '0',
				background: '#B3B3B3',
				display: 'block',
				height: document.body.scrollHeight + "px",
				width: document.body.scrollWidth + "px"
			})
			a.style.filter="Alpha(opacity=80)";//0¿¡ °¡±î¿ï¼ö·Ï Åõ¸í 100¿¡ °¡±î¿ï¼ö·Ï ºÒÅõ¸í
			c.show();
			SLB_setCenter(c,true);
			if(type == 'image') {
				b.innerHTML="<img src=" + url + " class='SLB_center' onload='SLB_setCenter(this);' style='border:5px solid #FF9933'>";
				if(arguments[2]) a.onclick = function () {
					SLB_show()
				};
				if(arguments[3]) b.innerHTML += "<div class='SLB_caption'>"+ arguments[3] +"<\/div>";
			} else if (type='html') {
				b.innerHTML = url;
				SLB_setCenter(b.firstChild);
				if(arguments[2]) b.onclick = "";
			}
			hideSelect();
		} else {
			a.onclick = "";
			a.hide();
			b.innerHTML = "";
			b.onclick = function () {
				SLB_show()
			};
			c.hide();
			showSelect();
			SLB_cnt = 0;
		}
	} catch(e) {
		alert("SLB_show: " + e);
	}
}

function SLB_setCenter(obj) {
	try {
		if(obj) {
			/*
			var sizeX=1000;
			if(obj.width > sizeX) {
				Rate=obj.width/sizeX;nHeight=obj.height/Rate;if(Rate>0) {
					obj.width=sizeX;obj.height=nHeight;
				}
			}
			*/
			var h = window.innerHeight || self.innerHeight || document.body.clientHeight;
			//alert("h: " + h);
			var w = window.innerWidth || self.innerWidth || document.body.clientWidth;
			//alert("w: " + w);
			var l = (document.body.scrollLeft + ((w-(obj.width||parseInt(obj.style.width)||obj.offsetWidth))/2));
			//alert("l: " + l);
			var t = (document.body.scrollTop + ((h-(obj.height||parseInt(obj.style.height)||obj.offsetHeight))/2));
			//alert("t: " + t);
			if((obj.width||parseInt(obj.style.width)||obj.offsetWidth) >= w) {
				l = 0;
			}
			if((obj.height||parseInt(obj.style.height)||obj.offsetHeight) >= h) {
				t = document.body.scrollTop;
			}
			$('SLB_content').setStyle({
				left: l + "px"
			})
			if(SLB_cnt == 0) {
				$('SLB_content').setStyle({
					top: t + "px"
				})
				if($('SLB_content').offsetHeight >= h) {
					SLB_cnt++;
				}
			}
			obj.style.visibility = 'visible';
			if(obj.nextSibling && (obj.nextSibling.className == 'SLB_close' || obj.nextSibling.className == 'SLB_caption')) {
				obj.nextSibling.show();
				if($('SLB_content').offsetHeight < h) {
					$('SLB_content').style.top = parseInt($('SLB_content').style.top) - (obj.nextSibling.offsetHeight/2) + "px";
				}
			}
			if(!arguments[1]) {
				$('SLB_loading').hide();
			} else {
				obj.style.left = l + "px";
				obj.style.top = t + "px";
			}
		}
	} catch(e) {
//		alert("SLB_setCenter: " + e);
	}
}

function hideSelect() {
	var windows = window.frames.length;
	var selects = $$("SELECT");
	for (i=0;i < selects.length ;i++ ) {
		selects[i].style.visibility = "hidden";
	}

	if (windows > 0) {
		for(i=0; i < windows; i++) {
			try {
				var selects = window.frames[i].$$("SELECT");
				for (j=0;j<selects.length ;j++ ) {
					selects[j].style.visibility = "hidden";
				}
			} catch (e) {
			//	alert(e);
			}
		}
	}
}

function showSelect() {
	var windows = window.frames.length;
	var selects = $$("SELECT");
	for (i=0;i < selects.length ;i++ ) {
		selects[i].style.visibility = "visible";
	}

	if (windows > 0) {
		for(i=0; i < windows; i++) {
			try {
				var selects = window.frames[i].$$("SELECT");
				for (j=0;j<selects.length ;j++ ) {
					selects[j].style.visibility = "visible";
				}
			} catch(e) {
			//	alert(e);
			}
		}
	}
}

var prevOnScroll = window.onscroll;

window.onscroll = function () {
	if(prevOnScroll != undefined) {
		prevOnScroll();
	}
	try {
		$('SLB_film').setStyle({
			width: document.body.scrollWidth + "px",
			height: document.body.scrollHeight + "px"
		})
		SLB_setCenter($('SLB_content').firstChild);
	} catch(e) {
		//alert(e);
	}
}

var prevOnResize = window.onresize;

window.onresize = function () {
	if(prevOnResize != undefined) {
		prevOnResize();
	}
	try {
		$('SLB_film').setStyle({
			width: document.body.offsetWidth + "px",
			height: document.body.offsetHeight + "px"
		})
		SLB_setCenter($('SLB_content').firstChild);
	} catch(e) {
		//alert(e);
	}
}