﻿var nw;

window.addEvent('load', function() {
    mcp.setFooter();
});

mcp = {
    setFooter: function() {
        var content = $('main-area').getCoordinates();
        var footer = $(document.body).getElement("#footer");
        var pos = mcp.windowSize().height - footer.offsetHeight;

        if (content.bottom < pos) {
            footer.style.position = "absolute";
            footer.style.display = "block";
            footer.style.top = pos + 'px';
        }
        footer.style.visibility = 'visible';
    },

    addToCart: function(productID, orderAmount, orderSize, orderColor) {
        var url = mcpVars.fullPath + "/addtocart";
        new Request({
            url: url,
            data: { id: productID, amt: orderAmount, s: orderSize, c: orderColor, lang: mcpVars.lang },
            method: 'post',
            noCache: false,
            onComplete: function(text) {
                $('shopCart').set('html', text);
                mcp.closeModalWindow();
            },
            onFailure: function(text) {

            }
        }).send();
    },

    removeFromCart: function(orderItemID) {
        var url = mcpVars.fullPath + "/removefromcart";
        new Request({
            url: url,
            data: { id: orderItemID, lang: mcpVars.lang },
            method: 'post',
            noCache: false,
            onComplete: function(text) {
                $('shopCart').set('html', text);
                mcp.closeModalWindow();
            }
        }).send();
    },

    getImageDetail: function(objTitle) {
        var url = mcpVars.fullPath + "/productdetail";
        new Request({
            url: url,
            data: { id: objTitle, lang: mcpVars.lang },
            method: 'post',
            noCache: false,
            onComplete: function(text) {
                nw = new StickyWinModal({
                    position: 'center',
                    allowMultiple: false,
                    offset: {
                        x: -400,
                        y: -220
                    },
                    useIframeShim: true
                });
                nw.setContent(text);
                nw.show();
            }
        }).send();
    },

    closeModalWindow: function() {
        if (nw != null) nw.hide();
    },

    changeImage: function(imgTarget, imgSrc) {
        $(imgTarget).src = unescape(mcpVars.fullPath + "/products/380/" + imgSrc);
    },

    windowSize: function() {
        var w = 0;
        var h = 0;

        if (!window.innerWidth) {
            if (!(document.documentElement.clientWidth == 0)) {
                w = document.documentElement.clientWidth;
                h = document.documentElement.clientHeight;
            }
            else {
                w = document.body.clientWidth;
                h = document.body.clientHeight;
            }
        }
        else {
            w = window.innerWidth;
            h = window.innerHeight;
        }
        return { width: w, height: h };
    }
};



