/*
Project: jQuery Overlay Class Javascript file
Author: Zoltan Radics / zoltan.radics@gmail.com
*/

 (function($) {
    var methods = {
        init: function(option) {
            $('body').append('<div id="overlay"><div id="overlayContent"></div><a id="overlayClose" class="overlayClose" href="#" title=""></a></div>');
            
            $('.overlayClose').click(function() {
                $('#overlay').fadeOut('fast',
                function() {
                    $(this).remove();
                });
                return false;
            });
            
        
            $('#overlayContent').load(option.url,
            function(response, status, xhr) {
                $('#overlay').css('height', $(document).height());
                $('#overlay').fadeIn('fast',
                function() {
                    $('#overlayClose').css('left', (($(window).width() / 2) + ($('#overlayContent').width() / 2) + 25)).css('top', 30);
                    $('#overlayContent').css('left', (($(window).width() / 2) - ($('#overlayContent').width() / 2))).css('top', 40);
                    $('#overlayContent').fadeIn('fast');
                });
            });
        }
    };
    $.fn.overlay = function(method) {
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            return methods.init.apply(this, arguments);
        } else {
            $.error('Method ' + method + ' does not exist on jQuery.overlay');
        }
    };
})(jQuery);

