(function( $ ){
	$.fn.videoLightbox = {
		ready:true,
		isActive:false,
		lightboxMarkup:"<div id='lightbox_wrapper_bkgd' class='lightbox_wrapper_bkgd'>" + "<p>My content</p>" + "</div>" + "<div id='lightbox_horizon'><div id='lightbox_content' class='white_content'>" + "<div class='lightbox_menu'><ul><li><a id='lighbox_menu_close_btn' href='#'>X</a></li></ul></div>" + "</div></div>",
		$lightBoxBackground:null,
		$lightBoxContent:null,
		$hiddenFlashContent:[],
		showPlayer:function( url )
		{
			if (this.ready)
			{
				if(!this.isActive)
				{
					// hide all flash content 
					$(document).find("object").each(function()
					{
						$(this).attr("style", "visibility: hidden")
						this.$hiddenFlashContent = [];
						this.$hiddenFlashContent.push( $(this) )
						// console.log("Hiding flash item ")
					})
					
					$("body").append(this.lightboxMarkup)
					
					$lightBoxBackground = $("#lightbox_wrapper_bkgd");
					$lightBoxContent = $("#lightbox_horizon");
					this.isActive = true;
					// console.log("Added lightbox to stage")
					
					$("#lighbox_menu_close_btn").click( function() 
					{
						// console.log("Please close the lightbox")
						
						$.fn.videoLightbox.hidePlayer();
					})
					
				} else 
				{
					// console.warn("Lightbox already on stage")
				}
				
			} else 
			{
				// Not ready yet
			}
		}, 
		hidePlayer:function() 
		{
			if(this.isActive)
			{
				// console.log("Remove lightbox to stage")
				
				for(var i in this.$hiddenFlashContent)
				{
					// console.log("Showing flash item ")
					this.$hiddenFlashContent[i].attr("style", "visibility: visible")
				}
				
				// $lightBoxBackground.detach()
				// $lightBoxContent.detach()
				$lightBoxBackground.remove()
				$lightBoxContent.remove()
				this.isActive = false;
				
			} else 
			{
				// console.warn("Lightbox not on stage")
			}
		}
		
	}
	
	$.showPlayer = function( url )
	{
		$.fn.videoLightbox.showPlayer( url );
	};
	
	$.hidePlayer = function()
	{
		$.fn.videoLightbox.hidePlayer();
	};
		
})( jQuery );
