﻿/************************************** Splendid *************************************
* Created By:		Seb Wells ( seb@howsplendid.com )
* Creation Date:	15th December 2010
* Edited ----------------------------------------------------------------------------
*       By:              On:  
* Description -----------------------------------------------------------------------
*       Create a lightbox with an iframe. Based on Steve Doggett's accessible lightbox.
*
*       Dependancies:
*       - JQuery plugin v1.4.1
*       - accessible-lightbox.js
*       - css style .nockBack { background: none repeat scroll 0 0 #000000; left: 0; position: absolute; top: 0; z-index: 400; }
*
*       Usage: 
*        html in host page: <a href="/lightboxcontents.htm" class="signInOverlay">Sign In</a>   
*        script: jQuery(document).ready(function () {
*            // Wire up a click event for the popuplink
*            jQuery('.signInOverlay').click(function () {
*                var lightbox = new iframeLightbox(this.href, 600, 500);
*                lightbox.CreateLightbox();
*                return false;
*            });
*        });
*        html in client page: <a href="javascript:parent.CloseLightbox();">close</a>
*          
**************************************************************************************/

function cmslightbox(href, width, height) {
    this.width = width;
    this.height = height;
    this.href = href;

    this.CreateLightbox =
    function () {
        //alert("CreateLightbox");
        this.RemoveOldLightbox();
    };

    this.RemoveOldLightbox =
    function () {
        //alert("RemoveOldLightbox");
        if ($('#' + popupID).length == 0) {
            this.PostFadeOut();
            return;
        }

        $('#' + popupID).fadeOut(fadeSpeed, function () {
            $('#' + popupID).remove();
            this.PostFadeOut();
        });
    };

    this.PostFadeOut =
    function () {
        //alert("PostFadeOut");
        $('body').append('<div id="' + popupID + '"><iframe src ="' + this.href + '" scrolling="no" frameborder="0" width="' + this.width + '" height="' + this.height + '" allowtransparency="true" /></div>');

        $('#' + popupID).css(
            {
                display: 'none',
                position: "absolute",
                zIndex: 500
            }
        );

        PositionLightbox();

        this.FadeBackgroundIn();
        $('#' + popupID).fadeIn(fadeSpeed);
    };

    this.FadeBackgroundIn =
    function () {
        //alert("FadeBackgroundIn");
        var pageHeight = $(document).height();
        $('body').append('<div class="nockBack" style="opacity:0;"></div>');


        $("." + fadeClass).css({
            "height": $(window).height(),
            "z-index'": "5",
            "width": $(window).width(),
            "top": $(window).scrollTop()
        }).animate({
            "opacity": 0.7
        }, fadeSpeed);

        // This function is in main-navigation.js and it hides dropdowns, checkboxes and radio buttons in ie6.
        checkForDodgyIE6Elements("hidden");

        // When the fade is clicked, remove it again
        $("." + fadeClass).click(CloseLightbox);

        $(window).resize(this.ResizeEvent);

        $(window).scroll(this.ScrollEvent);
    };

    this.ResizeEvent =
    function () {
        try {
            $("." + fadeClass).css(
                {
                    "height": $(window).height(),
                    "width": $(window).width()
                }
            );
            PositionLightbox();
        }
        catch (e) { }

    };

    this.ScrollEvent =
    function () {
        try {
            $("." + fadeClass).css(
                {
                    "top": $(window).scrollTop()
                }
            );
            PositionLightbox();
        }
        catch (e) { }
    };
}

