(function($) {
$.fn.ui_overlay = function(options) {

	
	this.each(function() {	
	
	
		return ui_overlay(target, options);
	
  	})
  
}

ui_overlay = function (target, options) {


		return new ui_fn_overlay(target, options);

}
ui_fn_overlay = function (target, options) {


		this.target = target;
		
		this.settings= $.extend({}, $.fn.ui_overlay.defaults, options);

		this.overlay_create()
		if (this.settings.toFront || this.target== 'body') { $(this.overlay).ui_set_to_front()}
		if (this.settings.spinner) {this.overlay_spinner()}
		this.overlay_add()
		
		return this.overlay

}

ui_fn_overlay.prototype = {

  	
  	overlay_add : function () {
  	
  		return $(this.overlay).prependTo(this.target);
  	
  	},
	  	
  	overlay_create : function () {
  	
  	 this.overlay = $('<div/>', {'class': 'ui-overlay'});

  	 
  	 if(this.target== 'body') { 
  	 
  	 
  	 	$(this.overlay).css({position:'fixed'}).width($(window).width()).height($(window).height());

  	
  	 } else {
  	 
  	 	$(this.overlay).css({position:'absolute'}).ui_resize_to_container(this.target)  	 
  	 } 

  	 
  	 	$(this.overlay).css({left:0,top:0,backgroundColor:this.settings.color, opacity:this.settings.opacity});
  	
  	},
  	 	 	
  	overlay_spinner: function () {
  	
  		$(this.overlay).addClass('ui-spinner');
  	  	
  	}


}

$.fn.ui_overlay.defaults = {
	zIndex: 1000,
	spinner:true,
	color:'gray',
	toFront:false,
	opacity:0.5	
}; 
 })(jQuery);