
jQuery.fn.jAlign = function(options){
	
	var defaults = {  
	   vertical: true,  
	   horizontal: true,
	 	 top_margin: 0 //value in pixels
	  };
	
	var options = jQuery.extend(defaults, options);  
	
	return this.each(function(i){
		if(options.vertical == true && options.top_margin == 0)
		{
			var h = jQuery(this).height();
			var oh = jQuery(this).outerHeight();
			var mt = (h + (oh - h)) / 2;	
			jQuery(this).css("margin-top", "-" + mt + "px");	
			jQuery(this).css("top", "50%");
			jQuery(this).css("position", "absolute");
		};
		if (options.horizontal == true) {
			var w = jQuery(this).width();
			var ow = jQuery(this).outerWidth();	
			var ml = (w + (ow - w)) / 2;	
			jQuery(this).css("margin-left", "-" + ml + "px");
			jQuery(this).css("left", "50%");
			jQuery(this).css("position", "absolute");
		};
		if (options.top_margin > 0) {
			jQuery(this).css("top", options.top_margin + "px");
			jQuery(this).css("position", "absolute");
		};
	});
}