// Note: This script relies on popup.css for all of its styling.  If you plan to use this functionality, make sure that you have 
// that CSS file in your page.
var Panel = function(strPage, strCloseFunction, iWidth, iHeight, bDragable, iStartPosition, iXPos, iYPos)
{
	// Declare Private Member Attributes
	var m_strPage = strPage;
	var m_strCloseFunction = strCloseFunction;
	var m_iWidth = iWidth;
	var m_iHeight = iHeight;
	var m_bDragable = bDragable;
	var m_iStartPosition = iStartPosition;
	var m_iXPos = iXPos;
	var m_iYPos = iYPos;
	var m_objPanelBackground;
	var m_objPanelContent;
	
    function getScrollTop() 
    {
        return self.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
    };

    function getScrollLeft()
    {
        return self.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft;
    };
    
    function getWindowHeight(){
        var de = document.documentElement;
        return self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
    };

    function getWindowWidth(){
            var de = document.documentElement;
            return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
    };
    
	this.Show = function()
	{
	    // Center the panel
		if(m_iStartPosition == 0)
		{
			m_iXPos = getScrollLeft() + (getWindowWidth() / 2) - (m_iWidth / 2);
			m_iYPos = getScrollTop() + (getWindowHeight() / 2) - (m_iHeight / 2);
		}
		else
		{
			m_iXPos = getScrollLeft() + m_iXPos;
			m_iYPos = getScrollTop() + m_iYPos;
		}
		
		// Make sure that the top and left parameters are not less than 0. If they are reset them to 0 so that the 
		// window will correctly size in the browser.
		m_iXPos = (m_iXPos < 0) ? 0 : m_iXPos;
		m_iYPos = (m_iYPos < 0) ? 0 : m_iYPos;
		
		var bgHTML = "<div id='Panel_Background' style=' " + 
		    "height: " + jQuery(document).height() + "px; " + "width: " +  jQuery(document).width()  + "px; " +
		    "'></div>";
        jQuery('body').prepend(bgHTML);
		
        var contentHTML = "<div id='Panel_Content' style='" + 
        "left: " + m_iXPos + "px; top: " + m_iYPos + "px; " + 
        "width:" + m_iWidth + "px; height: " + m_iHeight + "px;'>" + 
        '<div id="Panel_Controls"><a href="javascript:' + m_strCloseFunction + '();">Close</a>&nbsp;&nbsp;</div>' + 
        '<div id="Panel_Content_Page">' + 
        '<div id="Panel_Loading" style="width: ' + m_iWidth + 'px; height: ' + m_iHeight + 'px; padding-top: ' + ((m_iHeight / 2) - 30) + 'px; text-align: center; font-weight: bold;">Loading...</div></div>' +
        "</div>";
        
        jQuery('#Panel_Background').after(contentHTML);
        jQuery('#Panel_Background').css("opacity", 0.5);
        
        // Invoke the function to close the window if the user clicks off of the main window.
        jQuery('#Panel_Background').click(function() {
            try
            {
                eval(strCloseFunction + '();');
            } catch (err) {}
        });
      
       
        // Load the content of the handler into the DOM element
        jQuery("#Panel_Content_Page").load(m_strPage);
	};
	
	this.Hide = function()
	{
		jQuery('#Panel_Background').remove();
		jQuery('#Panel_Content').remove();
	};
	

};