﻿/************************************** Splendid *************************************
* Created By:		Steve Doggett
* Creation Date:	26th January 2009
* Edited ----------------------------------------------------------------------------
*       By:              On:  
* Description -----------------------------------------------------------------------
*       This file gives the lightbox fade and basic functionality
*       Uses the JQuery plugin.
*
*       Functions:
*           closePopup()                    // Function to close the lightbox popup
*           removePopup()                   // Remove the popup elements so new one can be put in when needed.
*           myFade()                        // Does the background fade to white for the popup to sit on
*          
**************************************************************************************/

/********************************** Global Variables *********************************/
var popupID = "#lbbPopup";
var pageFadeID = "pageFade";
var fadeSpeed = 1000;

/********************************* Page Fade Functions *******************************/

/****
* Function to close the lightbox popup
****/
function closePopup()
{
    // Fade out the page div so page is visible as noraml again.
    $("#" + pageFadeID).fadeOut(fadeSpeed, function()
    {
        $("#" + pageFadeID).css({
            height: "0px"
        }).unbind("click");
        $('#' + pageFadeID).remove();
    
        $("#pageWrap select").show();
        $("#pageWrap input:checkbox").show();
        $("#pageWrap input:radio").show();        
    });

    removePopup();
}

/****
* Remove the popup elements so new one can be put in when needed.
****/
function removePopup()
{
    $(popupID).fadeOut(fadeSpeed, function()
    {
        $(popupID).children().remove();
    });
}

/****
* Does the background fade to transparent black for the popup to sit on
****/
function myFade()
{
    var pageHeight = $(document).height();

    $("body").append('<div id="' + popupID.replace("#", "") + '" style="display:none;" class="popupHolder contain"></div>');
    $(popupID).before('<div id="' + pageFadeID + '" class="blackout" style="position:absolute;  width:100%; display:block;  height:' + pageHeight + 'px"></div>');
    
    if($.browser.msie)
    {
        $('.blackout').css('opacity','0.75');
        if($.browser.version.substr(0,1) == "6")
        {
            $("#pageWrap select").hide();
            $("#pageWrap input:checkbox").hide();
            $("#pageWrap input:radio").hide();
        }
    } else
    {
        // For the different browsers
        $("#" + pageFadeID).animate({
            opacity: 0.75
        }, fadeSpeed);
    }

    // When the fade is clicked, remove it again
    $("#" + pageFadeID).click(function()
    {
        closePopup();
    });
}