jQuery.fn.center = function (options) {
	var opt = { vertical : true,
				horizontal : true,
				container: window,
				position : 'fixed',
				index : '9999'
	};
	
	$.extend(opt, options);
	return this.each(function(i) {
		var el = $(this);
		var jWin = $(opt.container);
		var isWin = opt.container == window;

		if(opt.position){
			el.css("position", opt.position);
		}
		
		if(opt.index){
		   el.css("z-index", opt.index);
		}
		
		var heightFudge = isWin ? 2.0 : 1.8;
	
        var x = (isWin ? jWin.width() : jWin.outerWidth()) / 2 - el.outerWidth() / 2;
        var y = (isWin ? jWin.height() : jWin.outerHeight()) / heightFudge - el.outerHeight() / 2;
		
		if(opt.vertical === false && opt.horizontal === true){
			el.css("left", x + jWin.scrollLeft());
        	el.css("top", 0);
		}
		else if(opt.horizontal === false && opt.vertical === true){
			el.css("left", 0);
        	el.css("top", y + jWin.scrollTop());
		}
		else if(opt.horizontal === false && opt.vertical === false){
			el.css("left", 0);
        	el.css("top", 0);
		}
		else{
			el.css("left", x + jWin.scrollLeft());
        	el.css("top", y + jWin.scrollTop());
		}
	});
}
