var Wine = {
	__postLoginAction__: null,
	__postUploadAction__: null,
	__postCloseFrameAction__: null,


	// ·Î±×ÀÎ µ¥ÀÌÅÍ..!
	memberData:{
		login: false,
		uid: "",
		uname: ""
	},


	layerFrame: null,
	pageLayer: null,
	disabledZone: null,
	downloadFrame: null,


	// ÆäÀÌÁö ·¹ÀÌ¾î ³»ºÎÀÇ ÇÁ·¹ÀÓ ¹ÝÈ¯
	getLayerFrame: function(){
		Wine.layerFrame = $("__searchFrame__");


		if( !Wine.layerFrame ){
			Wine.layerFrame = new Element("iframe");
			Wine.layerFrame.id = Wine.layerFrame.name = "__searchFrame__";
			Wine.layerFrame.frameBorder = 0;
			Wine.layerFrame.setAttribute("ALLOWTRANSPARENCY", "true");

			Wine.getPageLayer().appendChild( Wine.layerFrame );
		}

		return Wine.layerFrame;
	},


	// ÆäÀÌÁö ·¹ÀÌ¾î ¹ÝÈ¯
	getPageLayer: function(){
		Wine.pageLayer = $("__pageLayer__");


		if( !Wine.pageLayer ){
			Wine.pageLayer = new Element("div");

			Wine.pageLayer.id = "__pageLayer__";
			Wine.pageLayer.style.display = "none";
			Wine.pageLayer.style.position = "absolute";

			document.body.appendChild( Wine.pageLayer );
		}

		Wine.pageLayer.width = Wine.pageLayer.height = 0;
		Wine.pageLayer.style.zIndex = 9050;

		Event.observe(
			window,
			"resize",
			function(){
				Wine.pageLayer.style.left = ( (document.body.clientWidth / 2) - (Wine.pageLayer.width / 2) ) + "px";
				Wine.pageLayer.style.top = ( (document.body.clientHeight / 2) - (Wine.pageLayer.height / 2) ) + "px";
			}
		);


		return Wine.pageLayer;
	},
	

	// ¹ÝÅõ¸í ·¹ÀÌ¾î ¹ÝÈ¯
	getDisabledZone: function(){
		if( !Wine.disabledZone ){
			Wine.disabledZone = new Element("div");
			Wine.disabledZone.id = "__divDisabledZone__";
			Wine.disabledZone.style.zIndex = 0;
			Wine.disabledZone.style.width = document.body.scrollWidth;
			Wine.disabledZone.style.height = document.body.scrollHeight;
			Wine.disabledZone.style.left = 0;
			Wine.disabledZone.style.top = 0;
			Wine.disabledZone.style.position = "absolute";
			Wine.disabledZone.style.backgroundColor = "black";
			Wine.disabledZone.style.opacity = 0.25;
			Wine.disabledZone.style.MozOpacity = 0.25;
			Wine.disabledZone.style.KhtmlOpacity = 0.25;
			Wine.disabledZone.style.filter = "alpha(opacity=25)";
			Wine.disabledZone.style.zIndex = 9000;

			Wine.disabledZone.hide();


			Event.observe(
				window,
				"resize",
				function(){
					Wine.getDisabledZone().width = document.body.scrollWidth;
					Wine.getDisabledZone().height = document.body.scrollHeight;
				}
			);


			document.body.appendChild( Wine.disabledZone );
		}

		return Wine.disabledZone;
	},



	// ·¹ÀÌ¾î ÆäÀÌÁö ·Îµå( °æ·Î, ³ÐÀÌ, ³ôÀÌ, °æ°è¼±Ç¥½Ã¿©ºÎ )
	loadPage: function( src, width, height, fnPostClose ){
		for(var i=0; i<document.getElementsByTagName("select").length; i++){
			document.getElementsByTagName("select")[i].style.display = "none";
		}



		Wine.getPageLayer().width = Wine.getLayerFrame().width = width;
		Wine.getPageLayer().height = Wine.getLayerFrame().height = height;
		Wine.getPageLayer().style.left = ( (document.body.clientWidth / 2) - (width / 2) ) + "px";
		Wine.getPageLayer().style.top = ( (document.body.clientHeight / 2) - (height / 2) ) + "px";

		Wine.getLayerFrame().src = src;


		Wine.getDisabledZone().show();
		Wine.getPageLayer().show();

		Wine.getLayerFrame().focus();

		Wine.__postCloseFrameAction__ = fnPostClose;
	},



	// ·¹ÀÌ¾î ÆäÀÌÁö ´Ý±â..
	closePage: function(){
		for(var i=0; i<document.getElementsByTagName("select").length; i++){
			document.getElementsByTagName("select")[i].style.display = "inline";
		}



		if( typeof(Wine.__postCloseFrameAction__) == "function" ){
			try{
				Wine.__postCloseFrameAction__(arguments[0]);
			} catch(e){};


			Wine.__postCloseFrameAction__ = null;
		}


		Wine.getLayerFrame().src = "about:blank";

		Wine.getPageLayer().hide();
		Wine.getDisabledZone().hide();
	},



	// ´Ù¿î·Îµå ÇÁ·¹ÀÓ ¹ÝÈ¯..
	getDownloadFrame: function(){
		if( !Wine.downloadFrame ){
			Wine.downloadFrame = document.createElement("IFRAME");
			Wine.downloadFrame.id = Wine.downloadFrame.name = "__ifrDownload__";
			Wine.downloadFrame.frameBorder = "0px";
			Wine.downloadFrame.style.width = Wine.downloadFrame.style.height = "0px";
			Wine.downloadFrame.style.display = "none";
			
			document.body.appendChild( Wine.downloadFrame );
		}

		return Wine.downloadFrame;
	},


	// È¸¿øÀÇ ·Î±×ÀÎÁ¤º¸ °¡Á®¿À±â..!
	loadMemberInfo: function( fnPostAction ){
		new Ajax.Request(
			"/06_Member/process/loginInfo.asp",
			{
				onSuccess: function( xmlHttp ){
					Wine.memberData = xmlHttp.responseText.evalJSON();

					if( typeof(fnPostAction) == "function" ){
						fnPostAction();
					}
				}
			}
		);
	},



	// ·Î±×ÀÎ·¹ÀÌ¾î º¸ÀÌ±â..!
	showLoginLayer: function( fnPostLogin ){
		Wine.__postLoginAction__ = null;
		Wine.__postLoginAction__ = fnPostLogin;



		for(var i=0; i<document.getElementsByTagName("select").length; i++){
			document.getElementsByTagName("select")[i].style.display = "none";
		}



		Wine.loadPage("/06_Member/layer_login.asp", 482, 280);
	},



	// ·Î±×ÀÎ·¹ÀÌ¾î ´Ý±â..!
	closeLoginLayer: function(){
		for(var i=0; i<document.getElementsByTagName("select").length; i++){
			document.getElementsByTagName("select")[i].style.display = "inline";
		}


		if( typeof(Wine.__postLoginAction__) == "function" ){
            Wine.__postLoginAction__();
            Wine.__postLoginAction__ = null;


            try{
                var oTopMenuFlash = $("WineTopMenuFlash");

				if( oTopMenuFlash ){
					var flashParams = "";
					flashParams += "lognum=1";
					flashParams += "&depth1=" + oTopMenuFlash.getVariables("depth1");
					flashParams += "&depth2=" + oTopMenuFlash.getVariables("depth2");
				}

			} catch(e){
				//window.location.reload();
			};

		} else{
			window.location.reload();
		}

		Wine.loadMemberInfo( new Function("Wine.closePage();") );
	},


	// ·Î±×¾Æ¿ô..
	logout: function(){
		if( confirm("·Î±×¾Æ¿ô ÇÏ½Ã°Ú½À´Ï±î?") ){
			window.location.href = "/06_Member/process/member_logout.asp";
		}
	},


	// ¾÷·Îµå Æû ¿­±â...
	openUploadForm: function( fnCallback, uploadPath, type ){
		Wine.__postUploadAction__ = fnCallback;

		Wine.loadPage( ("/common/uploadForm.asp?type=" + (type || "") + "&path=" + uploadPath), 350, 200);
	},


	// ¾÷·Îµå Æû ´Ý±â..
	closeUploadForm: function( fileName ){
		if( fileName && (fileName.length > 0) ){
			if( typeof(Wine.__postUploadAction__) == "function" ){
				try{
					Wine.__postUploadAction__( fileName );
				} catch(e){};
			}
		}


		Wine.closePage();
	},


	// ÀÌ¹ÌÁö ºä¾î~
	showPicture: function( src, lockWindow ){
		if( lockWindow == null )							lockWindow = true;
		if( lockWindow )									Wine.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){
					Wine.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 );
		}
	},



	// ¿ÍÀÎÁ¤º¸º¸±â ÆäÀÌÁö·Î ÀÌµ¿..!
	goWineInfoPage: function( brandCode ){
		alert(brandCode + " ¿ÍÀÎÁ¤º¸º¸±â ÆäÀÌÁö·Î ÀÌµ¿");
	},



	// ¿ÍÀÎ »óÇ° ºü¸¥ °Ë»ö..!
	showProduct: function( brandCode ){
		if( parent && parent.Wine ){
			parent.location.href = "/01_Choice/world_wine_view.asp?code=" + brandCode;
		} else{
			window.location.href = "/01_Choice/world_wine_view.asp?code=" + brandCode;
		}
	},



	// ³»°¡¼±ÅÃÇÑ ¿ÍÀÎÁ¤º¸ ÀúÀå..!
	setMemberChoiceWine: function( brandCode ){
		new Ajax.Request(
			"/06_Member/process/member_choiceWine_insert.asp",
			{
				parameters:("code=" + brandCode),
				onSuccess: function( xmlHttp ){
					var result = parseInt(xmlHttp.responseText, 10);

					switch( result ){
						case -1:
							Wine.showLoginLayer( 
								function(){ 
									Wine.setMemberChoiceWine(brandCode);
								}
							);
							break;

						case -2:
							alert("¸Å°³º¯¼ö ºÎÁ·!");
							break;

						case -3:
							alert("ÀÌ¹Ì µî·ÏÇÑ »óÇ°ÀÔ´Ï´Ù!");
							break;

						case 1:
							if( confirm("\"³»°¡¼±ÅÃÇÑ ¿ÍÀÎ\" ¸®½ºÆ®¿¡ Ãß°¡µÇ¾ú½À´Ï´Ù!\n\nÁö±Ý È®ÀÎÇÏ½Ã°Ú½À´Ï±î?") ){
								window.location.href = "/06_Member/mywine_page.asp";
							}
							break;

						default:
							alert( xmlHttp.responseText );
							break;
					}
				},

				onFailure: function( xmlHttp ){
					alert(xmlHttp.responseText);
				}
			}
		);
	},


	// ½ºÅä¸®¿ÍÀÎ ºí·Î±×ÆÛ°¡±â..
	scrapStoryWine: function( cdomain,copystr ){

		var defstr="" ; 

		defstr += "<table cellpadding=0 cellspacing=0 width=770 align=center>" 
		defstr += "<tr>" 
		defstr += "<td colspan=5><img src=\""+cdomain+"/images/scrap_story_top.jpg\" border=0 usemap=\"#scrap_blog_top\"></td>" 
		defstr += "</tr>" 
		defstr += "<tr>" 
		defstr += "<td bgcolor=\"#590402\" width=25></td>" 
		defstr += "<td bgcolor=\"#F5F3E7\" width=25></td>" 
		defstr += "<td bgcolor=\"#F5F3E7\" width=670 style=\"font-family:µ¸¿ò; font-size:11px; line-height:18px; color:#8D8D8D; letter-spacing:-1;\">" 
		defstr += copystr
		defstr += "</td>" 
		defstr += "<td bgcolor=\"#F5F3E7\" width=25></td>" 
		defstr += "<td bgcolor=\"#170000\" width=25></td>"
		defstr += "</tr>" 
		defstr += "<tr>" 
		defstr += "<td colspan=5><img src=\""+cdomain+"/images/scrap_story_bottom.jpg\" border=0 usemap=\"#scrap_blog_bottom\"></td>" 
		defstr += "</tr>" 
		defstr += "<map name=\"scrap_blog_top\">" 
		defstr += "<area shape=\"rect\" coords=\"48,28,150,70\" href=\"http://www.wine.co.kr/\" target=\"_blank\" onFocus=\"this.blur()\">" 
		defstr += "</map>" 
		defstr += "<map name=\"scrap_blog_bottom\">" 
		defstr += "<area shape=\"rect\" coords=\"298,50,472,94\" href=\"http://www.wine.co.kr/\" target=\"_blank\" onFocus=\"this.blur()\">" 
		defstr += "</map>" 
		defstr += "</table>"

		if( textToClip(defstr) ){
			alert("¿ÍÀÎÁ¤º¸°¡ Å¬¸³º¸µå¿¡ º¹»çµÇ¾ú½À´Ï´Ù!\n\n¿øÇÏ´Â°÷¿¡ Ctrl+V·Î ºÙ¿©³Ö±â ÇÏ¼¼¿ä.");
		}
		else{
			alert("Å¬¸³º¸µå º¹»çÁß ¿À·ù°¡ ¹ß»ýÇß½À´Ï´Ù. \n\n Àá½ÃÈÄ ´Ù½Ã ½ÃµµÇØÁÖ¼¼¿ä");
		}
			
	},




	// ¿ÍÀÎÁ¤º¸ ºí·Î±×ÆÛ°¡±â..
	scrapWineInfoBlog: function( brandCode ){
		new Ajax.Request(
			"/product/process/scrap_wineInfo.asp",
			{
				parameters:("code=" + brandCode),
				onSuccess: function( xmlHttp ){
					if( textToClip(xmlHttp.responseText) ){
						alert("¿ÍÀÎÁ¤º¸°¡ Å¬¸³º¸µå¿¡ º¹»çµÇ¾ú½À´Ï´Ù!\n\n¿øÇÏ´Â°÷¿¡ Ctrl+V·Î ºÙ¿©³Ö±â ÇÏ¼¼¿ä.");
					}
				},

				onFailure: function( xmlHttp ){
					alert( xmlHttp.responseText );
				}
			}
		);
	},


	// ¿ÍÀÎ Æ÷µµ¾Ë°¡°Ô °¡±â..
	goWineGrapeShop: function( brandCode ){
		if( parent ){
			parent.location.href = "/04_Event/grape_market.asp";
		} else{
			window.location.href = "/04_Event/grape_market.asp";
		}
	},



	// "¿ÍÀÎ ¿ë¾î°Ë»öÃ¢" ¿­±â..!
	openWineDic: function(){
		Wine.loadPage("/05_About/popup_winedic.asp", 610, 422 );
	},


	// "Äü¸Þ´º ¼³Á¤Ã¢" ¿­±â..!
	openMenuSetting: function(){
		if( Wine.memberData.login ){
			Wine.loadPage("/common/quick_editer.asp", 868, 430 );

		} else{
			Wine.showLoginLayer( Wine.openMenuSetting );
		}
	}
};






Wine.Product = {
	__postSearchAction__: null,


	// ¿ÍÀÎ »óÇ°µ¥ÀÌÅÍ Á¶È¸..!
	get: function( brandCode, fnPostSearch ){
		if( brandCode ){
			new Ajax.Request(
				"/product/process/wine_info.asp",
				{
					parameters:("code=" + brandCode),
					onSuccess: function( xmlHttp ){
						if( fnPostSearch && (typeof(fnPostSearch) == "function") && (xmlHttp.responseText.length > 10) ){
							fnPostSearch( xmlHttp.responseText.evalJSON().data );
						}
					},

					onFailure: function( xmlHttp ){
						alert( xmlHttp.responseText );
					}
				}
			);
		}
	},


	// »óÇ°°Ë»ö Ã¢ ¿­±â - ´ÜÀÏ¼±ÅÃ
	openQuickSearch: function( fnPostSearch ){
		Wine.Product.__postSearchAction__ = fnPostSearch;

		Wine.loadPage( "/product/layer_quickSearch.asp", 400, 400 );
	},


	closeQuickSearch: function( data ){
		if( data && typeof(Wine.Product.__postSearchAction__) == "function" ){
			Wine.Product.__postSearchAction__( data );

			Wine.Product.__postSearchAction__ = null;
		}

		Wine.closePage();
	},



	// "¿À´Ã º» ¿ÍÀÎ" ¿­±â..!
	openTodayView: function(){
		Wine.loadPage("/product/popup_todaylist.asp", 760, 240 );
	},


	// »óÇ°°Ë»ö Ã¢ ¿­±â - ´ÙÁß¼±ÅÃ
	openMultipleSearch: function( fnPostSearch ){
		Wine.Product.__postSearchAction__ = fnPostSearch;

		Wine.loadPage( "/adminForDoosanWine/common/wine_multiSearch.asp", 430, 602 );
	}
};











// Site-Map Å¬¸¯½Ã »ó´Ü Flash ¿µ¿ª È®Àå
function expandTopFlash(){
	if( $("WineTopMenuFlash") ) {
		$("WineTopMenuFlash").style.height = screen.height;


		for(var i=0; i<document.getElementsByTagName("select").length; i++){
			document.getElementsByTagName("select")[i].style.display = "none";
		}
	}
}


// Site-Map ´ÝÈú¶§ »ó´Ü Flash ¿µ¿ª Ãà¼Ò
function reduceTopFlash(){
	if( $("WineTopMenuFlash") ) {
		$("WineTopMenuFlash").style.height = 200;


		for(var i=0; i<document.getElementsByTagName("select").length; i++){
			document.getElementsByTagName("select")[i].style.display = "inline";
		}
	}
}
