﻿// display the lightbox
function lightbox(insertContent, ajaxContentUrl) {

    // add lightbox/shadow <div/>'s if not previously added
    if ($('#lightbox').size() == 0) {
        var theLightbox = $('<div id="lightbox"/>');
        var theShadow = $('<div id="lightbox-shadow"/>');
        $(theShadow).click(function (e) {
            closeLightbox();
        });
        $('body').append(theShadow);
        $('body').append(theLightbox);
    }

    // remove any previously added content
    $('#lightbox').empty();

    // insert HTML content
    if (insertContent != null) {
        $('#lightbox').append(insertContent);
    }

    // insert AJAX content
    if (ajaxContentUrl != null) {
        // temporarily add a "Loading..." message in the lightbox
        $('#lightbox').append('<p class="loading">Loading...</p>');

        // request AJAX content
        $.ajax({
            type: 'GET',
            url: ajaxContentUrl,
            success: function (data) {
                // remove "Loading..." message and append AJAX content
                $('#lightbox').empty();
                $('#lightbox').append(data);
            },
            error: function () {
                alert('AJAX Failure!');
            }
        });
    }

    // move the lightbox to the current window top + 100px
    $('#lightbox').css('top', $(window).scrollTop() + 100 + 'px');

    // display the lightbox
    $('#lightbox').show();
    $('#lightbox-shadow').show();

}

// close the lightbox
function closeLightbox() {

    // hide lightbox and shadow <div/>'s
    $('#lightbox').hide();
    $('#lightbox-shadow').hide();

    // remove contents of lightbox in case a video or other content is actively playing
    $('#lightbox').empty();
}

//$(document).ready(function () {
//    // put all your jQuery goodness in here.
//    lightbox('<h1 style="margin-top:20px;color:#6AA12F;">NO guarantee for delivery before christmas.</h1><p>Sorry but due to the high demand of MES Footwear we are unable to guarantee delivery for christmas.</p><p>Why not take a look our amazing gift vouchers which we can guarantee for christmas.</p><p><a href="http://www.mesfootwork.com/gift-vouchers">Click here</a> to check out the amazing MES gift vouchers</p>');
//});
