/*

FAMILYCAM Flash Video Player 

File:			FamilyCamPlayer.js
Copyright: 		(c)2008 familycam.com
Author: 		Stephen Beattie <snbeattie@gmail.com>, www.stephenbeattie.com

Dependencies:	
	SWFObject v2.0 for plugin detection and 'ExpressInstall' player upgrade option

Javascript Usage:

1. 	Include "swfobject.js" and "FamilyCamPlayer.js" (this file) in the HEAD of your HTML.  SWFObject must be included first.

2.	Create a container DIV element in your HTML containing fallback content if Javascript/Flash is unavailable in the user's browser

		<div id="myDIV">This content will be replaced by javascript....</div>

3.	Add the following Javascript code after your nominated container DIV (example using full array of available startup parameters):
	N.B. The path to the player SWF must also be supplied as a constructor argument. 
	
		<script language="javascript">	
			var player = new FamilyCamPlayer( '../path/to/player.swf', 'myDIV', 512, 330, {	// Mandatory constructor arguments
				file: 'rtmp://localhost/vod/mp4:transformers-tlr4_720p.mp4',	// Mandatory - NO DEFAULT
				starttime: '00:01:03',								// Optional - default 0 (seconds)
				autoplay: false,									// Optional - default true (boolean)
				volume: 50,										// Optional - default 75 (%)
				buffersize: 20 									// Optional - default 15 (seconds)
				hardwarescaling: false								// Optional - default true (boolean)
				videosmoothing: true								// Optional - default true (boolean)
				showlogo: false									// Optional - default true (boolean)
			});
		</script>
	
4.	After page load, you can then use the following Javascript calls from buttons, links etc. to manipulate the flash player:

		player.play();
		player.setVolume(85);
		player.seek('00:25.32'); // or seek(25);
		player.pause();
		alert( player.getCurrentTime() );

N.B.	See source below for full list and usage of external player API

*/

function FamilyCamPlayer( swf, div, width, height, flashvars )
{
	params = { allowfullscreen:'true', allownetworking:'all', allowscriptaccess:'always' };
	attributes = { id: div+'_player', name: div+'_player' };

	var path = ( swf.indexOf('/') != -1 ) ? swf.substr( 0, swf.lastIndexOf('/') ) + '/' : '';
	
	swfobject.embedSWF( swf, div, width, height, 
		'9.0.115,0', path + 'expressInstall.swf', flashvars, params, attributes );
		
	this.playerId = div + '_player';
	
	swfobject.addDomLoadEvent( this.removeInstance );
}

FamilyCamPlayer.prototype = {
	instance:		function(){ return document.getElementById( this.playerId ); },
	play: 			function(){ this.instance().playVideo(); },
	stop: 			function(){ this.instance().stopVideo(); },
	pause: 			function(){ this.instance().pauseVideo(); },
	seek: 			function( time ){ this.instance().seekVideo( time ); },
	getCurrentTime:	function(){ return this.instance().getCurrentTime(); },
	setVolume: 		function( percent ){ this.instance().setVolume( percent ); },
	getVolume: 		function(){ this.instance().getVolume(); },
	mute: 			function(){ this.instance().disableAudio(); },
	unmute: 		function(){ this.instance().enableAudio(); },
	
	removeInstance:	function(){ swfobject.removeSWF( this.playerId ); }
}

