﻿/*
* jQuery popBox
* Copyright (c) 2010 Simon Hibbard
* 
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:

* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE. 
*/

/*
* Version: V1.2.1
* Release: 26-01-2011
* Based on jQuery 1.4.2
* Additional features provided with thanks to Alex Lareau
*/

(function ($) {
    var popID = 0;
    $.fn.modalPopLite = function (options) {
        var options = $.extend({}, { openButton: "modalPopLite-open-btn", closeButton: "modalPopLite-close-btn" }, options);

        return this.each(function () {
            popID++;
            var thisPopID = popID;

            obj = $(this);
            triggerObj = options.openButton;
            closeObj = options.closeButton;

            //alert("winH: " + winH + "top: " + top + "objH: " + objH);
            obj.before('<div id="modalPopLite-mask' + thisPopID + '" style="width:100%" class="modalPopLite-mask" />');
            obj.wrap('<div id="modalPopLite-wrapper' + thisPopID + '" style="left: -10000px;" class="modalPopLite-wrapper" />');


            $(triggerObj).live("click", function (e) {
                e.preventDefault();
                var winW = $(window).width();
                var winH = $(window).height();
                var objW = obj.width();
                var objH = obj.height();
                var left = (winW / 2) - (objW / 2);
                var top = (winH / 2) - (objH / 1.5);

                $('#modalPopLite-mask' + thisPopID).css('height', winH + "px");
                $('#modalPopLite-mask' + thisPopID).fadeTo('slow', 0.6);
                //$('#modalPopLite-wrapper' + thisPopID).hide();
                $('#modalPopLite-wrapper' + thisPopID).css({'left': left + "px", 'top': top});
                $('#modalPopLite-wrapper' + thisPopID).fadeIn('slow');
            });

            $(closeObj).live("click", function (e) {
                e.preventDefault();
                $('#modalPopLite-mask' + thisPopID).hide();
                //$('#modalPopLite-wrapper' + thisPopID).hide();
                $('#modalPopLite-wrapper' + thisPopID).css('left', "-10000px");
            });

            //if mask is clicked
            $('#modalPopLite-mask' + thisPopID).click(function (e) {
                e.preventDefault();
                $(this).hide();
                //$('#modalPopLite-wrapper' + thisPopID).hide();
                $('#modalPopLite-wrapper' + thisPopID).css('left', "-10000px");
            });
        });

    };

    $.fn.modalPopLite.Close = function (id) {
        $('#modalPopLite-mask' + id).hide();
        //$('#modalPopLite-wrapper' + id).hide();
        $('#modalPopLite-wrapper' + thisPopID).css('left', "-10000px");
    };

    $.fn.modalPopLite.ShowProgress = function () {
        $('<div class="popBox-ajax-progress"></div>').appendTo("body")
    };

    $.fn.modalPopLite.HideProgress = function () {
        $("body").remove('.popBox-ajax-progress');
    };

})(jQuery);

