var Haitai = {
	__postLoginAction__: null,
	__postUploadAction__: null,
	__postCloseFrameAction__: null,
	__postZipcodeAction__: null,
	__viewCoolnA__: true,


	// ·Î±×ÀÎ µ¥ÀÌÅÍ..!
	memberData:{
		login: false,
		uid: "",
		uname: ""
	},


	layerFrame: null,
	pageLayer: null,
	disabledZone: null,
	downloadFrame: null,


	// ÆäÀÌÁö ·¹ÀÌ¾î ³»ºÎÀÇ ÇÁ·¹ÀÓ ¹ÝÈ¯
	getLayerFrame: function(){
		if( !Haitai.layerFrame ){
			Haitai.layerFrame = new Element("iframe");
			Haitai.layerFrame.id = Haitai.layerFrame.name = "__layerFrame__";
			Haitai.layerFrame.frameBorder = 0;
			Haitai.layerFrame.setAttribute("ALLOWTRANSPARENCY", "true");

			Haitai.getPageLayer().appendChild( Haitai.layerFrame );
		}

		return Haitai.layerFrame;
	},


	// ÆäÀÌÁö ·¹ÀÌ¾î ¹ÝÈ¯
	getPageLayer: function(){
		if( !Haitai.pageLayer ){
			Haitai.pageLayer = new Element("div");

			Haitai.pageLayer.id = "__pageLayer__";
			Haitai.pageLayer.style.display = "none";
			Haitai.pageLayer.style.position = "absolute";
			Haitai.pageLayer.width = Haitai.pageLayer.height = 0;
			Haitai.pageLayer.style.zIndex = 9050;

			Haitai.pageLayer.page = Haitai.getLayerFrame();

			Event.observe(
				window,
				"resize",
				function(){
					Haitai.pageLayer.style.left = ( (document.body.clientWidth / 2) - (Haitai.pageLayer.width / 2) ) + "px";
					Haitai.pageLayer.style.top = ( (document.body.clientHeight / 2) - (Haitai.pageLayer.height / 2) ) + "px";
				}
			);


			document.body.appendChild( Haitai.pageLayer );
		}

		return Haitai.pageLayer;
	},
	

	// ¹ÝÅõ¸í ·¹ÀÌ¾î ¹ÝÈ¯
	getDisabledZone: function(){
		if( !Haitai.disabledZone ){
			Haitai.disabledZone = new Element("div");
			Haitai.disabledZone.id = "__divDisabledZone__";
			Haitai.disabledZone.style.zIndex = 0;
			Haitai.disabledZone.style.width = document.body.scrollWidth;
			Haitai.disabledZone.style.height = document.body.scrollHeight;
			Haitai.disabledZone.style.left = 0;
			Haitai.disabledZone.style.top = 0;
			Haitai.disabledZone.style.position = "absolute";
			Haitai.disabledZone.style.backgroundColor = "black";
			Haitai.disabledZone.style.opacity = 0.25;
			Haitai.disabledZone.style.MozOpacity = 0.25;
			Haitai.disabledZone.style.KhtmlOpacity = 0.25;
			Haitai.disabledZone.style.filter = "alpha(opacity=25)";
			Haitai.disabledZone.style.zIndex = 9000;

			Haitai.disabledZone.hide();


			Event.observe(
				window,
				"resize",
				function(){
					Haitai.getDisabledZone().width = document.body.scrollWidth;
					Haitai.getDisabledZone().height = document.body.scrollHeight;
				}
			);


			document.body.appendChild( Haitai.disabledZone );
		}

		return Haitai.disabledZone;
	},



	// ·¹ÀÌ¾î ÆäÀÌÁö ·Îµå( °æ·Î, ³ÐÀÌ, ³ôÀÌ, °æ°è¼±Ç¥½Ã¿©ºÎ )
	loadPage: function( src, width, height, fnPostClose ){

		for(var i=0; i<document.getElementsByTagName("select").length; i++){
			document.getElementsByTagName("select")[i].style.display = "none";
		}


		Haitai.getPageLayer().width = Haitai.getLayerFrame().width = width;
		Haitai.getPageLayer().height = Haitai.getLayerFrame().height = height;
		Haitai.getPageLayer().style.left = ( (document.body.clientWidth / 2) - (width / 2) ) + "px";
		Haitai.getPageLayer().style.top = ( (document.body.clientHeight / 2) - (height / 2)  )  + "px";

		Haitai.getLayerFrame().src = src;


		Haitai.getDisabledZone().show();
		Haitai.getPageLayer().show();

		Haitai.getLayerFrame().focus();

		Haitai.__postCloseFrameAction__ = fnPostClose;
	},



	// ·¹ÀÌ¾î ÆäÀÌÁö ´Ý±â..
	closePage: function(){
		for(var i=0; i<document.getElementsByTagName("select").length; i++){
			document.getElementsByTagName("select")[i].style.display = "inline";
		}



		if( typeof(Haitai.__postCloseFrameAction__) == "function" ){
			try{
				Haitai.__postCloseFrameAction__(arguments[0]);
			} catch(e){};


			Haitai.__postCloseFrameAction__ = null;
		}


		Haitai.getLayerFrame().src = "about:blank";

		Haitai.getPageLayer().hide();
		Haitai.getDisabledZone().hide();
	},


	// ·¹ÀÌ¾î º¸ÀÌ±â( ·¹ÀÌ¾î, ³ÐÀÌ, ³ôÀÌ )
	showLayer: function( oLayer, width, height ){
		for(var i=0; i<document.getElementsByTagName("select").length; i++){
			document.getElementsByTagName("select")[i].style.display = "none";
		}

		oLayer.style.position = "absolute";
		oLayer.style.zIndex = 9050;
		oLayer.style.left = ( (document.body.clientWidth / 2) - (width / 2) ) + "px";
		oLayer.style.top = ( (document.body.clientHeight / 2) - (height / 2) ) + "px";
		oLayer.style.width = width;
		oLayer.style.height = height;

		Haitai.getDisabledZone().show();
		oLayer.show();
	},


	// ·¹ÀÌ¾î °¨Ãß±â
	hideLayer: function( oLayer ){
		for(var i=0; i<document.getElementsByTagName("select").length; i++){
			document.getElementsByTagName("select")[i].style.display = "inline";
		}


		oLayer.hide();
		Haitai.getDisabledZone().hide();
	},




	// ·¹ÀÌ¾î ÆäÀÌÁö ¸®»çÀÌÂ¡..
	resizePage: function( width, height ){
		Haitai.getPageLayer().width = Haitai.getLayerFrame().width = width + "px";
		Haitai.getPageLayer().height = Haitai.getLayerFrame().height = height + "px";
		Haitai.getPageLayer().style.left = ( (document.body.clientWidth / 2) - (width / 2) ) + "px";
		Haitai.getPageLayer().style.top = ( (document.body.clientHeight / 2) - (height / 2) ) + "px";
	},



	// ´Ù¿î·Îµå ÇÁ·¹ÀÓ ¹ÝÈ¯..
	getDownloadFrame: function(){
		if( !Haitai.downloadFrame ){
			Haitai.downloadFrame = document.createElement("IFRAME");
			Haitai.downloadFrame.id = Haitai.downloadFrame.name = "__ifrDownload__";
			Haitai.downloadFrame.frameBorder = "0px";
			Haitai.downloadFrame.style.width = Haitai.downloadFrame.style.height = "0px";
			Haitai.downloadFrame.style.display = "none";
			
			document.body.appendChild( Haitai.downloadFrame );
		}

		return Haitai.downloadFrame;
	},



	
	// ºÎ¶óº¸ÄÜ 40ÁÖ³â ÀÌº¥Æ®1 
	openEvent1: function( fnCallback ){
		Haitai.__postZipcodeAction__ = fnCallback;

		Haitai.loadPage("/event/201003/event.asp", 440, 290);
	},


	
	// ´©½Ö¹Ù ºóÄ­Ã¤¿ì±â ÀÌº¥Æ® °³ÀÎÁ¤º¸ 
	openWordUser: function(){
		Haitai.loadPage("/event/20100510/userinfo.asp", 594, 440);
	},


	// ´©½Ö¹Ù ´ñ±Û ÀÌº¥Æ® °³ÀÎÁ¤º¸ 
	openCmtUser: function( param ){
		Haitai.loadPage("/event/20100510/userinfo_cmt.asp" , 594, 440);
	},


	// ´©½Ö¹Ù °æ±âÀÏÁ¤ÆË¾÷ 
	openMatchSchedule: function( param ){
		Haitai.loadPage("/event/20100510/popup_schedule.html" , 552, 372);
	},
	
	
	
	// ¿ìÆí¹øÈ£Ã£±â Æû ¿­±â..
	openZipcode: function( frmName ){
		Haitai.loadPage("/common/pop_zipcode.asp?frm="+frmName, 400, 500);
	},


	// ¿ìÆí¹øÈ£Ã£±â Æû ´Ý±â..
	closeZipcode: function( zip1, zip2, addr1 ){
		if( typeof(Haitai.__postZipcodeAction__) == "function" ){
			try{
				Haitai.__postZipcodeAction__( zip1, zip2, addr1 );
			} catch(e){};
		}


		Haitai.closePage();
	},


	// ÀÌ¹ÌÁö ºä¾î~
	showPicture: function( src, lockWindow ){
		if( lockWindow == null )							lockWindow = true;
		if( lockWindow )									Haitai.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 #6B12C2";
			oImage.alt = "ÀÌ¹ÌÁö¸¦ Å¬¸¯ÇÏ½Ã¸é ´ÝÈü´Ï´Ù.";


			oImage = resizeImage(oImage, 800, 800);



			oImage.lockPositionCenter = function(){
				oImage.style.left = ( (screen.availWidth / 2) - (this.width / 2) ) + "px";
				oImage.style.top = ( (screen.availHeight / 2) - (this.height / 2) ) + "px";
//				oImage.style.top = "10px";

				this.focus();
			};

			Event.observe( 
				oImage,
				"Haitai",
				function(e){
					Haitai.getDisabledZone().hide();
					oImage.hide();
				}
			);

			Event.observe(
				window,
				"resize",
				function(){
					oImage.lockPositionCenter();
				}
			);

			document.body.appendChild( oImage );
		}



		oImage.lockPositionCenter();
		oImage.show();
	},


	// ToolTip ¼³¸í³»¿ëÀ» ÀÌ¹ÌÁö·Î ¼³Á¤
	setToolTipHelpImage: function( obj, imgSrc ){
		if( obj ){
			var objPos = ( obj.style.top && obj.style.left ) ? [obj.style.left, obj.style.top] : Position.page( obj );


			obj._toolTip = new Image();
			obj._toolTip.src = imgSrc;

			obj._toolTip.id = (obj.id + "_toolTip");
			obj._toolTip.style.position = "absolute";
			obj._toolTip.style.display = "none";
			obj._toolTip.style.left = (objPos[0] - (obj._toolTip.width / 3)) + "px";
			obj._toolTip.style.top = (objPos[1] - (obj._toolTip.height) + 125) + "px";


			Event.observe( 
				obj, 
				"mouseover", 
				function(e){
					obj._toolTip.style.left = (e.x - e.offsetX + document.body.scrollLeft) - (obj._toolTip.width / 2) + 10;
					obj._toolTip.style.top = (e.y - e.offsetY + document.body.scrollTop) - (obj._toolTip.height) - 5;

					Element.show( obj._toolTip );
				}
			);

			Event.observe( obj, "mouseout", new Function("Element.hide(this._toolTip);") );


			document.body.appendChild( obj._toolTip );
		}
	}

};

