﻿/// <reference path="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.1-vsdoc.js" />
/** LightBox effect
*   @author: James Diacono
*   @date: 31st of May, 2010
*   @requires: jQuery
*   @usage: jQuery plugin to 'LightBox' an element - it will be centred vertically and horizontally on the screen
*/

/* Constructor */
jQuery(function () {
    var lightBox = jQuery('<div id="lightBox" />').prependTo('body').hide();

    jQuery(lightBox).
        css('top', '0px').
        css('left', '0px').
        css('background', 'black').
        css('filter', 'alpha(opacity = 70)'). // opacity for IE 8 and below
        css('opacity', '0.7').
        css('z-index', '999'); // One less than the element being lightboxed

    if (jQuery.browser.msie && jQuery.browser.version <= 6) {
        jQuery(lightBox).append('<style type="text\/css">#lightBox {position:absolute;}<\/style>'); // for IE 6
    } else {
        jQuery(lightBox).css('position', 'fixed');
    }
});

jQuery.fn.lightBox = function () {
    var that = this;

    // Show the lightbox
    jQuery('#lightBox').
        css('height', jQuery(window).height()).
        css('width', jQuery(window).width()).
        show().
        click(function () {
            that.unLightBox();
        });


    if (jQuery.browser.msie && jQuery.browser.version <= 6) {
        jQuery('#lightBox').css('top', jQuery(window).scrollTop()); // for IE 6
    }

    // Center it to the window and show it
    this.
        css("top", (jQuery(window).height() - this.height()) / 2 + jQuery(window).scrollTop() + "px").
        css("left", (jQuery(window).width() - this.width()) / 2 + jQuery(window).scrollLeft() + "px").
        css("z-index", "1000"). // One more than the lightbox
        show();


    // Custom behaviour stored in the lightBox DOM element
    if (typeof this[0].onLightBox === 'function') {
        this[0].onLightBox();
    }

    return this;
};

jQuery.fn.unLightBox = function () {
    // Hide the lightbox background
    jQuery('#lightBox').hide();

    this.hide();

    // Custom behaviour stored in the lightBox DOM element
    if (typeof this[0].onUnLightBox === 'function') {
        this[0].onUnLightBox();
    }

    return this;
};
