 /**********************************************************
  * Manage a faded overlay with custom content
  **********************************************************/


    var Overlay = new Object();

    // Overlay percent
    Overlay.alpha = 50;


   /**
    * Open element with an overlay
    * @param string id target element id
    */
    Overlay.open = function(id)
    {
        var position = 0;
        var percent = 0;


        // Assign references
        this.container = document.getElementById(id);
        this.content   = this.container.getElementsByTagName('DIV').item(0);
        

        // Hide content by default
        this.content.style.display      = 'none';

        
        // In IE, we must create an iframe to block windowed controls
        // showing on top of the page (IE 5.5+)

/*
	if (Common.isIE)
		{
*/  
		this.iframe = document.createElement('IFRAME');
		this.iframe.setAttribute("frameborder","no");
		this.iframe.setAttribute("border","0");
		this.iframe.style.position   = 'absolute';
		this.iframe.style.left       = '0px';
		this.iframe.style.top        = '0px';
		this.iframe.style.width      = '100%';
		this.iframe.style.height     = Common.getPageHeight() + 'px';
		this.iframe.style.zIndex     = 1000;
		this.iframe.style.filter     ='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';

		document.body.appendChild(this.iframe);
//	}


        // Create dark overlay
        this.overlay = document.createElement('DIV');

        // Set overlay to fullscreen
        this.overlay.style.position   = 'absolute';
        this.overlay.style.left       = '0px';
        this.overlay.style.top        = '0px';
        this.overlay.style.width      = '100%';
        this.overlay.style.background = '#003764';
        this.overlay.style.zIndex     = 1001;

        document.body.insertBefore(this.overlay, document.body.firstChild);


        // Set container to fullscreen
        this.container.style.display     = 'block';
        this.container.style.position    = 'absolute';
        this.container.style.left        = '0px';
        this.container.style.top         = '0px';
        this.container.style.width       = '100%';
        this.container.style.zIndex      = 1002;


        // Resolve vertical position for the container, as the user
        // might have scrolled down and we want to maintain that position

        if (window.innerHeight)
            position = window.pageYOffset;
            
        else if (document.documentElement && document.documentElement.scrollTop)
            position = document.documentElement.scrollTop

        else if (document.body)
            position = document.body.scrollTop

        this.container.style.top = position + 'px';


        // Animate single step
        var fadeIn = function()
        {
            var alpha = percent / 100;

            // Set opacity supporting various browsers
            Overlay.overlay.style.opacity      = alpha;
            Overlay.overlay.style.MozOpacity   = alpha;
            Overlay.overlay.style.KhtmlOpacity = alpha;
            Overlay.overlay.style.filter       = 'alpha(opacity=' + percent + ')';

            // Once animated, show content
            if (percent >= Overlay.alpha)
                Overlay.content.style.display = 'block';

            ++percent;
        };

        // Initiate right away
        fadeIn();

        // Animate the overlay
        for (var i = 1; i <= this.alpha; ++i)
            window.setTimeout(fadeIn, i * 5);
            
        // Listen to window resizing
        Common.addEventListener(window, 'resize', this.changeSize);
        this.changeSize();

        // Disable link
        return false;
    };

    
   /**
    * Close currently opened element
    */
    Overlay.close = function()
    {
        // Remove overlay
        document.body.removeChild(this.overlay);

        // Remove iframe in IE
        if (this.iframe)
            document.body.removeChild(this.iframe);
            
        // Hide content
        this.content.style.display = 'none';
        
        // Remove event listener
        Common.removeEventListener(window, 'resize', this.changeSize);
    };
    
    
   /**
    * Resize overlay when window size changes
    */
    Overlay.changeSize = function()
    {
        // Update overlay height
        Overlay.overlay.style.height = Common.getPageHeight() + 'px';

        // Update container width for IE
        if (Common.isIE)
            Overlay.container.style.width = Common.getBrowserWidth() + 'px';
            
        Common.removeEventListener(window, 'resize', this.changeSize);
    };
