TDPopup = function(Obj) {
// variables
    var self = this;
    var Content = {};
    var Close = {};
	var BG = {};
	var Visible = false;

// init
    function init() {
		BG = FindComponent(Obj, "TDPopupBG");
        Content = FindComponent(Obj, "TDPopupContent");

		if (GetIEVersion() < 0) {
			BG.style.background = "url(" + FindComponent(BG, "TDFixPNG").src + ")";
			FindComponent(BG, "TDFixPNG").style.visibility = "hidden";
			Content.style.background = "url(" + FindComponent(Content, "TDFixPNG").src + ")";
			FindComponent(Content, "TDFixPNG").style.visibility = "hidden";
		} else {
			Content.style.width = (Content.offsetWidth - 40) + "px";
			Content.style.height = (Content.offsetHeight - 40) + "px";
		}
		
        AddEvent(BG, "mouseup", MouseDown);
		AddEvent(Content, "mouseup", MouseDown);
    };
    
// close on click
    function MouseDown(e) {
        Hide();
    };
    
// show and align all components
	this.Show = function() {
		Obj.style.width = GetDocumentSize().Width + "px";
        Obj.style.height = GetDocumentSize().Height + "px";
        Obj.style.visibility = "visible";
		
        BG.style.width = Obj.offsetWidth + "px";
        BG.style.height = Obj.offsetHeight + "px";
        BG.style.visibility = "visible";
        
        Content.style.left = Math.ceil((BG.offsetWidth - Content.offsetWidth) / 2) + "px";
        Content.style.top = Math.ceil((BG.offsetHeight - Content.offsetHeight) / 2) + "px";
        Content.style.visibility = "visible";
        
        Visible = true;
	};
    
// call this event when the window resizes
    this.Resize = function() {
        if (Visible) self.Show();
    };
    
// hide all components of this object
    function Hide() {
		Obj.style.visibility = "hidden";
        BG.style.visibility = "hidden";
        Content.style.visibility = "hidden";
        
        Reset();
        
        Visible = false;
    };
    
// reset all sizes to prevent scrollbars from showing up
    function Reset() {
        Obj.style.width = "2px";
        Obj.style.height = "2px";
        
        BG.style.width = "2px";
        BG.style.height = "2px";
        
        Content.style.left = "0px";
        Content.style.top = "0px";
    };

    init();
};