var readyPlayer=false;

function modif_vol(val){
	val=-val;
	var ratio=2/5;
	var vol=$("#volume_slider").height()*(1/ratio);
	vol+=val;
	if(vol>100){vol=100;}
	if(vol<0){vol=0;}
	var current_volume=100-vol;
	vol=vol*ratio;
	$("#volume_slider").css("height",vol);
	$("#jpId").jPlayer("volume", current_volume);
}

function increase_vol(){modif_vol(5);}
function decrease_vol(){modif_vol(-5);}
function close_Jplayer(){try{$("#jpId").jPlayer("stop");}catch(e){}}
function changeTitleSong(title){$("#current_song > span").html(title);}
function start_tracklist(){setTimeout("start2_tracklist()",100);}

function changeMp3(mp3){
	if(readyPlayer==false){
		setTimeout("changeMp3(\""+mp3+"\")", 200);
	}else{
		$("#jpId").jPlayer("clearFile");
		$("#jpId").jPlayer("setFile", mp3).jPlayer("play");
	}
}



function start2_tracklist(){
	$("#tracklist").jScrollPane({showArrows:true,scrollbarWidth:10,arrowSize:12});
	$.jPlayer.timeFormat.showHour = true;
	$("#jpId").jPlayer({
		ready:function(){
			readyPlayer=true
		},
		volume: 75,
		swfPath: "content/flash",
		customCssIds: true
	})
	.jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime){
		$("#timeCurrent").html($.jPlayer.convertTime(playedTime));
		$("#timeTotal").html($.jPlayer.convertTime(totalTime));
		$(".current_track").each(function(i){
			this.className="not_track";
			$(this).children().removeClass("a_track");
		});

		//Tracklistings search
		playedTime/=1000;
		var trouve=false;
		var newName = "";
		$(".not_track").each(function(i){
			if($(this).children().children(".invisible").html()<=playedTime && $(this).next().children().children(".invisible").html()>playedTime && trouve==false){
				$(this).removeClass("not_track");
				$(this).addClass("current_track");
				$(this).children().addClass("a_track");
				newName=$(this).children().children(".invisibleName").html();
				trouve=true;
			}
		});
		if(trouve==false){
			$(".not_track:last").each(function(i){
				$(this).removeClass("not_track");
				$(this).addClass("current_track");
				$(this).children().addClass("a_track");
				newName=$(this).children().children(".invisibleName").html();
			});
		}
		changeTitleSong(newName);
	})
	.jPlayer("onSoundComplete", function(){this.element.jPlayer("play");})
	.jPlayer("cssId", "play", "play_btn")
	.jPlayer("cssId", "pause", "pause_btn")
	.jPlayer("cssId", "stop", "stop_btn")
	.jPlayer("cssId", "loadBar", "loadbar")
	.jPlayer("cssId", "playBar", "progressbar");
}

function playAt(nw, time, title){
	$('#jpId').jPlayer("playHeadTime",(time+0.5)*1000);
	$(".current_track").each(function(i){
		this.className="not_track";
		$(this).children().removeClass("a_track");
	});
	for(var i=0; i<nw.childNodes.length; i++){
		nw.childNodes[i].className="a_track";
	}
	nw.className="current_track";
	changeTitleSong(title);
}
