//////////////////////////////////////////////////////////////////////////////////////////////////
//  Foxbright FoxPopup object.
//   Manages an overlay on a page.
//   Assumes jQuery and geometry.js are present.
//////////////////////////////////////////////////////////////////////////////////////////////////


function FoxPopup()
{
};


//////////////////////////////////////////////////////////////////////////////////////////////////
// Variables.
//////////////////////////////////////////////////////////////////////////////////////////////////

FoxPopup.parent_element_selector = 'body';

// popup div id.
FoxPopup.popup_id = "fb_popper";
// content div id.
FoxPopup.popup_content_id = "fb_popper_content";
// closer div
FoxPopup.popup_closer_id = "fb_popper_closer";

// time (in milliseconds) that the overlay should fade.
FoxPopup.fade_duration = 200;

// function to be called when content is displayed.
FoxPopup.onDisplay = function() {};

//////////////////////////////////////////////////////////////////////////////////////////////////


FoxPopup.popContent = function(popContent)
{
    if(jQuery('#' + FoxPopup.popup_id).length == 0)
    {
        jQuery('<div id="' + FoxPopup.popup_id + '"><div id="' + FoxPopup.popup_closer_id + '"></div><div id="' + FoxPopup.popup_content_id + '"></div></div>').appendTo(FoxPopup.parent_element_selector);
        jQuery('#' + FoxPopup.popup_closer_id).click(function(){ FoxPopup._hidePopup(); });
    }
    jQuery('#' + FoxPopup.popup_content_id).html(popContent);

    var popupTop = Math.floor(Geometry.getVerticalScroll() + (Geometry.getViewportHeight() / 2) - (jQuery( '#' + FoxPopup.popup_id ).height() / 2));
    //var popupLeft = Math.floor((Geometry.getViewportWidth() / 2) - (jQuery( '#' + FoxPopup.popup_id ).width() / 2));

    jQuery( '#' + FoxPopup.popup_id ).css( 'top', popupTop + "px");
    //jQuery( '#' + FoxPopup.popup_id ).css( 'left', popupLeft + "px");

    FoxPopup._showPopup();
}

//////////////////////////////////////////////////////////////////////////////////////////////////
// Displays the dialog.  (Meant to be only for internal use)
//  OPTIONAL PARAMETERS
//  fade_duration - the time, in milliseconds, that the popup should be faded in/out.
//              this will override the default set when the FoxPopup object was created.
FoxPopup._showPopup = function(fade_duration)
{
    var duration = FoxPopup.fade_duration
    if (typeof(fade_duration) != "undefined")
    {
        duration = fade_duration;
    }
    jQuery('#' + FoxPopup.popup_id).fadeIn(duration, FoxPopup.onDisplay);
}//end showPopup


//////////////////////////////////////////////////////////////////////////////////////////////////
// Hides the dialog.  (Meant to be only for internal use)
//  OPTIONAL PARAMETERS
//  fade_duration - the time, in milliseconds, that the popup should be faded in/out.
//              this will override the default set when the FoxPopup object was created.
FoxPopup._hidePopup = function(fade_duration)
{
    var duration = FoxPopup.fade_duration
    if (typeof(fade_duration) != "undefined")
    {
        duration = fade_duration;
    }
    jQuery('#' + FoxPopup.popup_id).fadeOut(duration);
}//end hidePopup

