﻿// JScript 檔
var commeryShowId;
var scrollLeft;
var scrollTop;
var clientWidth;
var clientHeight;
var cs_interval;

function menuItem_mouseOver(sender) 
{
	var oPanelSubMenu = document.getElementById('panelSubMenu');
	var oCurrentSubMenu = document.getElementById(sender);
	if(oCurrentSubMenu !=null) 
	{
	    oPanelSubMenu.innerHTML = oCurrentSubMenu.innerHTML;
	    oPanelSubMenu.visible="true" ;
	}
	else 
	{
	    oPanelSubMenu.innerHTML = '';
	    oPanelSubMenu.visible="false" ;
	}
}

function menuItem_click() 
{
	var oPanelSubMenu = document.getElementById('panelSubMenu');
	oPanelSubMenu.innerHTML = '';
	oPanelSubMenu.visible="false" ;
}	

function changeViewState(id)
{
    if(id.style.visibility=="hidden")
    {
        id.style.visibility = "visible";
    }
    else
    {
        id.style.visibility = "hidden";
    }
}

function setCommeryShow(id)
{
    commeryShowId = id;

    window.onresize = resetCommeryShow;
    window.onscroll = scrollCommeryShow;
   
    setTimeout('resetCommeryShow();',100);
}

function resetCommeryShow()
{
    countAttribute();
    commeryShowId.style.top = scrollTop + 20;
    commeryShowId.style.left = clientWidth - scrollLeft - commeryShowId.offsetWidth - 20;

}

function scrollCommeryShow()
{
    if(cs_interval)
        clearInterval(cs_interval);
    cs_interval = setInterval("moveCommeryShow()",1);
}

function moveCommeryShow()
{
    countAttribute();
    
    if(parseInt(commeryShowId.style.top) > scrollTop + 20)
    {
        commeryShowId.style.top = parseInt(commeryShowId.style.top) - 1;
    }
    else if(parseInt(commeryShowId.style.top) < scrollTop + 20)
    {
        commeryShowId.style.top = parseInt(commeryShowId.style.top) + 1;
    }
        
    if(parseInt(commeryShowId.style.left) > (clientWidth - scrollLeft - commeryShowId.offsetWidth - 20))
    {
        commeryShowId.style.left = parseInt(commeryShowId.style.left) - 1;
    }
    else if(parseInt(commeryShowId.style.left) < (clientWidth - scrollLeft - commeryShowId.offsetWidth - 20))
    {
        commeryShowId.style.left = parseInt(commeryShowId.style.left) + 1;
    }
    
    if((parseInt(commeryShowId.style.top) == (scrollTop + 20)) && (parseInt(commeryShowId.style.left) == (clientWidth - scrollLeft - commeryShowId.offsetWidth - 20)))
    {
        clearInterval(cs_interval);
    }
    //alert('top' + commeryShowId.style.top + "." + (scrollTop + 20) + "  left" + commeryShowId.style.left + "." + (clientWidth - scrollLeft - commeryShowId.offsetWidth - 20));
}

function countAttribute()
{
    scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    if (window.innerWidth) {
        clientWidth = ((Sys.Browser.agent === Sys.Browser.Safari) ? window.innerWidth : Math.min(window.innerWidth, document.documentElement.clientWidth));
    } else {
        clientWidth = document.documentElement.clientWidth;
    }
    if (window.innerHeight) {
        clientHeight = ((Sys.Browser.agent === Sys.Browser.Safari) ? window.innerHeight : Math.min(window.innerHeight, document.documentElement.clientHeight));
    } else {
        clientHeight = document.documentElement.clientHeight;
    }
}