/**
 * Product detail hover button effect.
 *
 * Requires "arccmgr.js" for event dispatching.
 */

prodFx = {

    /**
     * Set to enable hover button.
     */
    enabled: false,

    /**
     * Internal variables for hover button tracking.
     */
    buttonImg: null,
    overProduct: false,
    lastProductId: null,
    lastColorId: null,
    overButton: false,

    //showButton: function(event, xoff, yoff, productId)
    showButton: function(event, xoff, yoff, productId, nodeId)
    {

        this.overProduct = true;

        if (this.enabled &&
            (this.buttonImg == null || this.lastProductId != productId))
        {
            this.lastProductId = productId;
            this.lastColorId = nodeId;
            this.destroyButton();

            if (!event) var event = window.event;
            var tg = (window.event) ? event.srcElement : event.target;
            this.buttonImg = document.createElement("img");
            this.buttonImg.setAttribute("src", STATIC_ARC_URL + "images/quickshop_off.png");
            this.buttonImg.setAttribute("width",107);// setting width & height to prevent strech on IE7
            this.buttonImg.setAttribute("height",25);
            this.buttonImg.style.position = 'absolute';
            this.buttonImg.style.zIndex = 900;
            this.buttonImg.style.left = (parseInt(arc.Util.getAbsoluteLeft(tg))+ xoff)+"px";
            this.buttonImg.style.top = (parseInt(arc.Util.getAbsoluteTop(tg))+ yoff)+"px";
            this.buttonImg.onmouseover = function()
            {
                document.body.style.cursor = 'pointer';
                prodFx.buttonImg.setAttribute("src", STATIC_ARC_URL + "images/quickshop_over.png");
                prodFx.overButton = true;
            }
            this.buttonImg.onmouseout = function()
            {
                document.body.style.cursor = 'default';
                prodFx.buttonImg.setAttribute("src", STATIC_ARC_URL + "images/quickshop_off.png");
                prodFx.overButton = false;
            }
            this.buttonImg.onmousedown = function()
            {
                document.body.style.cursor = 'pointer';
                prodFx.buttonImg.setAttribute("src", STATIC_ARC_URL + "images/quickshop_over.png");
                prodFx.overButton = false;
            }
            this.buttonImg.onmouseup = function()
            {
                document.body.style.cursor = 'default';
                prodFx.buttonImg.setAttribute("src", STATIC_ARC_URL + "images/quickshop_over.png");
                prodFx.openProduct();
            }
            document.body.appendChild(this.buttonImg);
        }
    },

    openProduct: function()
    {
        // Dispatch a launch event for the "proddetail" application context.
        arcDetailsLaunch(this.lastProductId, this.lastColorId)
    
        // Hide the button on launch.
        this.overProduct = false;
        this.overButton = false;
        this.destroyButton();
    },

    hideButton: function()
    {
        this.overProduct = false;
        setTimeout("prodFx.timeoutButton();", 500);
    },

    timeoutButton: function()
    {
        if (!this.overButton && !this.overProduct)
        {
            this.destroyButton();
        }
    },

    destroyButton: function()
    {
        if (this.buttonImg != null)
        {
            document.body.removeChild(this.buttonImg);
            this.buttonImg = null;
        }
    }
};


