﻿/**
* jQuery lightBox plugin
* This jQuery plugin was inspired and based on Lightbox 2 by Lokesh Dhakar (http://www.huddletogether.com/projects/lightbox2/)
* and adapted to me for use like a plugin from jQuery.
* @name jquery-lightbox-0.5.js
* @author Leandro Vieira Pinho - http://leandrovieira.com
* @version 0.5
* @date April 11, 2008
* @category jQuery plugin
* @copyright (c) 2008 Leandro Vieira Pinho (leandrovieira.com)
* @license CC Attribution-No Derivative Works 2.5 Brazil - http://creativecommons.org/licenses/by-nd/2.5/br/deed.en_US
* @example Visit http://leandrovieira.com/projects/jquery/lightbox/ for more informations about this jQuery plugin
* To change image height en width: width="'+settings.imageWidth+'" height="'+settings.imageHeight+'" 
*/
(function($) {
    $.fn.lightBox = function(WrapperId, FocusId, settings) {
        settings = jQuery.extend({ overlayBgColor: '#000', overlayDisplay: 'none', overlayOpacity: 0.8 }, settings);

        var jQueryMatchedObj = this;

        function _initialize() { _start(this, jQueryMatchedObj); return false; }
        function _start(objClicked, jQueryMatchedObj) { $('embed, object,select.hidden').css({ 'visibility': 'hidden' }); _set_interface(); _set_focus_to(FocusId); } //select became invisible too. But Residence popup has a selectbox that is visible

        function _set_focus_to(FocusId) { $(FocusId).focus(); }
        function _set_interface() { var arrPageSizes = ___getPageSize(); $('#jquery-Overlay').css({ opacity: settings.overlayOpacity, width: arrPageSizes[0], height: arrPageSizes[1] }).fadeIn(); var arrPageScroll = ___getPageScroll(); $(WrapperId).css({ top: arrPageScroll[1] + (arrPageSizes[3] / 10), left: arrPageScroll[0] }).show(); $('#jquery-Overlay, .closeBtn').click(function() { _finish(); }); $(window).resize(function() { var arrPageSizes = ___getPageSize(); $('#jquery-Overlay').css({ width: arrPageSizes[0], height: arrPageSizes[1] }); var arrPageScroll = ___getPageScroll(); $(WrapperId).css({ top: arrPageScroll[1] + (arrPageSizes[3] / 10), left: arrPageScroll[0] }); }); }

        function _finish() { $(WrapperId).hide(); $('#jquery-Overlay').fadeOut(function() { $('#jquery-Overlay').hide(); }); $('embed, object, select').css({ 'visibility': 'visible' }); }

        function ___getPageSize() {
            var xScroll, yScroll; if (window.innerHeight && window.scrollMaxY) { xScroll = window.innerWidth + window.scrollMaxX; yScroll = window.innerHeight + window.scrollMaxY; } else if (document.body.scrollHeight > document.body.offsetHeight) { xScroll = document.body.scrollWidth; yScroll = document.body.scrollHeight; } else { xScroll = document.body.offsetWidth; yScroll = document.body.offsetHeight; }
            var windowWidth, windowHeight; if (self.innerHeight) {
                if (document.documentElement.clientWidth) { windowWidth = document.documentElement.clientWidth; } else { windowWidth = self.innerWidth; }
                windowHeight = self.innerHeight;
            } else if (document.documentElement && document.documentElement.clientHeight) { windowWidth = document.documentElement.clientWidth; windowHeight = document.documentElement.clientHeight; } else if (document.body) { windowWidth = document.body.clientWidth; windowHeight = document.body.clientHeight; }
            if (yScroll < windowHeight) { pageHeight = windowHeight; } else { pageHeight = yScroll; }
            if (xScroll < windowWidth) { pageWidth = xScroll; } else { pageWidth = windowWidth; }
            arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight); return arrayPageSize;
        };

        function ___getPageScroll() {
            var xScroll, yScroll; if (self.pageYOffset) { yScroll = self.pageYOffset; xScroll = self.pageXOffset; } else if (document.documentElement && document.documentElement.scrollTop) { yScroll = document.documentElement.scrollTop; xScroll = document.documentElement.scrollLeft; } else if (document.body) { yScroll = document.body.scrollTop; xScroll = document.body.scrollLeft; }
            arrayPageScroll = new Array(xScroll, yScroll); return arrayPageScroll;
        };

        return this.unbind('click').click(_initialize);
    };
})(jQuery);