(function($) {
	
	Namespace('MFMedia.BackgroundVideo', (function() {
		var videoPlayer, videoPlayerId;
		var videoPlayerUrl = MFMediaSettings.templateUrl + '/flash/bg-video-player.swf';
		var videoUrl = "http://bitcast-a.v1.ord1.bitgravity.com/botr/sAmgQFeZ/videos/NxHouJVk-34281.mp4";// 'bg-videos/' + MFMediaSettings.videoFilename;
		var videoPlayerParams = {
			'scale': 'showall',
			'play': 'false',
			'loop': 'true',
			'wmode': 'opaque',
			'bgcolor': '#000000',
			'allowScriptAccess': 'always',
			'salign': '',
			'repeat': 'always'
		};
		
		/**
		 * Starts playing the video when the player is ready
		 */
		var startPlayer = function() {
			//alert(videoPlayerId);
			if (document[videoPlayerId] && document[videoPlayerId].load) {
				videoPlayer = document[videoPlayerId];
				//videoPlayer.forceResize();
				videoPlayer.load(videoUrl, false);
				//alert(videoUrl);
			} else {
				setTimeout(startPlayer, 200);
			}
		};
		
		var toggle = function() {
			if (MFMedia.BackgroundVideo.playing) {
				MFMedia.BackgroundVideo.pause();
			} else {
				MFMedia.BackgroundVideo.play();
			}
		};
	
		return {
			
			'playing': true,
			'autoPlay': true,
			
			/**
			 * Creates the flash player and place it on the page
			 */
			'init': function(id) {
				videoPlayerId = id;
				
				swfobject.embedSWF(
					videoPlayerUrl, 
					videoPlayerId, 
					"100%",
					"100%", 
					'9.0.0', 
					'expressInstall.swf', 
					{}, 
					videoPlayerParams, 
					{}
				);
				
	
				
				//$('#video-button').click(toggle);
				startPlayer();
			},
			
			'isloaded' : function() {
				if (videoPlayer && videoPlayer.load && MFMedia.readyVideo) {
					$('#imgembed').css('display', 'none');
					MFMedia.BackgroundVideo.play();
				} else {
					setTimeout(MFMedia.BackgroundVideo.isloaded, 200);
				}
			},
			
			/**
			 * Play the video
			 */
			'play': function() {
				videoPlayer && videoPlayer.playVideo();
				MFMedia.BackgroundVideo.playing = true;
				//$('#video-button').html(MFMediaLocale.PauseTheVideo);
			},
			
			/**
			 * Pause the video
			 */
			'pause': function() {
				videoPlayer && videoPlayer.pauseVideo();
				MFMedia.BackgroundVideo.playing = false;
				//$('#video-button').html(MFMediaLocale.PlayTheVideo);
			},
			
			'toggle': toggle
		};
		
	})());
	
})(jQuery);

