﻿/* 
* Part of Nitriques Solutions inc. (http://www.nitriques.com) jQuery plug-in bundle
* Liscence under the The Code Project Open License (CPOL)
* http://www.codeproject.com/info/cpol10.aspx

* Name: jquery.center.js
* Date: 2010-01-08
* Version: 1.1

* Pre-requisites: none;

* Copyrights (c) Tony L.
* Found on 2010-01-08 at http://stackoverflow.com/questions/210717/what-is-the-best-way-to-center-a-div-on-the-screen-using-jquery

* v1.1
* Added safe block (function ($) {...})(jQuery) for noConflict
* Added a negative top verification if (top < 0) {top = 0;}

* v1.0.1
* Added -40px to the top, it gives a better effect
* Changed plugin declaration, function name

* v1.0 
* Original release

*/
(function ($) {
$.fn.extend({ // jQuery plugin
    ntr$center: function() {
        var top = ($(window).height() - this.height()) / 2 + $(window).scrollTop() - 40;
        if (top < 0) {top = 0;}
    
        this.css("position", "absolute");
        this.css("top", (top + "px"));
        this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
        return this;
    }
});
})(jQuery);
