﻿jQuery.fn.center = function(offsetTop, offsetLeft) {
	if (!offsetTop) offsetTop = 0;
	if (!offsetLeft) offsetLeft = 0;
	
	this.css("position", "absolute");
	this.css("top", (($(window).height() - this.height()) / 2 + $(window).scrollTop()) + offsetTop + "px");
	this.css("left", (($(window).width() - this.width()) / 2 + $(window).scrollLeft()) + offsetLeft + "px");
	
	return this;
}

jQuery.fn.centerPosition = function (centerVertical, top, centerHorizontal, left) {

	this.css("position", "absolute");
	this.css("top", (centerVertical ? (($(window).height() - this.height()) / 2 + $(window).scrollTop()) + top : top) +  "px");
	this.css("left", (centerHorizontal ? (($(window).width() - this.width()) / 2 + $(window).scrollLeft()) + left : left) + "px");
	return this;
}
