/*
 * jquery.centerElement.js (version 1.0)
 *
 * Centers all matched elements.
 *
 * HTML:
 * <div id="Modal">A Modal Box</div>
 *
 * CSS:
 * #Modal { border: 1px solid #ddd; }
 *
 * JavaScript:
 * $('#Modal').centerElement();
 *
 * I made this. (SmallSharpTools.com - 2008)
 *
 * License: Creative Commons
 *
 */
(function($) {

    $.fn.centerElement = function(options) {

        var opts = $.extend({}, $.fn.centerElement.defaults, options);

        return this.each(function() {

            // Position
            var wWidth = $(window).width();
            var wHeight = $(window).height();
            var width = $(this).width();
            var height = $(this).height();
            
            var topPos = parseInt((wHeight / 2) - (height / 2), 10) + $(window).scrollTop() + 'px';
            var leftPos = parseInt((wWidth / 2) - (width / 2), 10) + 'px';
            
            $(this).
                css("position", opts.position).
                css("top", topPos).
                css("left", leftPos).
                css("z-index", opts.zIndex);

        });

    };

    // publicly accessible defaults
    $.fn.centerElement.defaults = {
        position: 'absolute',
        zIndex: '100'
    };

})(jQuery);

