var Morceau = -1;
var Stopped = false;
var Paused = false;
var FlashInstalled = false;
var AlbumIsReady = false;
var opa=100;
var opi=100;
var AutoCache = false;
var BodyLoaded = 0;
var avis = 0;
var atop = 0;
var timed = 0;
var preim=new Array;
var albuminner = "";
function keyPressHandler(e) {
  var kC  = (window.event) ? event.keyCode : e.keyCode;
  var Esc = (window.event) ? 27 : e.DOM_VK_ESCAPE;
  var r = (kC!=Esc); 
  if (window.event)window.event.returnValue=r; else e.returnValue=r;
}
function set_opacity(id, opacity){
	el = document.getElementById(id);
	el.style["filter"] = "alpha(opacity="+opacity+")";
	el.style["-moz-opacity"] = opacity/100;
	el.style["-khtml-opacity"] = opacity/100;
	el.style["opacity"] = opacity/100;
	return true;
}
function mopi(){
	if (opi==opa) return;
	if (opi<opa)opa-=5; else opa+=5;
	set_opacity("lecteur_actions",opa);
	setTimeout('mopi()', 50);
}
function opacityto(N){
	opi=N;
	mopi();
}
function FlashIsReady() {
	FlashInstalled = true;
}
function AlbumIsLoaded() {
	document.getElementById("Flash").style.width = "400px";
	document.getElementById("Flash").style.height = "300px";
	//InitFlash();
	document.getElementById("lecteur_infos").style.backgroundPosition = "0px -300px";
	document.getElementById("FlashID").setVolume(volume);
	AlbumIsReady = true;
	HideWait();	
	showAction(-1);
	OB=document.getElementById("Scrollbox");
	OB.innerHTML=albuminner;
	//if (!(document.getElementById("FlashID").TestOK()))window.location.reload();
	if ((autoMP3)&&(autoMP3!=0)){
		document.getElementById("MO"+autoMP3).scrollIntoView(false); 
		setMP3(autoMP3);
	};
}
function AddItemAlbum(I,N,T,D,W,G) {
	albuminner+="<div class='morceau"+W+"' onclick='setMP3("+I+")'title='"+G+"'>";
	albuminner+="<div class='morceau_num"+D+"'>"+N+"</div>";
	albuminner+="<div class='morceau_titre' id='MO"+I+"'>"+T+"</div>";
	albuminner+="</div>";
	//
	preim[I]=new Image();
	preim[I].src="titre.php?Titre="+escape(T);
}
function PlayPosition(P) {
	P=(P*3)-300;
	document.getElementById("lecteur_zone").style.backgroundPosition= P+'px 0px';
}
function CacherControl(){
	if (AutoCache)showAction(1);
}
var Interval = 0;
var Windex = 0;

function ShowWait(N) {
	//document.getElementById("lecteur_progress").style.visibility="visible";
	if (Windex==0) RollWait();
	document.getElementById("lecteur_seek").style.width = (N * 3) + "px";
}
function RollWait() {
	if (Windex==0) Interval=setInterval("RollWait()",100);
	Windex++;
	if (Windex==9)Windex=1;
	document.getElementById("lecteur_progress").style.backgroundPosition=-(Windex<<4) + "px 0px";
}
function HideWait() {
	Windex=1;
	clearInterval(Interval);
	Windex=0;
	document.getElementById("lecteur_progress").style.backgroundPosition="0px 0px";
}
function ButtonsState(N) {
	N = -(N * 24);
	document.getElementById("lecteur_control").style.backgroundPosition = "0px "+N+"px";
}
function bpush(N) {
	document.getElementById("FlashID").Command(N); 
	return false;
}
function ShowError(S) {
	document.getElementById("lecteur_centre").style.visibility="hidden";
	document.getElementById("erreur_noscript").style.visibility="visible";	
	document.getElementById("lecteur_erreur_texte").innerHTML=S;
}
function InitFlash(){
	if (AlbumIsReady) {
		HideWait();
	} else {
		setTimeout("InitFlash()",500);
	}
}

function verif_flash(){
	document.onkeydown=keyPressHandler;
	document.onkeypress=keyPressHandler;	
	//if (!AlbumIsReady)RollWait();
	setTimeout("verif_now()",1000);
}
function verif_now(){
	if (DetectFlashVer(9,0,0)){
		document.getElementById("Flash").style.visibility="visible";
        document.getElementById("lecteur_centre").style.visibility="visible";
		///InitFlash();
	} else {
		document.getElementById("lecteur_erreur_texte").innerHTML='<div>Pour \351couter les morceaux,<br> il vous faut d\'abord installer une<br>version r\351cente de:<br><a href="http://www.adobe.com/go/FR-H-GET-FLASH" target="_blank"><img src="images/adobe.png" alt="Flash Player" width="158" height="39" vspace="8" border="0" align="absmiddle" /></a></div>';
		document.getElementById("erreur_noscript").style.visibility="visible";
		document.getElementById("lecteur_centre").style.visibility="hidden";
		//document.getElementById("lecteur_progress").style.visibility="hidden";
		HideWait();
	}	
}
function setTitre(S){
	//document.getElementById("lecteur_titres").style.backgroundImage=(S!="")?"url(titre.php?Titre="+escape(S)+"&dum="+Math.random()+")":"";
	document.getElementById("lecteur_titres").style.backgroundImage=(S!="")?"url(titre.php?Titre="+escape(S)+")":"";
}
function setMP3(N) {
	if(!AlbumIsReady)return;
	if (Morceau!=N){
		if (Morceau!=-1){
			OB=document.getElementById("MO"+Morceau);
			OB.style.color = "#99a097";
			OB.style.fontWeight="";
			OB.style.fontStyle="";
			OB.style.cursor="pointer";
			OB.style.backgroundImage="";
		}
		setTitre("");
		OB=document.getElementById("MO"+N);
		OB.style.color = "#000000";
		OB.style.fontWeight="bold";
		OB.style.fontStyle="italic";		
		OB.style.cursor="default";
		OB.style.backgroundImage="url(images/hp.png)";
		Morceau=N;	
		document.getElementById("lecteur_zone").style.backgroundPosition = "-300px 0px";
		document.getElementById("lecteur_control").style.backgroundPosition = "0px 0px";
		RollWait();
		document.getElementById("lecteur_seek").style.width = "0px";
		showAction(-10);
		AutoCache = true;
		repond=document.getElementById("FlashID").LoadMP3(Morceau);
		if (repond!="1")setTimeout("ReloadOnFlashError()",250);
	}
	document.getElementById("lecteur_actions").style.visibility="visible";
	document.getElementById("lecteur_titres").style.visibility="visible";
	document.getElementById("infodnl").style.visibility = "visible";
	document.getElementById("lecteur_infos").style.visibility="hidden";
}
function hidescroll() {
	if (AlbumIsReady) document.getElementById("cache_scroll").style.visibility="visible";
}
function showscroll() {
	if (AlbumIsReady) document.getElementById("cache_scroll").style.visibility="hidden";	
}
function ShowDownload() {
	return;
	if (isIE)document.getElementById("_dnlwindow").src="dnlfirst.html";
	document.getElementById("_dnlwindow").style.visibility="visible";
}
function Action() {
	var OB = document.getElementById("lecteur_actions").style;
	var TOB = document.getElementById("lecteur_titres").style;
	clearTimeout(timed);
	atop+=avis;
	if (atop < -45) atop = -45; else if (atop > 0) atop = 0;
	if ((atop!=45)&&(atop!=0)) timed = setTimeout("Action()",50);
	OB.top = atop + "px";
	TOB.top = (-45-atop) + "px";
	if (!isIE) {
		opacity = 10 - (atop << 1);
		OB["filter"] = "alpha(opacity="+opacity+")";
		TOB["filter"] = "alpha(opacity="+opacity+")";
		opacity = opacity /100;
		OB["-moz-opacity"] = opacity;
		OB["-khtml-opacity"] = opacity;
		OB["opacity"] = opacity;
		TOB["-moz-opacity"] = opacity;
		TOB["-khtml-opacity"] = opacity;
		TOB["opacity"] = opacity;		
	}
}
function showAction(n) {
	AutoCache = false;
	avis=n;
	Action();
}
function posX(OB) {
	X = OB.offsetLeft;
    while ((OB=OB.offsetParent)) X+=OB.offsetLeft; 
    return X;
}
function beginseek(e) {
	changeseek(e);
	return false;
}
function changeseek(e) {
	if(document.all)X = event.clientX; else X = e.pageX;
	X -= posX(document.getElementById("lecteur_zone"));	
	XX = X;
	X-=300;
	document.getElementById("lecteur_seek").style.backgroundPosition = X + "px 0px";
	OB=document.getElementById("togo");
	OB.style.left = (XX + 38) + 'px';
	XX=Math.floor(XX/3);
	OB.innerHTML = document.getElementById("FlashID").TimeFor(XX);
	OB.style.visibility = "visible";
	return false;
}
function setseek(e) {
	if(document.all)X = event.clientX; else X = e.pageX;
	X = Math.floor((X - posX(document.getElementById("lecteur_zone")))/3);	
	document.getElementById("FlashID").seekSon(X);
}
function exitseek() {
	document.getElementById("lecteur_seek").style.backgroundPosition = "-300px 0px";
	document.getElementById("togo").style.visibility="hidden";
}
function beginvol(e) {
	changevol(e);
	return false;
}
function changevol(e) {
	X = -300;
	if(document.all)X += event.clientX; else X += e.pageX;
	X -= posX(document.getElementById("lecteur_vol"));	
	document.getElementById("lecteur_volseek").style.backgroundPosition = X + "px 0px";
	return false;
}
function setvol(e) {
	if(document.all)X = event.clientX; else X = e.pageX;
	X = X - posX(document.getElementById("lecteur_vol"));	
	document.getElementById("FlashID").setVolume(X<<1);
}
function exitvol() {
	document.getElementById("lecteur_volseek").style.backgroundPosition = "-300px 0px";	
}
function setVolume(N) {
	setCookie("VOL",N,30);
	N = -300 + (N >>> 1);
	document.getElementById("lecteur_vol").style.backgroundPosition = N + "px 0px";	
}
function setCookie(c_name, value, expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function gethauteur(){
        if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight;
        else if (window.innerHeight) return window.innerHeight;
        else if (document.body && document.body.clientHeight) return document.body.clientHeight;
}
function getlargeur(){
        if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth;
        else if (window.innerWidth) return window.innerWidth;
        else if (document.body && document.body.clientWidth) return document.body.clientWidth;
}  
function reconstruction(){
	document.getElementById("wrapper").style.minHeight=gethauteur()+"px";	
}
function ReloadOnFlashError(){
	alert("Erreur lors du chargement.\nLa page va se recharger.");
	window.location.reload();
}
document.write("<style>#wrapper {min-height:"+gethauteur()+"px;}</style>");
window.onresize=reconstruction;
