<!--

	// this is a sample JavaScript file, intended to show how you can use
	// MediaFrame's API to build up a player around the software.  More examples
	// and demo's can be seen in the documentation, found on the project site
	

	// Variables	
	var monitor_started = 0;
	
	
	// This function is called when MediaFrame finishes playback.  It is
	// set to rewind the video in this case
	function mediaframe_stop(){
		setTimeout('document.mediaframe.playerrewind()', 2500);
	}
	
	
	// This function is called when MediaFrame begins playback
	function mediaframe_start(){
	}
	
	
	// This function is called when MediFrame is ready to begin video
	// playback
	function mediaframe_ready(){
		if(monitor_started == 0) {
			monitor_started = 1;
		}
	}
	
	
	// This function polls the player and updates returns its current state
	// to an element within the HTML page
	function MFMonitor(){
		var movie_length = document.mediaframe.get_video_length();
		if(movie_length > 0) {
			movie_length = Math.round(movie_length / 1000);
			var seconds = movie_length % 60;
			movie_length = Math.floor(movie_length / 60) + ':' + Math.floor(seconds / 10) + (seconds % 10);
		}
		
		var current_time = document.mediaframe.get_video_time();
		if(current_time >= 0) {
			current_time = Math.round(current_time / 1000);
			var seconds = current_time % 60;
			current_time = Math.floor(current_time / 60) + ':' + Math.floor(seconds / 10) + (seconds % 10);
		}
		
		var current_time_ms = document.mediaframe.get_video_time();
		
		setHTML('filename: ' + document.mediaframe.get_filename()
			+ '<br />Player state: ' + document.mediaframe.get_mf_state()
			+ '<br />User connection speed: ' + document.mediaframe.get_connection_speed() + 'kbps'
			+ '<br />Video length: ' + movie_length
			+ '<br />Playback time (milli seconds): ' + current_time_ms
			+ '<br />Playback time (seconds): ' + current_time
			+ '<br />Mute: ' + document.mediaframe.get_audio_state()
			+ '<br />Volume: ' + document.mediaframe.get_volume()
			+ '<br />Volume %: ' + document.mediaframe.get_volume('%')
			+ '<br />Error code: ' + document.mediaframe.get_errorcode()
			+ '<br />Error text: ' + document.mediaframe.get_errortext()
			);
		
		setTimeout('MFMonitor()', 100);
	}
	
	
	// Write the current state to the in-page feedback box
	function setHTML(text) {
		var feedbackbox = document.getElementById("feedback_agent");
		feedbackbox.innerHTML = text;
	}
	
	
	// Write subtitlecontent to the subtitle box in-page
	function setSubtitles(text) {
		var subtitlebox = document.getElementById("subtitles");
		subtitlebox.innerHTML = text;
	}
	
	
	// This function returns the current player state in alert boxes
	function getMFState() {
		alert("mute = " + document.mediaframe.get_audio_state());
		alert("filename = " + document.mediaframe.get_filename());
		alert("movie size = " + document.mediaframe.get_video_size());
		alert("player state = " + document.mediaframe.get_mf_state());
		alert("error code = " + document.mediaframe.get_errorcode());
		alert("connection speed = " + document.mediaframe.get_connection_speed());
		alert("volume = " + document.mediaframe.get_volume());
		alert("volume (%) = " + document.mediaframe.get_volume('%'));
	}
	
	
	// You can subtitle your video by polling MediaFrame's current
	// playtime and then writing the subtitles to a layer in-page
	function MFSubtitle() {
		var time = document.mediaframe.get_video_time();
		
		if(time >= 0) {
			time = Math.round(time / 1000);
			var seconds = time % 60;
			time = Math.floor(time / 60) + ':' + Math.floor(seconds / 10) + (seconds % 10);
		}
		
		if (time == '0:06') {
			setSubtitles('<p><strong>Grandfather:</strong> Have you ever seen a single person going into that factory?</p>');
		} else if (time == '0:10') {
			setSubtitles('<p><strong>Charlie:</strong> There must people working there.</p>');
		} else if (time == '0:12') {
			setSubtitles('<p><strong>Grandfather:</strong> The only thing that comes out of that place is the candy.</p>');
		} else if (time == '0:15') {
			setSubtitles('<p><strong>Grandfather:</strong> I\'d give anything in the world, just to go in that amazing factory!</p>');
		} else if (time == '0:21') {
			setSubtitles('');
		} else if (time == '0:24') {
			setSubtitles('<p><strong>Wonker:</strong> Dear people of the World...</p>');
		} else if (time == '0:27') {
			setSubtitles('<p><strong>Wonker:</strong> I Willy Wonker, have decided to allow five children to visit my factory.</p>');
		} else if (time == '0:32') {
			setSubtitles('<p><strong>TV broadcast:</strong> Five golden tickets have been hidden underneath the wrapping paper of five ordinary Wonker bars.</p>');
		} else if (time == '0:37') {
			setSubtitles('<p><strong>Grandfather:</strong> Wouldn\'t it be something Charlie, to open a bar of candy and to find a golden ticket... ?</p>');
		} else if (time == '0:42') {
			setSubtitles('<p><strong>Charlie:</strong> But I only get one bar a year...</p>');
		} else if (time == '0:44') {
			setSubtitles('<p><strong>Grandfather:</strong> Nothings impossible!</p>');
		} else if (time == '0:47') {
			setSubtitles('<p><strong>Shop keeper:</strong> You\'ve found Wonkers last golden ticket!</p>');
		} else if (time == '0:50') {
			setSubtitles('<p>Sorry, but subtitling hasn\'t been implemented beyond this point for this trailer!</p><p>It can be set to run for as long as you need it too.</p>');
		}
		
		setTimeout('MFSubtitle()', 100);
	}

//-->