/**
 *
 * center jQuery Plug-in
 *  
 * @author popula
 * @version 0.9 
 * 
 * @param vertical (true)/false. center vertically
 * @param horizontal (true)/false. center horizontally
 * @param zIndex: set z-index (default 0 = do not set z-index!)
 * 
 */

jQuery.fn.center = function (options) {
	options = jQuery.extend({
		vertical: true,
		horizontal: true,
		zIndex: 0,
		centerTo: null
		}, options);
	return this.each(function () {
		var o = $(this);

		if (options.zIndex != 0) {
			o.css({
				zIndex: options.zIndex
			})
		}
		var relObj = o; 
		if (options.centerTo) {
			relObj = $('#main');
		}
		if (!relObj) {
			throw 'relObj not defined!';
			return;
		}
		if (options.vertical === true) {
			o.css({
				top: relObj.offset().top + (relObj.height() / 2) + 'px'
			}).css({
				marginTop:	'-' + (o.outerHeight() / 2) + 'px'
				});
		}
		if (options.horizontal === true) {
			o.css({
				left: relObj.offset().left + (relObj.width() / 2) + 'px'
			}).css({
				marginLeft:	'-' + (o.outerWidth() / 2) + 'px'
			});;
		}
	});
};