$(document).ready(function(){
    
    /**
     * SpryModal
     * 
     * @version 1.0 < 01.04.2011 >
     * 
     * 
     * #modal_wrapper{display: none;position: absolute;z-index: 1200;top:0px;left:0px;}
     * 
     */
    (function($){
        
        $.spryModal = {
            options: {
              show              : true,  // set it to false to hide the modal
              centerOnScroll    : true   // center modal when scrolling the page
            },
            elements: []
        };

        
        $.fn.spryModal = function(options){
            
            options = $.extend($.spryModal.options, options);
            
            return this.each(function(index) {
                if (index == 0) {
                    var $this = $(this);
                    
                    if(options.show === true)
                    {

                        // center on modal activation
                        $this.show().positionCenter();    
                        
                        // center modal on page scroll
                        if(options.centerOnScroll === true)
                        {
                            $(window).bind('scroll', function () { 
                               $this.positionCenter();
                            });
                        }
                        
                        /** -----------------------------
                         *  show and create modal background
                        -----------------------------  */
                        $this.before('<div id="modalBackground"></div>');
                        
                        var modalHeight = $(document).height();
                                                
                        $('#modalBackground').height( modalHeight ).css({
                            'position'      : 'absolute',
                            'z-index'       : '1100',
                            'width'         : '100%',              
                            'top'           : '0',
                            'left'          : '0',
                            'background'    : '#000',
                            'opacity'       : 0.9
                        });
                    }
                    else
                    {
                        // hide modal
                        $this.hide();
                        
                        // remove modal background
                        $('#modalBackground').remove();
                        
                        if(options.centerOnScroll === true)
                        {
                            $(window).unbind('scroll');
                        }
                    }
                                
                }
            });

        };
    })(jQuery);
    
});

