function mdi_widgets_Lightbox() {

	var FADE_EFFECT_TIME = 100;

	var HIDE_PROBLEMATIC_TAGS_CLASS = "hiddenByLightbox";

	var _problematicTags = [ "select", "iframe", "object", "embed" ].join( "," );
	var _lightboxObj = false;

	function _init() {

	}

	function _showLightbox( id ) {

		if( !_setLightboxObj() ) {
			return;
		}

		var children = _lightboxObj.find( "#" + id );
		if( children.length == 0 ) {
			return;
		}

		children.css( {
			"display"		: "block",
			"visibility"	: "visible"
		} );

		_hideProblematicTags();

		_lightboxObj.fadeIn( FADE_EFFECT_TIME );

		if( !children.hasClass( "lightbox-visible" ) ) {
			children.addClass( "lightbox-visible" );
		}

	}

	function _showProblematicTags() {
		$( _problematicTags ).removeClass( HIDE_PROBLEMATIC_TAGS_CLASS );
	}

	function _hideProblematicTags() {

		if( $( _problematicTags ).hasClass( HIDE_PROBLEMATIC_TAGS_CLASS ) ) {
			return;
		}

		$( _problematicTags ).addClass( HIDE_PROBLEMATIC_TAGS_CLASS );

	}

	function _hideLightbox( id ) {

		if( typeof id == "string" ) {
			_lightboxObj.children( "#" + id ).removeClass( "lightbox-visible" ).fadeOut( FADE_EFFECT_TIME, _afterHideLightbox );
		} else if( $( this ).parent().children( ".lightbox-visible" ).hasClass( "lightbox-cant-close" ) ) {
			return;
		} else {
			$( this ).parent().children( ".lightbox-visible" ).removeClass( "lightbox-visible" ).fadeOut( FADE_EFFECT_TIME, _afterHideLightbox );
		}

		if( $( "#lightbox .lightbox-visible" ).length == 0 ) {
			$( "#lightbox" ).hide();
		}

	}

	function _afterHideLightbox() {

		if( $( this ).hasClass( "lightbox-remove-on-close" ) ) {
			$( this ).remove();
		}

	}

	function _hideLightboxes() {

		if( !_setLightboxObj() ) {
			return;
		}

		_lightboxObj.fadeOut( FADE_EFFECT_TIME, function() {

			_lightboxObj.children( ".lb-content" ).css( {
				"display"		: "none",
				"visibility"	: "hidden"
			} );

			_showProblematicTags();

		} );

	}

	function _setLightboxObj() {

		if( _lightboxObj ) {
			return true;
		}

		var lightboxObj = $( "#lightbox" );
		if( lightboxObj.length == 0 ) {
			return false;
		}

		_lightboxObj = lightboxObj;

		_hideLightboxes();

		lightboxObj.find( ".lb-overlay" ).click( _hideLightbox );
		lightboxObj.find( ".lb-close" ).click( _hideLightbox );

		return true;

	}

	return {
		init			: _init,
		showLightbox	: _showLightbox,
		hideLightbox	: _hideLightbox,
		hideLightboxes	: _hideLightboxes
	};

}

var lightboxWidget = new mdi_widgets_Lightbox();
