﻿jQuery.fn.center = function(options) {
    var settings = { vertical: true, horizontal: true };
    $.extend(settings, options);
    this.css("position", "absolute");
    if (settings.vertical) {
        if ($(window).height() > this.height())
            this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
    }
    if (settings.horizontal) {
        if ($(window).width() > this.width())
            this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
    }
    return this;
}

