var lastID;
var currentID;
var currentFlashID;
var player;
var id;

function openVideo(videoFile, divId, flashId){
	$f(divId,{
		src:'/js/flowplayer/flowplayer.commercial-3.2.5.swf',
		wmode:'transparent'
	},{
		key:'#@2ab3272e9bbd9af162c',
		clip:{
		  url:'/medias/videos/'+videoFile,
		  autoPlay: true,
		  scaling: 'orig'
		},
		play:{
			replayLabel:'Rejouer'
		},
		onLoad: function () {
			this.setVolume(100);
		},
		screen:{
			bottom: 15
		},
		canvas: {
			backgroundColor: 'transparent',
			backgroundGradient: 'none'
		},
		plugins: { 
			controls: { 
				url: '/js/flowplayer/flowplayer.controls-3.2.3.swf', 
		 
				// display properties 
				backgroundColor: 'rgba(0,0,0,0.5)', 
				backgroundGradient: 'none',
				borderRadius: 10,
				
				// controlbar-specific configuration 
				fontColor: '#ffffff',
				timeFontColor: '#E1C090',
				progressColor: '#7B0100',
				sliderBorder :'none',
				volumeSliderColor: '#000000',
				volumeColor: '#7B0100',
				volumeBorder: 'none',
				buttonColor: '#A7813A',
				buttonOverColor: '#D48E2E',
				bufferColor: '#D48E2E',
				timeColor: '#D18315', 
				autoHide: 'never', 
				// which buttons are visible and which are not? 
				play:true, 
				volume:true, 
				mute:true, 
				time:false, 
				stop:false, 
				playlist:false, 
				fullscreen:true, 
				// scrubber is a well-known nickname for the timeline/playhead combination 
				scrubber: true 
				// you can also use the "all" flag to disable/enable all controls 
			} 
		}
	});
}

function loadVideo (videoFile){
	$f().play("medias/videos/"+videoFile);
}

function windowSlide(id){
	if($('extraits-'+id).style.display == 'none'){
		Effect.BlindDown('extraits-'+id, { duration: .3, afterFinish: function(){
		  //alert('showVideo');
	  	  openVideo('psf'+currentID+'_1.flv','player-'+currentID,'psf'+currentID);
	  	}
		});
	} else {
		Effect.BlindUp('extraits-'+id, { duration: .3, beforeStart: function(){
		  $('player-'+id+'_api').replace();
		  //alert("slideUp");
		}
		});
	}
}

function openExtrait(id){
	currentID = id;
	if (!lastID || id == lastID){
	  windowSlide(id);
	} else if (id != lastID){
	  windowSlide(id);
	  if($('extraits-'+lastID).style.display != "none"){
	    windowSlide(lastID);
	  }
	} if (id == lastID && $('extraits-'+id).style.display != "none"){
	  //$('psf'+id).replace();
	  id = 0;
	}
	//alert(id);
	lastID = id;
}
function showPlayer(){
	alert('show player');
	openVideo('psf'+currentID+'_1.flv','player-'+currentID,'psf'+currentID);
}
