var ie6Below = $.browser.msie && parseFloat($.browser.version) <= 6;
 

//Jscript to generate window height (this is used with Monitor Solutions Popup)
function getWindowSize() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return [myWidth, myHeight];
}

function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [scrOfX, scrOfY];
}

/* lightbox overlay for content */

function showOverlay(html, keepContentWhenRemove, shopLink, shopText) {

    var popup = null;

    if (keepContentWhenRemove && showOverlay.html) {
        html = showOverlay.html;
    }


    displayPanel(html, shopLink, shopText);
    function removePopup() {
        popup.fadeOut("slow", function() { $(this).add(".popFrame").remove(); });
        $(window).unbind("scroll");
        return false;
    }

    function displayPanel(html, sohpLink, shopText) {

        popupHeading = $(".magazineView h3").text();

        popup = $('<div id="overlayPopup" class="popup"></div>' +
        '<div class="overlay"><div class="popupHeader">' +
        '<h2 class="popupHeading">' + popupHeading + '</h2>' +
        '<div class="actionHolder">' +
        '<p class="action popupClose"><a href="#"><span>CLOSE</span></a></p>' +
        '<p class="action buyOnline"><a href="' + shopLink + '" target="_blank"><span>' + shopText + '</span></a></p>' +
        '</div></div><div class="popupContent" /></div>').hide().css("display", "none");
        popup.filter(".popup").css("opacity", "0.5").click(removePopup);
        var popupContent = popup.find(".popupContent").append(html);

        showOverlay.html = popupContent.html();

        $("body").append(popup);

        popup.eq(1).width(popup.eq(1).width());

        popup.eq(1)
            .css("margin-left", -popup.eq(1).width() / 2)
            .find(".popupClose")
            .css("float", "right")
            .click(removePopup);

        popup.fadeIn();

        var offsetTop = ($(window).height() - popup.eq(1).height()) / 2;

        if (ie6Below) {

            popup.css("position", "absolute").eq(1).css({ top: (getScrollXY()[1] + offsetTop) }).end().eq(0).height(document.body.scrollHeight);
            $(window).bind("scroll", function() {
                popup.eq(1).stop().animate({ top: getScrollXY()[1] + offsetTop }, 500);
            });

            $("body").append('<iframe class="popFrame" style="position:absolute;top:0;left:0;width:100%;height:' + document.body.scrollHeight + 'px" frameborder="0" src="javascript:false;"></iframe>').find(":last").css("opacity", 0);
        }
        else {
            popup.get(1).style.top = offsetTop + "px";
        }
    }

    return false;
}
