/**
 * The show must go on.
 */
var Show = new function () {

	this.name = "ToolsAndDrinks";
	
	var isWelcomeBrowser = true;
	var canvas = null;
	var ctx = null;
	var CANVAS_COLOR = "rgba(248,248,245,1)";
	var FLASH_TIMEOUT = 2000;
	var hasNavigated = false;
	
	/**
	 * Action on DOMContentLoaded.
	 */
	this.ondom = function () {
		
		if ( Client.isExplorer6 ) {
			
			isWelcomeBrowser = false;
		
		} else if ( !Client.isExplorer ) {
			
			try {
				canvas = document.createElement ( "canvas" );
				canvas.setAttribute ( "width", "540" );
				canvas.setAttribute ( "height", "515" );
				
				ctx = canvas.getContext( "2d" );
				ctx.fillStyle = CANVAS_COLOR;
				ctx.fillRect ( 0, 0, 540, 515 );
				
			} catch ( oldBrowserException ) {
				
				isWelcomeBrowser = false;
			}
		}
		
		if ( isWelcomeBrowser ) {
			
			
			var div = document.createElement ( "div" );
			div.id = "scene2cover";
			
			document.getElementById ( "body" ).appendChild ( div );
			document.getElementById ( "body" ).style.backgroundImage = "url(\"/Frontend/Images/Splashes/simpleefficientscene.jpg\")";			
			document.getElementById ( "fallbacknav" ).style.display = "none";
			document.getElementById ( "theatrenav" ).style.display = "block";
			
			if ( !Client.isExplorer ) {
				div.appendChild ( canvas );
			}
		}
		
		
	}
	
	/**
	 * Praise the Manager.
	 */
	Manager.ondom ( this );
	
	/**
	 * Introduce new scene.
	 */
	this.enter = function ( scene, direction ) {
		
		switch ( scene ) {
			case 1 :
				fade ( true );
				break;
		}		
	}
	
	/**
	 * Exit old scene.
	 */
	this.exit = function ( scene, direction ) {
		
		switch ( scene ) {
			case 1 :
				hasNavigated = true;
				fade ( false );
				break;
		}
	}
	
	/**
	 * This fades the background cover.
	 * @param {boolean} isFadeIn
	 */
	function fade ( isFadeIn ) {
		
		if ( Client.isExplorer ) {
		
			var cover = document.getElementById ("scene2cover");
			cover.filters[0].Apply();
			
			if ( isFadeIn ) {
				cover.style.backgroundColor = "transparent";
			} else {
				cover.style.backgroundColor = "rgb(248,248,245)";
			}
			cover.filters[0].Play ();
			
		} else {
			
			function color ( alpha ) {
				ctx.globalAlpha = alpha;
				ctx.clearRect ( 0, 0, 800, 600 );
				ctx.fillStyle = CANVAS_COLOR;
				ctx.fillRect ( 0, 0, 800, 600 );
			}
			
			if ( isFadeIn ) {
				var i = 1;
				window.fadeinterval = window.setInterval ( function () {
					color ( i )
					if ( i == 0 ) {
						window.clearInterval ( window.fadeinterval );
					} else {
						i = i - 0.125;
					}
			    	}, 10 );
			} else {
				i = 0;
				window.fadeinterval = setInterval ( function () {
					color ( i );
					if ( i == 1 ) {
						window.clearInterval ( window.fadeinterval );
					} else {
						i = i + 0.25;
					}
			    	}, 10 );
			}
		}
	}
}
