function ModalElement(options) 
{
	options = options ? options : {};
	// INI: Private properties
	var _options = {
		bgColor		: options && options.bgColor ? options.bgColor : '#000',
		opacity		: options && options.opacity ? options.opacity : '0.8',
		fixed		: options && options.fixed === false   ?  false : true,
		modal		: options && options.modal === true   ?  true : false
	};
	var _element = null;
	var _originalCss = {};
	
	var _background = jQuery('<div id="ModalElementBackground"></div>');
	var _this = this;

	var _zIndex = 10000;
	// END: Private properties
	
// INI: Public methods
	// Show Any element in modal mode
	this.showElement = function(elementSelector) {		
		this.hide(function(){
			if (!jQuery(elementSelector).length) {
				return;
			}
			// Get the element to set modal
			_element = jQuery(jQuery(elementSelector).get(0));
			// Get the original css basic properties
			_originalCss.display = _element.css('display');
			_originalCss.position = _element.css('position');
			_originalCss.top = _element.css('top');
			_originalCss.left = _element.css('left');
			_originalCss.width = _element.css('width');
			_originalCss.height = _element.css('height');
			// Replace the original element
			_element.after(jQuery('<div id="AuxiliarElement" />').css(_originalCss));
			// Resize the elements (background,_element)
			_resize();
			// Reposition the modal element
			jQuery('body').append(_element);
			// Show element in modal mode
			_background.fadeIn('fast', function(){
				_element.fadeIn('fast');
			});
		});
	};
	this.hide = function(callback) {
		if (_element) {
			_element.fadeOut('fast', function(){
				jQuery('#AuxiliarElement').replaceWith(_element.css(_originalCss));
				_background.fadeOut(callback || function(){ });
			});
		}
		else if(callback) {
			callback();
		}
	};
	
// INI: Public methods
	function _resize() {
		if (_element && _element.length > 0) {
			var top = (jQuery(window).height() / 4) - (jQuery(_element).height() / 4);
			var left = (jQuery(window).width() / 2) - (_element.width() / 2);
			var position = _options.fixed ? 'fixed' : 'absolute';
			
			// If ie6, only position 'absolute'
			if (navigator.appVersion.indexOf('MSIE 6.0') != '-1') {
				position = 'absolute';
			}
			
			// Resize background
			_background.css({
				zIndex: 100,
				top: 0,
				left: 0,
				width: jQuery(window).width() + 'px',
				height: jQuery(document).height() > jQuery(window).height() ? jQuery(document).height() : jQuery(window).height() + 'px'
			});
			
			// Move the element to center
			_element.css({
				position: position,
				top: top < 50 ? 50 : top,
				left: left,
				zIndex: 101
			});
		}
	}
// INI: Private methods
	
// END: Private methods

// Constructor
	(function(){
		// setup background element
		if (jQuery.browser.msie){
			_background
				.css({ 
					filter : 'alpha(opacity = 50)', 
					position : 'absolute', 
					background : _options.bgColor, top : 0, left : 0, display : 'none'
				})
				.click(function() {
					if ( !_options.modal ) {
						_this.hide(); 
					}
				});
		}
		else {
			_background
				.css({
					opacity	: _options.opacity, 
					position : 'absolute', 
					background : _options.bgColor, top : 0, left : 0, display : 'none'
				})
				.click(function() {
					if ( !_options.modal ) {
						_this.hide(); 
					}
				});
		}		
		
		// append background element to body
		jQuery('body').append(_background);
		jQuery(window).resize(_resize);					
	}());
}
