var SLB_cnt = 0;

function SLB(url, type) {
	var a = document.getElementById("SLB_film");
	var b = document.getElementById("SLB_content");
	var c = document.getElementById("SLB_loading");
	if (url) {
		a.style.top = 0;
		a.style.left = 0;
		a.style.display = "";
		if (document.documentElement.scrollHeight > document.body.scrollHeight) {
			a.style.height = document.documentElement.scrollHeight + "px";
		} else {
			a.style.height = document.body.scrollHeight + "px";
		}
		c.style.display = "block";
		SLB_setCenter(c, true);
		if (type == "image") {
			b.innerHTML = "<img src=" + url + " class='SLB_center' onload='SLB_setCenter(this);' />";
			if (arguments[2]) a.onclick = function (){SLB()};
			if (arguments[3]) b.innerHTML += "<div class='SLB_caption'>" + arguments[3] + "</div>";
		} else if (type == "iframe") {
			b.innerHTML = "<iframe id='SLB_iframe' name='SLB_iframe' src=" + url + " width=" + arguments[2] + " height=" + arguments[3] + " class='SLB_center' marginwidth='0' marginheight='0' frameborder='0' vspace='0' hspace='0' onload='tryReHeight(" + arguments[5] + ");'/></iframe>";
			if (arguments[4]) {
				b.innerHTML += "<div class='SLB_close' onclick='SLB();' title='´Ý±â'>close</div>";
			}
			b.onclick = "";
			b.firstChild.style.cursor = "default";
		} else if (type == "html") {
			//alert(url);
			b.innerHTML = url;
			SLB_setCenter(b.firstChild);
			if (arguments[2]) b.onclick = "";
		}
		hideSelect();
	} else {
		a.onclick = "";
		a.style.display = "none";
		a.style.height = "100%";
		a.style.width = "100%";
		b.innerHTML = "";
		b.onclick = function() {SLB()};
		c.style.display = "none";
		showSelect();
		SLB_cnt = 0;
	}
}

function SLB_setCenter(obj) {
	if (obj) {
		var h = (window.innerHeight || self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight);
		var w = (window.innerWidth || self.innerWidth || document.documentElement.clientWidth || document.body.clientWidth);
		var l = ((window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft) + ((w - (obj.width || parseInt(obj.style.width) || obj.offsetWidth)) / 2));
		var t = ((window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop) + ((h - (obj.height || parseInt(obj.style.height) || obj.offsetHeight)) / 2));
		if ((obj.width || parseInt(obj.style.width) || obj.offsetWidth) >= w) l = 0;
		if ((obj.height || parseInt(obj.style.height) || obj.offsetHeight) >= h) t = (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop);
		document.getElementById("SLB_content").style.left = l + "px";
		if (SLB_cnt == 0) {
			document.getElementById("SLB_content").style.top = t + "px";
			if (document.getElementById("SLB_content").offsetHeight >= h - 20) {
				SLB_cnt++;
			}
			if (obj.nextSibling && (obj.nextSibling.className == "SLB_close" || obj.nextSibling.className == "SLB_caption")) {
				obj.nextSibling.style.display = "block";
				if ((t - (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop)) > (obj.nextSibling.offsetHeight/2)) {
					document.getElementById("SLB_content").style.top = parseInt(document.getElementById("SLB_content").style.top) - (obj.nextSibling.offsetHeight/2) + "px";
				}
			}
		}
		obj.style.visibility = "visible";
		if (!arguments[1]) {
			document.getElementById("SLB_loading").style.display = "none";
		} else {
			obj.style.left = l + "px";
			obj.style.top = t + "px";
		}
	}
}

function hideSelect() {
	var windows = window.frames.length;
	var selects = document.getElementsByTagName("SELECT");
	for (var i = 0; i < selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
	if (windows > 0) {
		for (var i = 0; i < windows; i++) {
			try {
				var selects = window.frames[i].document.getElementsByTagName("SELECT");
				for (var j = 0; j < selects.length; j++) {
					selects[j].style.visibility = "hidden";
				}
			} catch(e) {}
		}
	}
}

function showSelect() {
	var windows = window.frames.length;
	var selects = document.getElementsByTagName("SELECT");
	for (var i = 0; i < selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
	if (windows > 0) {
		for (var i = 0; i < windows; i++) {
			try {
				var selects = window.frames[i].document.getElementsByTagName("SELECT");
				for (var j = 0; j < selects.length; j++) {
					selects[j].style.visibility = "visible";
				}
			} catch(e) {}
		}
	}
}

function tryReHeight(sign) {
	var strAgent = navigator.userAgent.toLowerCase();
	//alert(strAgent);
	var bIE = (strAgent.indexOf("msie") != -1);
	var bIE7 = (strAgent.indexOf("msie 7.0") != -1);
	var bIE8 = (strAgent.indexOf("msie 8.0") != -1);
	var bChrome = (strAgent.indexOf("chrome") != -1);
	var bFirefox = (strAgent.indexOf("firefox") != -1);
	var bSafari = (strAgent.indexOf("konqueror") != -1 || strAgent.indexOf("safari") != -1);

	var FFextraWidth = 0;
	var FFextraHeight = 0;
	if (bChrome) {
		FFextraWidth = 17;
		FFextraHeight = 0;
	} else if (bFirefox) {
		FFextraWidth = 17;
		FFextraHeight = 0;
	} else if (bIE8 || bIE7 || bIE) {
		FFextraHeight = 1;
	}

	var currentfr = document.getElementById("SLB_iframe");
	if (sign == true) {
		try {
			/*if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) {
				setIframeSize(currentfr.contentDocument.body.offsetHeight + FFextraHeight);
			} else if (currentfr.Document && currentfr.Document.body.scrollHeight) {
				setIframeSize(currentfr.Document.body.scrollHeight);
			}*/
			/*if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) {
				//alert(currentfr.contentDocument.body.offsetWidth + "+" + FFextraWidth);
				setIframeSize(currentfr.contentDocument.body.offsetHeight + FFextraHeight, currentfr.contentDocument.body.offsetWidth + FFextraWidth);
			} else if (currentfr.Document && currentfr.Document.body.scrollHeight) {
				setIframeSize(currentfr.Document.body.scrollHeight, currentfr.Document.body.scrollWidth);
			}*/

			/* »ç¿ëÁ¶°Ç : ÆäÀÌÁö°£ ÀÌµ¿½Ã °¡·Î»çÀÌÁî ÅëÀÏ, Å©·Ò¿¡¼­´Â ¼¼·Î»çÀÌÁî Á¶Àý¾ÈµÊ */
			if (bIE || bIE7 || bIE8) {
				setIframeSize(currentfr.contentWindow.document.body.scrollHeight + FFextraHeight, currentfr.contentWindow.document.body.scrollWidth);
			} else if (bFirefox) {
				setIframeSize(currentfr.contentWindow.document.body.offsetHeight + FFextraHeight, currentfr.contentWindow.document.body.scrollWidth);
			} else {
				//setIframeSize(window.frames[0].document.body.scrollHeight, currentfr.contentWindow.document.body.scrollWidth);
				setIframeSize(currentfr.contentWindow.document.body.offsetHeight + FFextraHeight, currentfr.contentWindow.document.body.scrollWidth);
			}
		} catch(e) { }
	} else {
		SLB_setCenter(currentfr);
	}
}

function setIframeSize(h, w) {
	SLB_cnt = 0;
	var ifr = currentfr = document.getElementById("SLB_iframe");
	if (ifr) {
		if (w) {
			ifr.width = w;
		}
		if (h) {
			ifr.height = h;
		}
		SLB_setCenter(ifr);
	}
}

var prevOnScroll = window.onscroll;
window.onscroll = function() {
	if (prevOnScroll != undefined) prevOnScroll();
	if (document.documentElement.scrollHeight > document.body.scrollHeight) {
		document.getElementById("SLB_film").style.height = document.documentElement.scrollHeight + "px";
	} else {
		document.getElementById("SLB_film").style.height = document.body.scrollHeight + "px";
	}
	document.getElementById("SLB_film").style.width = document.body.scrollWidth + "px";
	SLB_setCenter(document.getElementById("SLB_content").firstChild);
}

var prevOnResize = window.onresize;
window.onresize = function() {
	if (prevOnResize != undefined) prevOnResize();
	if (document.documentElement.scrollHeight > document.body.scrollHeight) {
		document.getElementById("SLB_film").style.height = document.documentElement.scrollHeight + "px";
	} else {
		document.getElementById("SLB_film").style.height = document.body.scrollHeight + "px";
	}
	document.getElementById("SLB_film").style.width = document.body.offsetWidth + "px";
	SLB_setCenter(document.getElementById("SLB_content").firstChild);
}
