var actual_news=0;
var w=(screen.availWidth-1024)/2;
var h=screen.availHeight;
var attributes = {};
var params = {};
params.allowfullscreen = "true";
var is_clear=true;
var flashvars = {};

function clean(id){
	  is_clear= false;
	  $("label.theme").animate({"opacity" : "0.0" }, {duration : 200 , queue:true, complete : function(){$(theme['#'+id]).animate({"opacity" : "1.0" }, 200 ); }} );
	  $("label.titre").animate({"opacity" : "0.0" },  {duration : 200 , queue:true, complete : function(){$(titre['#'+id]).animate({"opacity" : "1.0" }, 200 );}} );
}

var elem='';
var imag=new Array(4);
var theme=new Array(4);
var titre=new Array(4);
var decale=new Array(4);

var volumeValue=50;

function charge_video(video_article,photo_video,id_dest){
		
		if($(video_article).html()!=null){
		var so = new SWFObject("../phpsflvplayer.swf", id_dest, "512", "368", "9", "#161619");
		so.addParam('allowscriptaccess','always');
		so.addParam("wmode","transparent");
		so.addParam("allowfullscreen","true");
		so.addVariable("file","video/"+$(video_article).html());
		so.addVariable("image","/photo/"+$(photo_video).html());
		so.addVariable("lightcolor","0x557722");
		so.addVariable("displaywidth","512");
		so.addVariable("displayheight","368");
		so.addVariable('autostart','false');
		so.write(id_dest);
  }
}

function charge_video2(video_article,photo_video,id_dest){
	
	if($(video_article).html()!=null){
	var so = new SWFObject("../phpsflvplayer.swf", "video", "512", "368", "9", "#161619");
	so.addParam('allowscriptaccess','always');
	so.addParam("wmode","transparent");
	so.addParam("allowfullscreen","true");
	so.addVariable("file","video/"+video_article);
	so.addVariable("image","/photo/"+photo_video);
	so.addVariable("lightcolor","0x557722");
	so.addVariable("displaywidth","512");
	so.addVariable("displayheight","368");
	so.addVariable('autostart','false');
	so.write(id_dest);

}
}
function demoInstanceInfo(myPlayer, myInfo) {
	 var jPlayerInfo = "<p>This jPlayer instance is running in your browser using ";
	 if(myPlayer.jPlayerGetInfo("html5")) {
	 jPlayerInfo += "<strong>HTML5</strong> with ";
	 if(myPlayer.jPlayerGetInfo("canPlayOGG")) {
	 jPlayerInfo += "<strong>OGG</strong>";
	 } else {
	 jPlayerInfo += "<strong>MP3</strong>";
	 }
	 } else {
	 jPlayerInfo += "<strong>Flash</strong> with <strong>MP3</strong>";
	 }
	 jPlayerInfo += " files.<br />This instance has the constructor option ";
	 if(myPlayer.jPlayerGetInfo("oggSupport")) {
	 jPlayerInfo += "set to <code>$(\"#jpId\").jPlayer({oggSupport: true})</code>";
	 } else {
	 jPlayerInfo += "defaulting to <code>$(\"#jpId\").jPlayer({oggSupport: false})</code>";
	 }
	 jPlayerInfo += "</p>";
	 myInfo.html(jPlayerInfo);
	} 
	
	$(document).ready(function(){
	    
			var hauteur=3.2*$("#rubriques").height();
	    	if($("#chronique"))
	    		if(hauteur<$("#chronique").height())
	    			hauteur=$("#chronique").height();
	    	
	    	if($("#video_article"))
	    		hauteur+=544;
	    	hauteur+="px";
	    	$("#titres").css('height',hauteur);
	    	$("#rubriques").css('height',hauteur);
	    	$("#plus").css('height',hauteur);

    /* Charge la video */
	    charge_video("#video_article","#photo_video","video");
	    charge_video("#video_article_0","#photo_video_0","video_0");
	    charge_video("#video_article_1","#photo_video_1","video_1");
	    charge_video("#video_article_2","#photo_video_2","video_2");
	    charge_video("#video_article_3","#photo_video_3","video_3");
	    
		$("#video_0").hover(function() {
			$("#shadow").animate({"opacity" : "0.0" }, {duration : 200, complete: function(){$("#shadow").css('display','none');}});
			$("#titre_0").animate({"opacity" : "0.0" }, {duration : 200, complete: function(){$("#titre_0").css('display','none');}});
			});
		$("#video_1").hover(function() {
			$("#shadow").animate({"opacity" : "0.0" }, {duration : 200, complete: function(){$("#shadow").css('display','none');}});
			$("#titre_1").animate({"opacity" : "0.0" }, {duration : 200, complete: function(){$("#titre_1").css('display','none');}});
			});
		$("#video_2").hover(function() {
				$("#shadow").animate({"opacity" : "0.0" }, {duration : 200, complete: function(){$("#shadow").css('display','none');}});
				$("#titre_2").animate({"opacity" : "0.0" }, {duration : 200, complete: function(){$("#titre_2").css('display','none');}});
				});
		$("#video_3").hover(function() {
					$("#shadow").animate({"opacity" : "0.0" }, {duration : 200, complete: function(){$("#shadow").css('display','none');}});
					$("#titre_3").animate({"opacity" : "0.0" }, {duration : 200, complete: function(){$("#titre_3").css('display','none');}});
					});
		$('#song_title').html('RFI - Le debat africain(1/2)');
		$("#jquery_jplayer").jPlayer({
			ready: function () {
				$(this).setFile("./audio/le_debat_africain_1_20100131_0810.mp3","").pause();
				demoInstanceInfo($(this), $("#jplayer_info"));
			},
			cssPrefix: "different_prefix_example",
			volume: 50,
			oggsupport:true
		})
		.jPlayerId("play", "player_play")
		.jPlayerId("pause", "player_pause")
		.jPlayerId("stop", "player_stop")
		.jPlayerId("loadBar", "player_progress_load_bar")
		.jPlayerId("playBar", "player_progress_play_bar")
		.jPlayerId("volumeMin", "player_volume_min")
		.jPlayerId("volumeMax", "player_volume_max")
		.jPlayerId("volumeBar", "player_volume_bar")
		.jPlayerId("volumeBarValue", "player_volume_bar_value")
		.onProgressChange( function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
			var myPlayedTime = new Date(playedTime);
			var ptMin = (myPlayedTime.getUTCMinutes() < 10) ? "0" + myPlayedTime.getUTCMinutes() : myPlayedTime.getUTCMinutes();
			var ptSec = (myPlayedTime.getUTCSeconds() < 10) ? "0" + myPlayedTime.getUTCSeconds() : myPlayedTime.getUTCSeconds();
			$("#play_time").text(ptMin+":"+ptSec);

			var myTotalTime = new Date(totalTime);
			var ttMin = (myTotalTime.getUTCMinutes() < 10) ? "0" + myTotalTime.getUTCMinutes() : myTotalTime.getUTCMinutes();
			var ttSec = (myTotalTime.getUTCSeconds() < 10) ? "0" + myTotalTime.getUTCSeconds() : myTotalTime.getUTCSeconds();
			$("#total_time").text(ttMin+":"+ttSec);
		})
		.onSoundComplete( function() {
			$(this).play();
		});
		
		$("#player_volume_up").click(function() {
			volumeValue+=5;
			//$("#jquery_jplayer").jPlayer("volume", volumeValue);

			
		});

		$("#player_volume_down").click(function() {
			volumeValue-=5;
			//$("#jquery_jplayer").jPlayer("volume", volumeValue);
		});
		
		$(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});  
		
		for(var i=0;i<4;i++){
		     elem="#elem_"+i;
		     imag[elem]="#image_"+i;
		     theme[elem]="#theme_"+i;
		     titre[elem]="#titre_"+i;
		     decale[elem]="-"+512*i+"px";

		   $(elem).mouseover(function(){
			$("#shadow").css('display','block');
			$(titre[elem]).css('display','block');
			$("#shadow").animate({"opacity" : "0.5" }, {duration : 200});
			$("#contenu_une").animate({"left" : decale['#'+this.id] }, 200 );
		      if(is_clear)
		      	clean(this.id);
		    }); 
		   $(elem).mouseout(function(){is_clear=true;});
		 }
		
	});
