/* 
 * Center plugin - center element on screen
 * v0.2 - 12/11/2008
 * - added ability to center in another element besides window
 */
(function($){
	$.fn.center = function(el)
	{
		// Get element dimensions
		var height = $(this).innerHeight();
		var width = $(this).innerWidth();
		
		// Figure out offset of container
		if(el)
		{
			var left = ($(el).innerWidth() - width) / 2;
			var top = ($(el).innerHeight() - height) / 2;
		}
		else
		{
			var scroll = $(window).scrollTop();
			var left = ($(window).width() - width) / 2;
			var top = (($(window).height() - height) / 2) + scroll;
		}
		
		// Make sure lightbox doesn't go above top of window
		if (top < 50)
		{
			top = 50;
		}
		
		$(this).css({left: left, top: top});
		
		return this;
	};
})(jQuery);
