        function set_blanket_height() {
            if (typeof window.innerWidth != 'undefined') {
                viewportheight = window.innerHeight;
            } else {
                viewportheight = document.documentElement.clientHeight;
            }
            if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
                blanket_height = viewportheight;
            } else {
                if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
                    blanket_height = document.body.parentNode.clientHeight;
                } else {
                    blanket_height = document.body.parentNode.scrollHeight;
                }
            }
            document.getElementById('blanket').style.height = blanket_height + 'px';
        }
        function set_popup_size_and_position(source) {
            var viewportwidth;
            var viewportheight;
            // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
            if (typeof window.innerWidth != 'undefined') {
                viewportwidth = window.innerWidth,
        viewportheight = window.innerHeight
            }
            // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
            else if (typeof document.documentElement != 'undefined'
    && typeof document.documentElement.clientWidth != 'undefined'
    && document.documentElement.clientWidth != 0) {
                viewportwidth = document.documentElement.clientWidth,
        viewportheight = document.documentElement.clientHeight
            }
            // older versions of IE
            else {
                viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
        viewportheight = document.getElementsByTagName('body')[0].clientHeight
            }
            var newImage = new Image();
            newImage.src = source;
            var imageHeight = newImage.height;
            var imageWidth = newImage.width;
            // set size
            document.getElementById('popup').style.height = imageHeight;
            document.getElementById('popup').style.width = imageWidth;
            var borderWidth = document.getElementById('popup').style.borderWidth;

            //set position
            document.getElementById('popup').style.left = (viewportwidth - imageWidth - 2 * borderWidth) / 2 + 'px';
            document.getElementById('popup').style.top = (viewportheight - imageHeight - 2 * borderWidth) / 2 + 'px';
        }
        function toggle(div_id) {
            var el = document.getElementById(div_id);
            if (el.style.display == 'block') {
                el.style.display = 'none';
            } else {
                el.style.display = 'block';
            }
        }
        function set_image_source(source) {
            document.getElementById('popupimage').src = source;
        }
        function popup(source) {
            set_blanket_height()
            set_image_source(source)
            set_popup_size_and_position(source)
            toggle('blanket');
            toggle('popup');
        }