/*
* popup_video.js
* ScreenToaster
* Michael Bagur
*
* hack to hide flash videos when opening a popup
*
******************************************************/

/*
* hide the video (needed when opening a popup)
* else flash video will stay on top of the html mask
*/
function hideVideo() {
	try  {
		// Hide the embed and set a black background
		if (document.getElementById('videoEmbed'))
			document.getElementById('videoEmbed').style.visibility = "hidden";
		if (document.getElementById('videoObject'))
			document.getElementById('videoObject').style.visibility = "hidden";
		if (document.getElementById('videoContainer'))
			document.getElementById('videoContainer').style.backgroundColor = "black";


	// Catch errors
	} catch (e) {
		logger.error("popup_video.js > hideVideo(): "+e);
	}
}

/*
* redisplay the video
*/ 
function showVideo() {
	try {
		// Show the embed and set a white background
		if (document.getElementById('videoEmbed'))
			document.getElementById('videoEmbed').style.visibility = "visible";
		if (document.getElementById('videoObject'))
			document.getElementById('videoObject').style.visibility = "visible";
		if (document.getElementById('videoContainer'))
			document.getElementById('videoContainer').style.backgroundColor = "white";
		
	// Catch errors
	} catch (e) {
		logger.error("popup_video.js > showVideo(): "+e);
	}
}

jQuery(function() {
	try {
		var oldOpenPopup = openPopup;
		var oldClosePopup = closePopup;
		
		(function($) {
			$.fn.closePopup = function() {
				try {
					// cache le popup
					this.fadeOut(500);
					
					// cache le masque
					$("#mask").fadeOut(500);
					
					showVideo();
					
				// Catch errors
				} catch (e) {
					logger.error("popup_video.js > closePopup(): "+e);
				}
				
				return false;
			}
		})(jQuery);
		
		openPopup = function(elementId) {
			hideVideo();
			oldOpenPopup(elementId);
		}
		
		closePopup = function(elementId) {
			showVideo();
			oldClosePopup(elementId);
		}
	// Catch errors
	} catch (e) {
		logger.error("popup_video.js > jQuery onLoad() : "+e);
	}
});