//====================================================================
//==本批 JavaScript 用来在 FreeMenuStyle==2 情形下，激发 FrEE 编辑菜单
//====================================================================


//*********************************************************************
//**鼠标移动到 free_menu_icon 箭头上的时候，显示 free_menu_panel
//**其中 free_menu_panel 分三种摆放模式，居中，居左，居右
//**同时 free_menu_panel 分几种类型：main, sub, page, system, map, admin
//*********************************************************************
function show_free_menu(free_menu_icon_name,free_menu_panel_name,free_menu_panel_cell_name,free_menu_type)
{
	//------------------------------
	//--获得当前 free_menu_icon, free_menu_panel 对象
	//------------------------------
	var o_free_menu_icon = document.getElementById(free_menu_icon_name);
	var o_free_menu_panel = document.getElementById(free_menu_panel_name);
	var o_free_menu_panel_cell = document.getElementById(free_menu_panel_cell_name);

	//------------------------------
	//--获得当前 free_menu_icon 箭头的位置
	//------------------------------
	var free_menu_icon_x = FindAbsolutePositionX(o_free_menu_icon);
	var free_menu_icon_y = FindAbsolutePositionY(o_free_menu_icon);

	//------------------------------
	//--显示 free_menu_panel  (table 和 td)
	//------------------------------
	o_free_menu_panel.style.display="block";	

	//------------------------------
	//--三种摆放模式下 （居中，居左，居右），free_menu_panel 的 left 值
	//------------------------------
	var free_menu_panel_center_x = free_menu_icon_x - Math.round(o_free_menu_panel.clientWidth / 2) + Math.round(o_free_menu_icon.clientWidth / 2) -1  ;
	var free_menu_panel_left_x = free_menu_icon_x  + Math.round(o_free_menu_icon.clientWidth / 2) - 28 ;
	var free_menu_panel_right_x = free_menu_icon_x - o_free_menu_panel.clientWidth + Math.round(o_free_menu_icon.clientWidth / 2) + 27 ;
	var free_menu_panel_y = free_menu_icon_y + o_free_menu_icon.clientHeight -1;

	//------------------------------
	//--计算目前窗口的宽度 （注意，这里， IE, Firefox, Oepra 不一致，在 IE 中，应该使用 document.body.clientWidth, 在后二者中，应该使用 window.innerWidth）
	//--我们先使用 window.innerWidth，在 Firefox 和 Opera，这没有问题，直接得到准确值；但在 IE中，这里返回 0，所以，判断一下，如果是 0，说明是 IE，则使用 window_width=document.body.clientWidth
	//------------------------------
	var window_width=window.innerWidth;

	if (window_width<=0 ||  window_width==null)
	{
		window_width=document.body.clientWidth;
	}

	//------------------------------
	//--不同的摆放模式
	//------------------------------
	if (free_menu_panel_center_x >= 0 &&  (free_menu_panel_center_x + o_free_menu_panel.clientWidth <= window_width))
	{
		o_free_menu_panel.className = "free_menu_panel_" + free_menu_type + "_center";
		o_free_menu_panel_cell.className = "free_menu_panel_" + free_menu_type + "_center";

		o_free_menu_panel.style.left = free_menu_panel_center_x  + "px";
		o_free_menu_panel.style.top = free_menu_panel_y + "px" ;
	}
	else if (free_menu_panel_center_x < 0)
	{
		o_free_menu_panel.className = "free_menu_panel_" + free_menu_type + "_left";
		o_free_menu_panel_cell.className = "free_menu_panel_" + free_menu_type + "_left";

		o_free_menu_panel.style.left = free_menu_panel_left_x  + "px";
		o_free_menu_panel.style.top = free_menu_panel_y + "px" ;
	}
	else
	{
		o_free_menu_panel.className = "free_menu_panel_" + free_menu_type + "_right";
		o_free_menu_panel_cell.className = "free_menu_panel_" + free_menu_type + "_right";

		o_free_menu_panel.style.left = free_menu_panel_right_x  + "px";
		o_free_menu_panel.style.top = free_menu_panel_y + "px" ;
	}	
}

//*********************************************************************
//**鼠标移动到 free_menu_panel 上的时候，继续显示 free_menu_panel
//*********************************************************************
function keep_free_menu(free_menu_panel_name)
{
	var o_free_menu_panel=document.getElementById(free_menu_panel_name);
	o_free_menu_panel.style.display="block";	
}

//*********************************************************************
//**鼠标离开 free_menu_icon 箭头，离开 free_menu_panel 的时候，隐藏 free_menu_panel
//*********************************************************************
function hide_free_menu(free_menu_panel_name)
{
	var o_free_menu_panel=document.getElementById(free_menu_panel_name);
	o_free_menu_panel.style.display="none";	
}

//*********************************************************************
//**鼠标指针位于 Logo, MainMenu, Banner 等区域的时候，显示上传按钮（上传 Element 和 Texture）
//**注：ObjectFadein/ObjectFadeout 模式效果暂不佳
//*********************************************************************
function ShowUpload(UploadButtonPanelId,ToggleUploadButtonPanelId,ContainerId,Position)
{
	if (Position==1)
	{
		document.getElementById(UploadButtonPanelId).style.left=FindAbsolutePositionX(document.getElementById(ContainerId))+"px";
		document.getElementById(UploadButtonPanelId).style.top=FindAbsolutePositionY(document.getElementById(ContainerId))+"px";
		document.getElementById(ToggleUploadButtonPanelId).style.left=FindAbsolutePositionX(document.getElementById(ContainerId))+1+"px";
		document.getElementById(ToggleUploadButtonPanelId).style.top=FindAbsolutePositionY(document.getElementById(ContainerId))+1+"px";
		document.getElementById(UploadButtonPanelId).style.display="block";		
		document.getElementById(ToggleUploadButtonPanelId).style.display="block";	
		//ObjectFadein(UploadButtonPanelId,0,"block");
		//ObjectFadein(ToggleUploadButtonPanelId,0,"block");
	}	
	else
	{
		document.getElementById(UploadButtonPanelId).style.left=FindAbsolutePositionX(document.getElementById(ContainerId))+document.getElementById(ContainerId).offsetWidth-29+"px";
		document.getElementById(UploadButtonPanelId).style.top=FindAbsolutePositionY(document.getElementById(ContainerId))+"px";
		document.getElementById(ToggleUploadButtonPanelId).style.left=FindAbsolutePositionX(document.getElementById(ContainerId))+document.getElementById(ContainerId).offsetWidth-28+"px";
		document.getElementById(ToggleUploadButtonPanelId).style.top=FindAbsolutePositionY(document.getElementById(ContainerId))+1+"px";
		document.getElementById(UploadButtonPanelId).style.display="block";		
		document.getElementById(ToggleUploadButtonPanelId).style.display="block";	
		//ObjectFadein(UploadButtonPanelId,0,"block");
		//ObjectFadein(ToggleUploadButtonPanelId,0,"block");
	}
}

//*********************************************************************
//**鼠标指针离开后，关闭上传按钮
//*********************************************************************
function HideUpload(UploadButtonPanelId,ToggleUploadButtonPanelId)
{
	document.getElementById(UploadButtonPanelId).style.display="none";
	document.getElementById(ToggleUploadButtonPanelId).style.display="none";
	//ObjectFadeout(UploadButtonPanelId,0,"block");
	//ObjectFadeout(ToggleUploadButtonPanelId,0,"block");
}

//*********************************************************************
//**鼠标指针位于 Logo, MainMenu, Banner 等区域的时候，在这些区域显示 Mask 来指示要上传的 Element 和 Texture 区域
//*********************************************************************
function ShowMaskElement(UploadButton,MaskId,ContainerId)
{
	UploadButton.src=document.getElementById("imgUploadElementHover").src;
	document.getElementById(MaskId).style.left=FindAbsolutePositionX(document.getElementById(ContainerId))+"px";
	document.getElementById(MaskId).style.top=FindAbsolutePositionY(document.getElementById(ContainerId))+"px";
	document.getElementById(MaskId).style.width=document.getElementById(ContainerId).offsetWidth+"px";
	document.getElementById(MaskId).style.height=document.getElementById(ContainerId).offsetHeight+"px";
	document.getElementById(MaskId).style.display="block";
}

//*********************************************************************
//**鼠标指针离开后，关闭 Mask
//*********************************************************************
function HideMaskElement(UploadButton,MaskId)
{
	UploadButton.src=document.getElementById("imgUploadElement").src;
	document.getElementById(MaskId).style.display="none";
}

//*********************************************************************
//**鼠标指针位于 Logo, MainMenu, Banner 等区域的时候，在这些区域显示 Mask 来指示要上传的 Element 和 Texture 区域
//*********************************************************************
function ShowMaskTexture(UploadButton,MaskId,ContainerId)
{
	UploadButton.src=document.getElementById("imgUploadTextureHover").src;
	document.getElementById(MaskId).style.left=FindAbsolutePositionX(document.getElementById(ContainerId))+"px";
	document.getElementById(MaskId).style.top=FindAbsolutePositionY(document.getElementById(ContainerId))+"px";
	document.getElementById(MaskId).style.width=document.getElementById(ContainerId).offsetWidth+"px";
	document.getElementById(MaskId).style.height=document.getElementById(ContainerId).offsetHeight+"px";
	document.getElementById(MaskId).style.display="block";
}

//*********************************************************************
//**鼠标指针离开后，关闭 Mask
//*********************************************************************
function HideMaskTexture(UploadButton,MaskId)
{
	UploadButton.src=document.getElementById("imgUploadTexture").src;
	document.getElementById(MaskId).style.display="none";
}

//*********************************************************************
//**在 Element/Texture 上传面板上放置一个用来 Toggle 面板最大化，最小化的按钮，以便在面板遮挡了后面的操作界面时，可以将其最小化
//**用于只显示 texture 上传按钮的场合
//*********************************************************************
function ToggleMaxMin(ToggleButton,UploadButtonId)
{
	if (ToggleButton.className=="ToggleMaxMin ToggleMaxMinMax")
	{
		ToggleButton.className="ToggleMaxMin ToggleMaxMinMin";
		document.getElementById(UploadButtonId).className="Upload UploadMin";
	}		
	else
	{
		ToggleButton.className="ToggleMaxMin ToggleMaxMinMax";
		document.getElementById(UploadButtonId).className="Upload UploadMax";
	}
}

//*********************************************************************
//**在 Element/Texture 上传面板上放置一个用来 Toggle 面板最大化，最小化的按钮，以便在面板遮挡了后面的操作界面时，可以将其最小化
//**用于既显示 texture 上传按钮，有显示 Element 上传按钮的场合
//*********************************************************************
function ToggleMaxTwoMin(ToggleButton,UploadButtonId)
{
	if (ToggleButton.className=="ToggleMaxMin ToggleMaxMinMax")
	{
		ToggleButton.className="ToggleMaxMin ToggleMaxMinMin";
		document.getElementById(UploadButtonId).className="Upload UploadMin";
	}		
	else
	{
		ToggleButton.className="ToggleMaxMin ToggleMaxMinMax";
		document.getElementById(UploadButtonId).className="Upload UploadMaxTwo";
	}
}
