function popupObject(width, height)
{
    this.popupWidth = 0;
    this.popupHeight = 0;
    this.popupCurrentWidth = 0;
    this.popupCurrentHeight = 0;
    this.myWidth = 0;
    this.myHeight = 0;
    this.cdiv = 'blank';
    this.expand = 'blank';
    this.innerHTML = '';
    this.popup = '';
    this.popupBackground = '';
    
    this.closePopup = function()
    {
        clearInterval(this.cdiv);
        this.cdiv = 'blank';
        
        this.popup = '';
        var div_loop;
        while (div_loop = document.getElementById('popup'))
        {
            div_loop.parentNode.removeChild(div_loop);
        }
        while (div_loop = document.getElementById('popupBackground'))
        {
            div_loop.parentNode.removeChild(div_loop);
        }
        document.getElementsByTagName('html')[0].style.overflow = 'auto';
    }
    
    this.getWindowSize = function()
    {
        document.getElementsByTagName('html')[0].style.overflow = 'hidden';
        if (typeof( window.innerWidth ) == 'number')
        {
            this.myWidth = window.innerWidth;
            this.myHeight = window.innerHeight;
        }
        else if (document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ))
        {
            this.myWidth = document.documentElement.clientWidth;
            this.myHeight = document.documentElement.clientHeight;
        }
        else if (document.body && ( document.body.clientWidth || document.body.clientHeight ))
        {
            this.myWidth = document.body.clientWidth;
            this.myHeight = document.body.clientHeight;
        }
    }
    
    this.positionCenter = function()
    {
        this.getWindowSize();
        if (this.cdiv == 'blank') {this.cdiv = window.setInterval("popup.positionCenter()", 25);}
        this.popupBackground.style.top = Math.floor(Math.round( document.documentElement.scrollTop)) + 'px';
        this.popup.style.top = document.documentElement.scrollTop + Math.floor((this.myHeight - this.popupCurrentHeight)/2) + 'px';
        this.popup.style.left = document.documentElement.scrollLeft + Math.floor((this.myWidth - this.popupCurrentWidth)/2) + 'px';
        this.popupBackground.style.height = this.myHeight + 'px';
        this.popupBackground.style.width = this.myWidth + 'px';
    }
    
    this.expand = function()
    {
        if (this.popupCurrentWidth < this.popupWidth || this.popupCurrentHeight < this.popupHeight)
        {
            if (this.popupCurrentWidth < this.popupWidth)
            {
                if (this.popupCurrentWidth + Math.floor(this.popupWidth/10) > this.popupWidth)
                {
                    this.popupCurrentWidth = this.popupWidth;
                }
                else
                {
                    this.popupCurrentWidth += Math.floor(this.popupWidth/10);
                }
            }
            if (this.popupCurrentHeight < this.popupHeight)
            {
                if (this.popupCurrentHeight + Math.floor(this.popupHeight/10) > this.popupHeight)
                {
                    this.popupCurrentHeight = this.popupHeight;
                }
                else
                {
                    this.popupCurrentHeight += Math.floor(this.popupHeight/10);
                }
            }
            this.popup.style.width = this.popupCurrentWidth + 'px';
            this.popup.style.height = this.popupCurrentHeight + 'px';
            this.positionCenter();
            var expand = setTimeout('popup.expand()',5);
        }
        else
        {
            this.popupWidth = this.popupCurrentWidth;
            this.popupHeight = this.popupCurrentHeight;
            this.innerText();
        }
    }
    
    this.innerText = function()
    {
        var newimg = document.createElement('img');
        newimg.style.position = 'absolute';
        newimg.style.zIndex = '350';
        newimg.style.width = '43px';
        newimg.style.height = '42px';
        newimg.setAttribute("src", "http://images.apegaming.net/image_warehouse/mNGsImit.png");
        newimg.setAttribute("alt", "X");
        
        try
        {
            newimg.addEventListener('click', function(event) { popup.closePopup(); }, false);    
        }
        catch(err)
        {
            newimg.attachEvent('onclick', function() { popup.closePopup() });
        }
        this.popup.appendChild(newimg);
        
        var popcont = document.createElement('div');
        popcont.setAttribute('id', 'popupcontainer');
        popcont.style.textAlign = 'center';
        popcont.style.position = 'relative';
        popcont.style.overflow = 'auto';
        popcont.style.fontWeight = 'bold';
        popcont.style.visibility = 'visible';
        popcont.innerHTML = this.innerHTML;
        this.popup.appendChild(popcont);
        var popupcontainer = document.getElementById('popupcontainer');
        var temppadding = Math.floor((this.popupHeight / 2) - (popupcontainer.offsetHeight / 2));
        if (temppadding < 0)
        {
            temppadding = 0;
        }
        popupcontainer.style.height = this.popupHeight + 'px';
        popupcontainer.style.width = this.popupWidth + 'px';
        popupcontainer.style.paddingTop = temppadding + 'px';
        popupcontainer.style.visibility = 'visible';
    }
    
    this.open = function(width, height, text)
    {
        this.getWindowSize();
        if (width == 0 || width > (this.myWidth * 0.98))
        {
            this.popupWidth = Math.floor(this.myWidth * 0.98);
        }
        else
        {
            this.popupWidth = width;
        }
        if (height == 0 || height > (this.myHeight * 0.98))
        {
            this.popupHeight = Math.floor(this.myHeight * 0.98);
        }
        else
        {
            this.popupHeight = height;
        }
        this.popupCurrentWidth = 0;
        this.popupCurrentHeight = 0;
        this.innerHTML = text;
        var ni = document.getElementsByTagName('body')[0];
        // container div
        var newdiv = document.createElement('div');
        newdiv.setAttribute('id', 'popupBackground');
        newdiv.style.position = "absolute";
        newdiv.style.zIndex = '300';
        newdiv.style.padding = '0';
        newdiv.style.width = Math.floor(this.myWidth * 1) + 'px';
        newdiv.style.height = Math.floor(this.myHeight * 1)+ 'px';
        newdiv.style.backgroundColor = 'black';
        newdiv.style.opacity = '0.5';
        newdiv.style.filter = 'alpha(opacity = 50)';
        ni.appendChild(newdiv);
            // html div
            var htmlTop = Math.floor((this.myHeight/2) - (this.popupHeight/2));
            var htmlLeft = Math.floor((this.myWidth/2) - (this.popupWidth/2));
            var newhtml = document.createElement('div');
            newhtml.setAttribute('id', 'popup');
            newhtml.style.position = "absolute";
            newhtml.style.zIndex = '301';
            newhtml.style.width = this.popupCurrentWidth + "px";
            newhtml.style.height = this.popupCurrentHeight + "px";
            newhtml.style.backgroundColor = 'white';
            newhtml.style.top = htmlTop  + 'px';
            newhtml.style.left = htmlLeft + 'px';
            newhtml.style.opacity = '1';
            newhtml.style.filter = 'alpha(opacity = 100)';
            newhtml.padding = '0px';
            ni.appendChild(newhtml);
        this.popup = document.getElementById('popup');
        this.popupBackground = document.getElementById('popupBackground');
        this.expand();
        this.positionCenter();
    }
}
var popup = new popupObject();