var XPopup = XPopup ? XPopup : function() {
   
   var private = {
      initialized: false,
      fadeIn: null,
      opacity: 0,
      bgDv: null,
      cDv: null
      };

   var public = {
      init: function() {
         private.bgDv = document.createElement("div");
         document.body.appendChild(private.bgDv);

         private.ppDv = document.createElement("div");

            private.xDv = document.createElement("div");
            private.ppDv.appendChild(private.xDv);

            private.cDv = document.createElement("div");
            private.ppDv.appendChild(private.cDv);

         document.body.appendChild(private.ppDv);

         private.initialized = true;
         public.applyStyle();
      },

      show: function(url, w, h, useGet) {
         if (!private.initialized)
            public.init();

         window.scroll(0, 0);
         public.setup(w, h);
         private.bgDv.style.display    = "block";
         private.ppDv.style.display    = "block";

         if (useGet) {
            XAjax(url, true, XPopup.setContent);
         }
         else {
            XAjax(url, false, XPopup.setContent);
         }
         
         // Show (fade-in)
         clearInterval(private.fadeId);
         private.fadeId = setInterval("XPopup.fade(1)", 10);
      },

      setup: function(w, h) {
         private.ppDv.style.width      = w + "px";
         private.ppDv.style.height     = h + 5 + "px";
         private.ppDv.style.left       = Math.round((getViewportWidth() - w) / 2) + "px";
         private.ppDv.style.top        = getViewportHeight() / 8 + "px";

         private.cDv.style.width       = w + "px";
         private.cDv.style.height      = h + "px";
         private.cDv.style.overflow    = "auto";

         private.bgDv.style.width      = getViewportWidth() + "px";
         private.bgDv.style.height     = getViewportHeight() + "px";
         private.bgDv.style.left       = "0px";
         private.bgDv.style.top        = "0px";
      },
      
      setContent: function (rTxt, rXML) {
         private.cDv.innerHTML = rTxt;
      },

      hide: function() {
         if (typeof(XList) != "undefined" && XList.changed) {
            XList.update();
         }

         // Show (fade-in)
         clearInterval(private.fadeId);
         private.fadeId = setInterval("XPopup.fade(0)", 5);
      },
      
      fade: function(io) {
         private.opacity = io ? private.opacity + 0.05 : private.opacity - 0.05;
         private.opacity = (private.opacity > 1) ? 1 : private.opacity;
         private.opacity = (private.opacity < 0) ? 0 : private.opacity;

         if (navigator.appName == "Microsoft Internet Explorer") {
            private.ppDv.style.filter  = "alpha(opacity=" + parseInt(100 * private.opacity) + ")";
            private.bgDv.style.filter  = "alpha(opacity=" + parseInt(100 * Math.min(0.5, private.opacity)) + ")";
         }
         else {
            private.ppDv.style.opacity = private.opacity;
            private.bgDv.style.opacity = Math.min(0.5, private.opacity);
         }

         if (!io && private.opacity == 0) {
            private.ppDv.style.display = "none";
            private.bgDv.style.display = "none";
            private.cDv.innerHTML = "";
         }

         if (private.opacity == 1 || private.opacity == 0) {
            clearInterval(private.fadeId);
         }
      },

      applyStyle: function() {
         // Popup style
         private.ppDv.style.display      = "none";
         private.ppDv.style.position     = "absolute";
         private.ppDv.style.padding      = "10px";
         private.ppDv.style.paddingTop   = "5px";
         private.ppDv.style.background   = "#ffffff";
         private.ppDv.style.opacity      = "0";
         private.ppDv.style.border       = "1px #000000 solid";
         private.ppDv.style.zIndex       = "999";
         private.ppDv.style.textAlign    = "right";

         // Content
         private.cDv.style.display      = "block";
         private.cDv.style.cssFloat     = "right";
         private.cDv.style.marginTop    = "5px";
         private.cDv.style.textAlign    = "left";

         // Button
         private.xDv.style.display      = "block";
         private.xDv.style.position     = "absolute";
         private.xDv.style.top          = "-23px";
         private.xDv.style.right        = "-1px";
         private.xDv.style.height       = "22px";
         private.xDv.style.width        = "40px";
         private.xDv.style.cursor       = "pointer";
         private.xDv.style.border       = "1px #000000 solid";
         private.xDv.style.borderBottom = "0px";
         private.xDv.style.background   = "#ffffff url(" + ((typeof(siteURL) != 'undefined') ? siteURL : baseURL) + "images/cms/close.png) no-repeat center center";

         // Background style
         private.bgDv.style.display     = "none";
         private.bgDv.style.position    = "fixed";
         private.bgDv.style.background  = "#000000";
         private.bgDv.style.opacity     = "0";
         private.bgDv.style.zIndex      = "998";

         if (navigator.appName == "Microsoft Internet Explorer") {
            private.ppDv.style.filter = "alpha(opacity = 0)";
            private.bgDv.style.position = "absolute";
            private.bgDv.style.filter = "alpha(opacity = 0)";
         }

         // Background listener
         //addListener(private.bgDv, 'click', function() {
         //   XPopup.hide();
         //});

         // Background listener
         addListener(private.xDv, 'click', function() {
            XPopup.hide();
         });
      }
   };

   return public;
}();