﻿var imageoverlay = {
    getposOffset: function(what, offsettype) {
        return (what.offsetParent) ? what[offsettype] + this.getposOffset(what.offsetParent, offsettype) : what[offsettype]
    },

    setPos: function(anchorobj, overlayobj, horizontaloffset, verticaloffset) {
        overlayobj.style.left = this.getposOffset(anchorobj, "offsetLeft") + horizontaloffset + "px";
        if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
            overlayobj.style.top = this.getposOffset(anchorobj, "offsetTop") + verticaloffset - 100 + "px";
        }
        else {
            overlayobj.style.top = this.getposOffset(anchorobj, "offsetTop") + verticaloffset + "px";
        }
    },

    init: function(anchorid, overlayid, horizontaloffset, verticaloffset, visible) {
        var anchorobj = document.getElementById(anchorid)
        if (anchorobj == null)
            return;

        var overlayobj = document.getElementById(overlayid);
        if (overlayobj == null)
            return;

        if (visible) {
            overlayobj.style.visibility = "visible";
            this.setPos(anchorobj, overlayobj, horizontaloffset, verticaloffset);

            $(window).resize(function() {
                imageoverlay.setPos(anchorobj, overlayobj, horizontaloffset, verticaloffset);
            });
        }
        else {
            overlayobj.style.visibility = "hidden";
        }
    }
}
