/*
 * jQuery simpleLightbox v1.1.0 
 *
 * Copyright (c) 2008 Taranets Aleksey
 * www: markup-javascript.com
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 */

jQuery.fn.gLightbox = function(_options) {
    // defaults options	
    var _options = jQuery.extend({
        lightboxContentBlock: '.popup',
        closeLink: 'a.close-btn, a.close',
        _ancor: ".page-holder",
        _gmapContainer: "#outContainer",
        href: true,
        onClick: null
    }, _options);

    return this.each(function(i, _this) {
        var _this = jQuery(_this);
        if (!_options.href)
            _this.lightboxContentBlock = _options.lightboxContentBlock;
        else _this.lightboxContentBlock = _this.attr('href');
        if (_this.lightboxContentBlock != '' && _this.lightboxContentBlock.length > 1) {
            _this.closeLink = _options.closeLink;
            var _lightbox = $(_this.lightboxContentBlock);
            var _gContainer = $(_options._gmapContainer);
            _lightbox.css('zIndex', 1999);
            _this.ancor = $(_options._ancor);
            _this.click(function() {

                if (jQuery.isFunction(_options.onClick)) {
                    _options.onClick.apply(_this);
                }

                _lightbox.fadeIn(400);
                _gContainer.css({ "visibility": "visible" });
                jQuery.fn.gLightbox.positionLightbox(_lightbox, _gContainer);
                return false;
            });

            jQuery(_this.closeLink).click(function() {
                _lightbox.fadeOut(400);
                _gContainer.css({ "visibility": "hidden" });
                return false;
            });

            jQuery.fn.gLightbox.positionLightbox = function(_lbox, _gcontainer) {
                var _height = 0;
                var _width = 0;
                var _minWidth = $('body > div:eq(0)').outerWidth();
                if (window.innerHeight) {
                    _height = window.innerHeight;
                    _width = window.innerWidth;
                } else {
                    _height = document.documentElement.clientHeight;
                    _width = document.documentElement.clientWidth;
                }
                var _thisHeight = _lbox.outerHeight();
                var _thisWidth = _lbox.outerWidth();
                var _page = $('body');

                var pageScroll = parseInt($(document).scrollTop());

                var popupHeight = _lbox.height();
                var popupWidth = _lbox.width();
                _lbox.css({
                    "position": "fixed",
                    "z-index": 100000,
                    "top": _this.ancor.position().top / 2 - pageScroll + _thisHeight * 1 / 2 + 35 + "px",
                    "left": _width / 2 - _thisWidth / 2
                });

                $(_gContainer).css({
                    "position": "fixed",
                    "z-index": 100000,
                    "top": _this.ancor.position().top / 2 - pageScroll + 30 + _thisHeight * 1 / 2 + 35 + "px",
                    "left": _width / 2 - _thisWidth / 2 + 12 + "px"
                });

                $(_gContainer).hide().fadeIn();
            }

            jQuery(window).resize(function() {
                jQuery.fn.gLightbox.positionLightbox(_lightbox, _gContainer);
            });

            jQuery(window).scroll(function() {
                jQuery.fn.gLightbox.positionLightbox(_lightbox, _gContainer);
            });


            jQuery.fn.gLightbox.positionLightbox(_lightbox, _gContainer);

            $(document).keydown(function(e) {
                if (!e) evt = window.event;
                if (e.keyCode == 27) {
                    _lightbox.fadeOut(400);
                    _gContainer.css({ "visibility": "hidden" });
                }
            });
        }
    });
}
$(document).ready(function(){
	$('a.gmapContent').each(function(){
		$(this).gLightbox();
	});
});



	