var Repolo = {
	__postLoginAction__: null,
	__postUploadAction__: null,
	__postCloseFrameAction__: null,


	// ·Î±×ÀÎ µ¥ÀÌÅÍ..!
	memberData:{
		login: false,
		uid: "",
		uname: ""
	},


	layerFrame: null,
	pageLayer: null,
	disabledZone: null,
	downloadFrame: null,


	// ÆäÀÌÁö ·¹ÀÌ¾î ³»ºÎÀÇ ÇÁ·¹ÀÓ ¹ÝÈ¯
	getLayerFrame: function(){
		if( !Repolo.layerFrame ){
			Repolo.layerFrame = new Element("iframe");
			Repolo.layerFrame.id = Repolo.layerFrame.name = "__layerFrame__";
			Repolo.layerFrame.frameBorder = 0;

			Repolo.getPageLayer().appendChild( Repolo.layerFrame );
		}

		return Repolo.layerFrame;
	},


	// ÆäÀÌÁö ·¹ÀÌ¾î ¹ÝÈ¯
	getPageLayer: function(){
		if( !Repolo.pageLayer ){
			Repolo.pageLayer = new Element("div");

			Repolo.pageLayer.id = "__pageLayer__";
			Repolo.pageLayer.style.display = "none";
			Repolo.pageLayer.style.position = "absolute";
			Repolo.pageLayer.width = Repolo.pageLayer.height = 0;
			Repolo.pageLayer.style.zIndex = 9050;

			Repolo.pageLayer.page = Repolo.getLayerFrame();

			Event.observe(
				window,
				"resize",
				function(){
					Repolo.pageLayer.style.left = ( (document.body.clientWidth / 2) - (Repolo.pageLayer.width / 2) ) + "px";
					Repolo.pageLayer.style.top = ( (document.body.clientHeight / 2) - (Repolo.pageLayer.height / 2) ) + "px";
				}
			);


			document.body.appendChild( Repolo.pageLayer );
		}

		return Repolo.pageLayer;
	},
	

	// ¹ÝÅõ¸í ·¹ÀÌ¾î ¹ÝÈ¯
	getDisabledZone: function(){
		if( !Repolo.disabledZone ){
			Repolo.disabledZone = new Element("div");
			Repolo.disabledZone.id = "__divDisabledZone__";
			Repolo.disabledZone.style.zIndex = 0;
			Repolo.disabledZone.style.width = document.body.scrollWidth;
			Repolo.disabledZone.style.height = document.body.scrollHeight;
			Repolo.disabledZone.style.left = 0;
			Repolo.disabledZone.style.top = 0;
			Repolo.disabledZone.style.position = "absolute";
			Repolo.disabledZone.style.backgroundColor = "white";
			Repolo.disabledZone.style.opacity = 0.4;
			Repolo.disabledZone.style.MozOpacity = 0.4;
			Repolo.disabledZone.style.KhtmlOpacity = 0.4;
			Repolo.disabledZone.style.filter = "alpha(opacity=40)";
			Repolo.disabledZone.style.zIndex = 9000;

			Repolo.disabledZone.hide();


			Event.observe(
				window,
				"resize",
				function(){
					Repolo.getDisabledZone().width = document.body.scrollWidth;
					Repolo.getDisabledZone().height = document.body.scrollHeight;
				}
			);


			document.body.appendChild( Repolo.disabledZone );
		}

		return Repolo.disabledZone;
	},



	// ·¹ÀÌ¾î ÆäÀÌÁö ·Îµå( °æ·Î, ³ÐÀÌ, ³ôÀÌ, °æ°è¼±Ç¥½Ã¿©ºÎ )
	loadPage: function( src, width, height, fnPostClose ){

		for(var i=0; i<document.getElementsByTagName("select").length; i++){
			document.getElementsByTagName("select")[i].style.display = "none";
		}


		Repolo.getPageLayer().width = Repolo.getLayerFrame().width = width;
		Repolo.getPageLayer().height = Repolo.getLayerFrame().height = height;
		Repolo.getPageLayer().style.left = ( (document.body.clientWidth / 2) - (width / 2) ) + "px";
		Repolo.getPageLayer().style.top = ( (document.body.clientHeight / 2) - (height / 2) ) + "px";

		Repolo.getLayerFrame().src = src;


		Repolo.getDisabledZone().show();
		Repolo.getPageLayer().show();

		Repolo.getLayerFrame().focus();

		Repolo.__postCloseFrameAction__ = fnPostClose;
	},



	// ·¹ÀÌ¾î ÆäÀÌÁö ´Ý±â..
	closePage: function(){
		for(var i=0; i<document.getElementsByTagName("select").length; i++){
			document.getElementsByTagName("select")[i].style.display = "inline";
		}



		if( typeof(Repolo.__postCloseFrameAction__) == "function" ){
			try{
				Repolo.__postCloseFrameAction__(arguments[0]);
			} catch(e){};


			Repolo.__postCloseFrameAction__ = null;
		}


		Repolo.getLayerFrame().src = "about:blank";

		Repolo.getPageLayer().hide();
		Repolo.getDisabledZone().hide();
	},



	// ´Ù¿î·Îµå ÇÁ·¹ÀÓ ¹ÝÈ¯..
	getDownloadFrame: function(){
		if( !Repolo.downloadFrame ){
			Repolo.downloadFrame = document.createElement("IFRAME");
			Repolo.downloadFrame.id = Repolo.downloadFrame.name = "__ifrDownload__";
			Repolo.downloadFrame.frameBorder = "0px";
			Repolo.downloadFrame.style.width = Repolo.downloadFrame.style.height = "0px";
			Repolo.downloadFrame.style.display = "none";
			
			document.body.appendChild( Repolo.downloadFrame );
		}

		return Repolo.downloadFrame;
	},

	
	// ÀÌ¹ÌÁö ºä¾î~
	showPicture: function( src, lockWindow ){
		if( lockWindow == null )							lockWindow = true;
		if( lockWindow )									Repolo.getDisabledZone().show();


		var oImage = $(src + "_container");

		if( !oImage ){
			oImage = new Element("img");

			oImage.src = src;
			oImage.style.zIndex = 9060;
			oImage.style.position = "absolute";
			oImage.style.cursor = "pointer";
			oImage.style.border = "2px solid orange";
			oImage.alt = "ÀÌ¹ÌÁö¸¦ Å¬¸¯ÇÏ½Ã¸é ´ÝÈü´Ï´Ù.";

			oImage.lockPositionCenter = function(){
				oImage.style.left = ( (document.body.clientWidth / 2) - (this.width / 2) ) + "px";
				oImage.style.top = ( (document.body.clientHeight / 2) - (this.height / 2) ) + "px";
			};


			Event.observe( 
				oImage, 
				"load", 
				function(e){
					oImage = resizeImage( oImage, 500, 500 );

					oImage.lockPositionCenter();
				}
			);

			Event.observe( 
				oImage,
				"click",
				function(e){
					Repolo.getDisabledZone().hide();
					oImage.hide();
				}
			);

			Event.observe(
				window,
				"resize",
				function(){
					oImage.lockPositionCenter();
				}
			);

			document.body.appendChild( oImage );
		}



		oImage.lockPositionCenter();
		oImage.show();
		oImage.focus();
	}
};