// necesita jquery.dimensions.js plugin
jQuery.fn.centra = function(x,y) {
         var leftPos=0,topPos=0;
         if(x) jQuery(this).css({width: x+'px'});
		 if(y) jQuery(this).css({height: y+'px'});

        return this.each(function() {
		if(x)leftPos = (jQuery(window).width() - jQuery(this).outerWidth()) / 2 + jQuery(window).scrollLeft();
        if(y)topPos = (jQuery(window).height() - jQuery(this).outerHeight()) / 2 + jQuery(window).scrollTop();

                // Make sure element is not out of bounds
                leftPos = (leftPos < 0) ? 0 : leftPos;
                topPos = (topPos < 0) ? 0 : topPos;
                if(y) jQuery(this).css({top: topPos +'px'});
				if(x) jQuery(this).css({left: leftPos +'px'});
})
};