var margin, timeout,lapage;
var scrolling=new Array;
scrolling["cont_actu_home"] = 0;
lataille = 350;
lescroll = 346;
marge_barre = 0;

function proportion (lay,scrol) {
taille_cont = document.getElementById(lay).offsetHeight;
marge_barre = scrol * (lescroll/taille_cont);
return marge_barre;
}

function af () {
alert (marge_barre);
}



function scrollTop(longScroll,layer_liste) {
	if(scrolling[layer_liste] > 3) {
	scrolling[layer_liste] = scrolling[layer_liste]-3;
		document.getElementById(layer_liste).style.marginTop = "-"+(scrolling[layer_liste])+"px";
		document.getElementById(layer_liste+"_barre").style.marginTop = "+"+(proportion(layer_liste,scrolling[layer_liste]))+"px";
	}
	else {
		return;
	}
	
	if(longScroll == true) {
		timeout = eval ('setTimeout("scrollTop(true,\''+layer_liste+'\')", 1);');		
	}
	
}

function scrollTop_acc(longScroll,layer_liste) {
	if(scrolling[layer_liste] > 6) {
	scrolling[layer_liste] = scrolling[layer_liste]-6;
	document.getElementById(layer_liste).style.marginTop = "-"+(scrolling[layer_liste]--)+"px";
	document.getElementById(layer_liste+"_barre").style.marginTop = "+"+((proportion(layer_liste,scrolling[layer_liste])))+"px";	
	}
	else {
	return;
	}	
	if(longScroll == true) {
	timeout = eval ('setTimeout("scrollTop_acc(true,\''+layer_liste+'\')", 1);');
	}	
}


// function scrollBottom, pour scroller vers le haut
function scrollBottom(longScroll,layer_liste) {

	if( document.getElementById(layer_liste).offsetHeight > scrolling[layer_liste]+lataille) {
	scrolling[layer_liste] = scrolling[layer_liste]+3;
		document.getElementById(layer_liste).style.marginTop = "-"+(scrolling[layer_liste])+"px";
		document.getElementById(layer_liste+"_barre").style.marginTop = "+"+(proportion(layer_liste,scrolling[layer_liste]))+"px";
	}
	else {
		return;
	}
	
	if(longScroll == true) {
		timeout = eval ('setTimeout("scrollBottom(true,\''+layer_liste+'\')", 1);');
		}
}

// function scrollBottom, pour scroller vers le haut
function scrollBottom_acc(longScroll,layer_liste) {
	if(scrolling[layer_liste]+lataille < document.getElementById(layer_liste).offsetHeight && document.getElementById(layer_liste).offsetHeight > lataille) {
	scrolling[layer_liste] = scrolling[layer_liste]+6;
		document.getElementById(layer_liste).style.marginTop = "-"+(scrolling[layer_liste]++)+"px";
		document.getElementById(layer_liste+"_barre").style.marginTop = "+"+(proportion(layer_liste,scrolling[layer_liste]))+"px";
	}
	else {
		return;
	}
	
	if(longScroll == true) {
		timeout = eval ('setTimeout("scrollBottom_acc(true,\''+layer_liste+'\')", 1);');
	}
}


function scroll_menu() {
	// DEBUT POUR LA GAMME //	
if (document.getElementById("cont_actu_home")) {
	if (document.getElementById("cont_actu_home").offsetHeight > lataille) {	
	document.getElementById("bt_up").onmouseover = function() {scrollTop(true,'cont_actu_home');};
	document.getElementById("bt_up").onmouseout = function() {scrollTop(false,'cont_actu_home');scrollTop_acc(false,'cont_actu_home');clearTimeout(timeout);};
	document.getElementById("bt_down").onmouseover = function() {scrollBottom(true,'cont_actu_home');};
	document.getElementById("bt_down").onmouseout = function() {scrollBottom(false,'cont_actu_home'); scrollBottom_acc(false,'cont_actu_home');clearTimeout(timeout);};
	
	document.getElementById("bt_up").onmousedown = function() {scrollTop_acc(true,'cont_actu_home');};
	document.getElementById("bt_down").onmousedown = function() {scrollBottom_acc(true,'cont_actu_home');};
	document.getElementById("bt_up").onmouseup = function() {scrollTop_acc(false,'cont_actu_home');clearTimeout(timeout);};
	document.getElementById("bt_down").onmouseup = function() {scrollBottom_acc(false,'cont_actu_home');clearTimeout(timeout);};
	
	// affectation et récupération de la valeur de marge du contenu, ça va nous servir à faire le scrolling
	document.getElementById("cont_actu_home").style.marginTop = "0px";
	document.getElementById("cont_actu_home_barre").style.marginTop = "0px";
	margin = document.getElementById("cont_actu_home").style.marginTop;		
	
	document.getElementById("bt_up_img").src ="img_com/fleche_haut_noir.gif";
	document.getElementById("bt_up").style.cursor ="pointer";
	document.getElementById("bt_down_img").src ="img_com/fleche_bas_noir.gif";
	document.getElementById("bt_down").style.cursor ="pointer";
	document.getElementById("barre_scroll_img").src ="img_com/barre_scroll.gif";
	
	}else {
	document.getElementById("bt_up_img").src ="img_com/vide.gif";
	document.getElementById("bt_up").style.cursor ="default";
	document.getElementById("bt_down_img").src ="img_com/vide.gif";
	document.getElementById("bt_down").style.cursor ="default";
	document.getElementById("barre_scroll_img").src ="img_com/vide.gif";
	}	
}

}


function lance_nav_actu(lg) {
if (document.getElementById("actu_fleche_gauche") && document.getElementById('actu_fleche_droite')) {
		if (num_encours_actu==0) {
		document.getElementById("actu_fleche_gauche").src = "img_com/vide.gif";
		document.getElementById("actu_fleche_gauche").style.cursor ="default";
		document.getElementById("actu_fleche_gauche").onclick=function () {			
			}
			document.getElementById("actu_fleche_gauche").onmouseover=function () {			
			}
			document.getElementById("actu_fleche_gauche").onmouseout=function () {			
			}
		}else {
		document.getElementById("actu_fleche_gauche").style.cursor ="pointer";
		document.getElementById("actu_fleche_gauche").src = "img_com/fl_gauche_noir_off.gif";
			document.getElementById("actu_fleche_gauche").onclick=function () {
			nav_article('precedent',lg,false);
			}
			document.getElementById("actu_fleche_gauche").onmouseover=function () {
			document.getElementById("actu_fleche_gauche").src = "img_com/fl_gauche_noir_on.gif";
			}
			document.getElementById("actu_fleche_gauche").onmouseout=function () {
			document.getElementById("actu_fleche_gauche").src = "img_com/fl_gauche_noir_off.gif";
			}
			
		}
		if (num_encours_actu == tab_id_actu.length-1) {
		document.getElementById('actu_fleche_droite').src='img_com/vide.gif';
		document.getElementById("actu_fleche_droite").style.cursor ="default";
		document.getElementById("actu_fleche_droite").onclick=function () {			
			}
			document.getElementById("actu_fleche_droite").onmouseover=function () {			
			}
			document.getElementById("actu_fleche_droite").onmouseout=function () {			
			}
		}else {
		document.getElementById("actu_fleche_droite").style.cursor ="pointer";
		document.getElementById("actu_fleche_droite").src = "img_com/fl_droite_noir_off.gif";
			document.getElementById("actu_fleche_droite").onclick=function () {
			nav_article('suivant',lg,false);	
			}
			document.getElementById("actu_fleche_droite").onmouseover=function () {
			document.getElementById("actu_fleche_droite").src = "img_com/fl_droite_noir_on.gif";
			}
			document.getElementById("actu_fleche_droite").onmouseout=function () {
			document.getElementById("actu_fleche_droite").src = "img_com/fl_droite_noir_off.gif";
			}
		}
	}
}

var fadddddd;
function nav_article (sens,lg,etat){
if (etat==false) {
clearInterval (te);
clearTimeout (fadddddd);
}
if (sens=="precedent") {
if (num_encours_actu > 0) {
num_encours_actu = num_encours_actu -1;
display_actu(tab_id_actu[num_encours_actu],lg);
lance_nav_actu(lg);
}
}
if (sens=="suivant") {
if (num_encours_actu < tab_id_actu.length-1) {
num_encours_actu = num_encours_actu +1;
display_actu(tab_id_actu[num_encours_actu],lg);
lance_nav_actu(lg);
}
}
}


function display_actu(leid,lg) {
var xmlHttp=GetXmlHttpObject();
if (xmlHttp==null){
alert ("Browser does not support HTTP Request");
return;
} 
document.getElementById("cont_actu_home").innerHTML="<div align='center'><br><br><br><img src='img_com/loading.gif' alt='' width='20' height='20' border='0'><br><br><br></div>"; 
var url="_inc/fonc_display_actu.php";
xmlHttp.onreadystatechange=function() { 
        if (xmlHttp.readyState==4){
            if (xmlHttp.status==200){
              changed_html_home_actu('cont_actu_home',xmlHttp,leid);
			  }
		}
    }
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded'); 
xmlHttp.send("id_actu="+leid+"&lg="+lg+"&sid="+Math.random());
}

function changed_html_home_actu(lay,dett,leid) {
document.getElementById(lay).innerHTML=dett.responseText; 
if (document.getElementById("cont_actu_home")) {
image = document.getElementById("cont_actu_home");
setOpacity(image, 0);
fadeIn(lay,0);
}
}

// DEFILENENT AUTOMATIQUE ACTU HOME PAGE // 
function anim_image(lg){
te = setInterval ("lance('"+lg+"')",4000)
}

function lance (lg) {
	if (num_encours_actu!='') {
		if (num_encours_actu==0) {
		num_encours_actu = tab_id_actu.length;
		}
		nav_article ("precedent",lg,true);
		num_encours_actu = num_encours_actu-1;
	}
}



// VIDEO
function lance_nav_vid(lg) {
if (document.getElementById("vid_fleche_gauche") && document.getElementById("vid_fleche_droite")) {
if (num_encours_vid==0) {
document.getElementById("vid_fleche_gauche").src = "img_com/vide.gif";
document.getElementById("vid_fleche_gauche").style.cursor ="default";
}else {
document.getElementById("vid_fleche_gauche").style.cursor ="pointer";
document.getElementById("vid_fleche_gauche").src = "img_com/fleche_gauche_blanc.gif";
	document.getElementById("vid_fleche_gauche").onclick=function () {
	nav_article_vid('precedent',lg);
	}
}
if (num_encours_vid == tab_id_vid.length-1) {
document.getElementById('vid_fleche_droite').src='img_com/vide.gif';
document.getElementById("vid_fleche_droite").style.cursor ="default";
}else {
document.getElementById("vid_fleche_droite").style.cursor ="pointer";
document.getElementById("vid_fleche_droite").src = "img_com/fleche_droite_blanc.gif";
	document.getElementById("vid_fleche_droite").onclick=function () {
	nav_article_vid('suivant',lg);	
	}
}
}
}


function nav_article_vid (sens,lg){
if (sens=="precedent") {
if (num_encours_vid > 0) {
num_encours_vid = num_encours_vid -1;
display_vid(tab_id_vid[num_encours_vid],lg);
lance_nav_vid(lg);
}
}
if (sens=="suivant") {
if (num_encours_vid < tab_id_vid.length-1) {
num_encours_vid = num_encours_vid +1;
display_vid(tab_id_vid[num_encours_vid],lg);
lance_nav_vid(lg);
}
}
}


function display_vid(leid,lg) {
var xmlHttp=GetXmlHttpObject();
if (xmlHttp==null){
alert ("Browser does not support HTTP Request");
return;
} 
document.getElementById("cont_vid_home").innerHTML="<div align='center'><br><br><br><img src='img_com/loading.gif' alt='' width='20' height='20' border='0'><br><br><br></div>"; 
var url="_inc/fonc_display_vid.php";
xmlHttp.onreadystatechange=function() { 
        if (xmlHttp.readyState==4){
            if (xmlHttp.status==200){
              changed_html('cont_vid_home',xmlHttp,leid);
			  }
		}
    }
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded'); 
xmlHttp.send("id_vid="+leid+"&lg="+lg+"&sid="+Math.random());
}



function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?100:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}


function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 2;
	  fadddddd =  window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 20);
    }else {
	clearTimeout(fadddddd);
	}
  }
}


