$(function(){
	$('DIV.playerVideo a.fplayer').each(function(){
		var re = new RegExp( /videoHD=([^;]+)(;|\b|$)/ );
		var match = re.exec( document.cookie );
		urlVideo = $(this).attr('href');
		if( match && match[ 1 ] == 'true' ){
			urlVideo = urlVideo.replace('sd/','');
			$(this).attr('href',urlVideo);
			$('#SD').removeClass('select');
			$('#HD').addClass('select');
		}

		idPlayer = this.id;
		if (!flashembed.isSupported([9, 0])) {
			formatVideo = ($('#HD').hasClass('select')) ? 'High' : 'Standard' ;
			$(this).attr('href',urlVideo);
			$(this).html('<p>Flash version 9.0 or greater is required<p><p>Click here to watch '+formatVideo+' definition video</p>');	
		} else {
			flowplayer(idPlayer, racine+"/flowplayer/flowplayer-3.2.5.swf", {
				clip: {
					autoPlay: true,
					scaling : 'fit'
				}/*,
				plugins: {
					controls: null
				},
				onFinish : function(){
					this.play();
				}*/
			});
		}
	});
});

function toggleHD(kelBt,idPlayer,urlClip){
	$(kelBt).parent().children('a').removeClass('select');
	$(kelBt).addClass('select');

	idBt = $(kelBt).attr('id');
	playhd = (idBt == 'HD') ? 'true' : 'false' ;
	var expiration = new Date();
	expiration.setDate( expiration.getDate() + 14 );
	document.cookie = [ 'videoHD='+playhd+'; expires=', expiration.toUTCString() ,'; path=/' ].join( '' );

	if (!flashembed.isSupported([9, 0])) {
		formatVideo = ($('#HD').hasClass('select')) ? 'High' : 'Standard' ;
		$("#player"+idPlayer).attr('href',urlClip);
		$("#player"+idPlayer).html('<p>Flash version 9.0 or greater is required<p><p>Click here to watch '+formatVideo+' definition video</p>');
	}else{
		$f("player"+idPlayer).play(urlClip);
	}

}

