
var player = function( _config ) {
	this.config = _config;
	this.videos = {};

	this.config.autoStart = ( typeof( this.config.autoStart ) != 'undefined' ? this.config.autoStart : true );
	this.config.width = ( this.config.width ? this.config.width : 650 );
	this.config.height = ( this.config.height ? this.config.height : 455 );
	console.log( this.config.url + this.config.video + '.m4v' );
	this.videos = {
			m4v: this.config.url + this.config.video + '.m4v',
			flv: this.config.url + this.config.video + '.flv',
			poster: this.config.url + this.config.video + '.jpg'
		};
	this.load();
}


player.prototype.ControlVersion = function() {
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry
	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {}

	if( !version ) {
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");

			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 

			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");
		} catch (e) {}
	}

	if( !version ) {
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {}
	}

	if( !version ) {
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {}
	}

	if( !version ) {
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}

	return version.substr( 4, version.length ).replace( ',', '.' );
};

/**
 * JavaScript helper required to detect Flash Player PlugIn version information
**/
player.prototype.GetSwfVer = function() {
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;

	if( navigator.plugins != null && navigator.plugins.length > 0 ) {
		if( navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"] ) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if( versionRevision == "" ) {
				versionRevision = descArray[4];
			}
			if( versionRevision[0] == "d" ) {
				versionRevision = versionRevision.substring(1);
			} else if( versionRevision[0] == "r" ) {
				versionRevision = versionRevision.substring(1);
				if( versionRevision.indexOf("d") > 0 ) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
			//alert("flashVer="+flashVer);
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( navigator.userAgent.indexOf("MSIE") != -1 && navigator.userAgent.toLowerCase().indexOf("win") != -1 && navigator.userAgent.indexOf("Opera") == -1 ) {
		flashVer = this.ControlVersion();
	}	
	return flashVer;
};

player.prototype.load = function() {
	var html = '<div id="jp_container_1" class="jp-video ">';
	html += '	<div class="jp-type-single">';
	html += '		<div id="jquery_jplayer_1" class="jp-jplayer"></div>';
	html += '		<div class="jp-gui">';
	html += '			<div class="jp-video-play">';
	html += '				<a href="javascript:;" class="jp-video-play-icon" tabindex="1">play</a>';
	html += '			</div>';
	html += '			<div class="jp-interface">';
	html += '				<div class="jp-progress">';
	html += '					<div class="jp-seek-bar">';
	html += '						<div class="jp-play-bar"></div>';
	html += '					</div>';
	html += '				</div><div class="time">';
	html += '				<div class="jp-current-time"></div> /';
	html += '				<div class="jp-duration"></div></div>';
	html += '				<div class="jp-controls-holder">';
	html += '					<ul class="jp-controls">';
	html += '						<li><a href="javascript:;" class="jp-play" tabindex="1">play</a></li>';
	html += '						<li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li>';
	html += '						<li><a href="javascript:;" class="jp-mute" tabindex="1" title="mute">mute</a></li>';
	html += '						<li><a href="javascript:;" class="jp-unmute" tabindex="1" title="unmute">unmute</a></li>';
	html += '						<li><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume">max volume</a></li>';
	html += '					</ul>';
	html += '					<div class="jp-volume-bar">';
	html += '						<div class="jp-volume-bar-value"></div>';
	html += '					</div>';
	html += '				</div>';
	html += '			</div>';
	html += '		</div>';
	html += '		<div class="jp-no-solution">';
	html += '			<span>Update Required</span>';
	html += '				To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>.';
	html += '		</div>';
	html += '	</div>';
	html += '</div>';

	var self = this;
	var suppliedTmp = '';
	var versionFlash = parseFloat( this.GetSwfVer() );
	if( versionFlash >= 11 ) {
		suppliedTmp = 'flv';
	} else if( ICZ.html.checkIt( 'chrome' ) || ICZ.html.checkIt( 'safari' ) ||
					ICZ.html.checkIt( 'iphone' ) || ICZ.html.checkIt( 'ipad' ) || ICZ.html.checkIt( 'ipod' ) ) {
		suppliedTmp = 'm4v';
	}

	jQuery( '#' + this.config.id ).append( html );
	$( '#jquery_jplayer_1' ).jPlayer({
			ready: function () {
					jQuery( this ).jPlayer( 'setMedia', self.videos );
					
					if( self.config.autoStart ) {
						jQuery( this ).jPlayer( 'play', 0 );
					}
				},

			swfPath: '/temoignages/jPlayer-2.1.0/',
			supplied: suppliedTmp,
			size: {
					width: this.config.width + 'px',
					height: this.config.height + 'px',
					cssClass: 'jp-video-custom'
				}
		});
};

