var curViewRcType = "";
var curViewJidx = "";
var g_height = 0;	// #### Á¦ÈÞ»ç¿¡¼­ ³ëÃâ ³ôÀÌ ¾È¸Â´Â ºÎºÐ Ã³¸® ####

function viewSummary(rcType, adid, event) {
	
	if (rcType != "PowerHot" && rcType != "MegaPlus" )
	{
		document.getElementById("GoodsGuide_Platinum").style.display	= "none";
		document.getElementById("GoodsGuide_Focus").style.display		= "none";
		document.getElementById("GoodsGuide_BestZone").style.display	= "none";
		document.getElementById("GoodsGuide_BestHot").style.display		= "none";
		document.getElementById("GoodsGuide_Prime").style.display		= "none";
		document.getElementById("GoodsGuide_BoxEdu").style.display		= "none";
	}
	
	if ($(rcType +"_li_" + adid) != null) {
		var fa = document.getElementById(rcType+"_li_"+adid) ;
		var fs = (fa.currentStyle) ? fa.currentStyle.backgroundPositionY : document.defaultView.getComputedStyle(fa, null).getPropertyValue("background-position");
	}
	
	if (curViewRcType != "" && curViewJidx != "") {
		closeSummary(curViewRcType,curViewJidx); 
//		if (rcType != "BestHot") return false;
	}

	curViewRcType   = rcType;
	curViewJidx		= adid;

	if ((fs == "top") || (fs == "0% 0%")) {
		fa.style.backgroundPosition = "left bottom"
	} else {
		if (rcType != "BestHot" && rcType != "PowerHot" && rcType != "MegaPlus") {
			return
		}
	}

 	if (rcType == "BestHot" || rcType == "PowerHot" || rcType == "MegaPlus") {
		document.getElementById(rcType+"_li_"+adid+"_view").style.display = "none";
		document.getElementById(rcType+"_li_"+adid+"_close").style.display = "block";
	}
		
	var mainWidth = Element.getWidth($("global"));	
  var mainLeft = $("global").offsetLeft;
 	var eventLeft = Event.pointerX(event);
 	//var eventTop = Event.pointerY(event);
	var eventTop = Event.pointerY(event) + g_height;
	var btnGap = -10;
	var layerWidth = 460; // ¿ä¾àº¸±â·¹ÀÌ¾î °¡·Î»çÀÌÁî
 	var layerLeft = (eventLeft - mainLeft) + 8;

	new Insertion.Bottom("global", "<div id='SummaryContainer' class='summary' style='position:absolute; background:none'></div>");
	
	ajax_updater("SummaryContainer", "/include/Main/mainPreviewBox.asp", "get", "rcType=" + rcType + "&adid=" + adid.split("|")[0]);
	
	if ((layerLeft + layerWidth) < mainWidth) {
		$("SummaryContainer").style.left = layerLeft + "px";
		$("SummaryContainer").style.top = (eventTop + btnGap) + "px";
	} else if ((layerLeft - layerWidth) < 0) {
		$("SummaryContainer").style.left = parseInt((mainWidth - layerWidth) / 2) + "px";
		$("SummaryContainer").style.top = (eventTop + btnGap) + "px";
	} else if ((layerLeft + layerWidth) > mainWidth) {
		$("SummaryContainer").style.left = (layerLeft - layerWidth) + "px";
		$("SummaryContainer").style.top = (eventTop + btnGap) + "px";
	}
	$("SummaryContainer").style.display = "block";

}

// ¿ä¾àº¸±â ·¹ÀÌ¾î´Ý±â
function closeSummary(rcType, adid) {
	curViewRcType = "";
	curViewJidx = "";
  	
	var fa = document.getElementById(rcType+"_li_"+adid) ;
	
	var fs = (fa.currentStyle) ? fa.currentStyle.backgroundPositionY : document.defaultView.getComputedStyle(fa, null).getPropertyValue("background-position");
	
  	if ((fs != "top") || (fs != "0% 0%")) {
 		fa.style.backgroundPosition = "left top"
   	}

	if (rcType == "BestHot" || rcType == "PowerHot" || rcType == "MegaPlus" ) {
		document.getElementById(rcType+"_li_"+adid+"_view").style.display  = "block";
		document.getElementById(rcType+"_li_"+adid+"_close").style.display = "none";
	}

	$("SummaryContainer").style.display = "none";

 }


function ajax_updater(_placeholder, _url, _method, _pars) {
	//showLoadingLayer();
	var myAjax = new Ajax.Updater(
		{success: _placeholder},
		_url,
		{
			method: _method,
			parameters: _pars,
			/*onLoading: function(req) {
				if (req.readyState == 1) {
					$(_placeholder).innerHTML = "<div style='height:100px;text-align:center;padding-top:30;'><img src='http://image.alba.kr/common/loading.gif' /></div>";
				}
			},*/
			onFailure: function(req) {$(_placeholder).innerHTML = "Error...";},
			//onComplete: function(req) {hideLoadingLayer();},
			evalScripts: true
		}
	);
}

function ajax_result(_url, _method, _pars, _obj) {
	var objAjax = new Ajax.Request(
		_url, {
			method: _method,
			parameters: _pars,
			onComplete: function(response) {fillSelectBoxJSON(response, _obj);}
			//onComplete: showResponse
		}
	);
}

// For Test
function showResponse(originalRequest) {
	alert("RESULT:" + originalRequest.responseText);
}

function fillSelectBoxJSON(res, obj)
{
	var serverData = res.responseText;
	var evalData = eval("(" + serverData + ")");
	obj.options.length = 1;

	if (evalData.result != "SUCCESS") {
		return;
	}

	for (var i = 0; i < evalData.data.length; i++) {
		var opt = new Option;
		opt.value = evalData.data[i].value;
		opt.text = evalData.data[i].text;
		obj.options[i + 1] = opt;
	}
	obj.options[evalData.data.length + 1] = new Option("ÀüÃ¼", "ÀüÃ¼");
}
