jQuery.fn.centerScreen = function(loaded) {
    var obj = this;
    var windowH = $(window).height();
    var windowW = $(window).width();
    var thisH = this.height();
    var thisW = this.width();
    var scrollTop = $(document).scrollTop();

    var top = (windowH - thisH) / 2 + scrollTop;
    var left = $(window).width() / 2 - this.width() / 2;

    if (top < 0)
        top = 10;
    if (left < 0)
        left = 10;

    if (!loaded) {
        obj.css('position', "absolute");
        obj.css('top', top);
        obj.css('left', left);
        $(window).resize(function() { obj.centerScreen(!loaded); });
    } else {
        obj.stop();

        obj.css('position', "absolute");
        obj.css('top', top);
        obj.css('left', left);

        //obj.animate({ top: $(window).height() / 2 - this.height() / 2, left: $(window).width() / 2 - this.width() / 2}, 200, 'linear');
    }
}

