/////////////////////////// variables a paramétrer //////////////////

var pas_initial=5; //// nombre de pixels dont bouge la scrollbar à l'état initial
var pas=3; //// nombre de pixels dont le pas initial va etre incrémenté au bout de n tours
var tour=12; //// nombre de tours de boucles a effectuer avant d'incrémenter le pas
var limit=110; /// limite le pas pour éviter qu'au fur et a mesure il incrémente a l'infini

/////////////////////// fin des variables a paraméter //////////////////



//// variables à ne pas toucher ///
var id_el;
var stopp=0;
var compt;
var inc=pas_initial;
var inc2=0;
//////////////////////////////////

function hide_scroll(id){
	var obj=document.getElementById(id);
	obj.style.overflow='hidden';	
}

function defil_scroll_haut(id){
	id_el=id;
	var obj=document.getElementById(id_el);
	var pos=obj.scrollTop;
	
	if(compt==0) stopp=0;
	
	if(inc>=limit) inc=limit;
	obj.scrollTop=pos+inc;
	
	if(stopp==0){		
		compt=1;
		inc2++;
		if(inc2%tour==0) inc=inc+pas;
		window.setTimeout("defil_scroll_haut(id_el)",0);
	}
	else {
		compt=0;
	}
	
	
}

function stop_scroll(){
	stopp=1;	
	inc=pas_initial;
	inc2=0;
}


function defil_scroll_bas(id){
	id_el=id;
	var obj=document.getElementById(id_el);
	var pos=obj.scrollTop;
	
	if(compt==0) stopp=0;
	
	if(inc>=limit) inc=limit;
	obj.scrollTop=pos-inc;
	
	if(stopp==0){		
		compt=1;
		inc2++;
		if(inc2%tour==0) inc=inc+pas;
		window.setTimeout("defil_scroll_bas(id_el)",0);
	}
	else {
		compt=0;
	}
	
	
}


/////////////******* fin fonction pr défiler sans scrollbar **********/////////////////////
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}


function getViewSize() { //// renvoie taille de la zone d'affichage
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  /// pr enlever espace occupé par scrollbars
  if(typeof(window.innerHeight) == 'number'){
	 if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ){
		myWidth=myWidth-(window.innerWidth - document.documentElement.clientWidth);
		myHeight=myHeight-(window.innerHeight - document.documentElement.clientHeight);
	}
	/*else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ){
		myWidth=myWidth-(window.innerWidth - document.body.clientWidth);
		myHeight=myHeight-(window.innerHeight - document.body.clientHeight);
	 }*/
  }  
   return [ myWidth, myHeight ];
}

function initPositionDiv(elem){
	var tab = new Array();
	tab = getScrollXY();
	elem.style.top=tab[1]+'px';
	elem.style.left=tab[0]+'px';
	elem.style.height=getViewSize()[1]+'px';
	window.setTimeout(function(){initPositionDiv(elem)}, 10);
}

function openDiv(urlImg, urlFermer){
	//, elemFlash
	var newDiv=document.createElement("div");
	var opa=0.6;
	newDiv.style.position="absolute";
	newDiv.style.zIndex=100;
	//newDiv.style.top=0;
	initPositionDiv(newDiv);
	newDiv.style.width='100%';
	newDiv.style.backgroundColor='#000000';
	newDiv.style.opacity=opa;
	newDiv.style.filter = "alpha(opacity=" + (opa*100) + ")"; /// pr IE
	document.body.appendChild(newDiv);
	
	var img = new Image();
	img.src=urlImg;
	
	var img2 = new Image();
	img2.src=urlFermer;
	img2.style.marginTop='10px';
	img2.style.cursor='hand';
	if(img2.style.cursor=='')img2.style.cursor='pointer';
	
	chargementFini=function(){
		var newDiv2=document.createElement("div");
		newDiv2.style.position="absolute";
		newDiv2.style.zIndex=200;
		newDiv2.style.textAlign='right';
		newDiv2.style.width=img.width+'px';
		newDiv2.style.border='10px solid white';
		newDiv2.style.backgroundColor='#ffffff';
		newDiv2.style.left='50%';
		
		/*
		var top=Math.round((img.height+20)/2);
		newDiv2.style.marginTop='-'+top+'px';
		newDiv2.style.top='50%';
		*/
		
		
		newDiv2.style.top='100px';
		newDiv2.style.marginLeft='-'+Math.round((img.width+20)/2)+'px';
		
		newDiv2.appendChild(img);
		newDiv2.appendChild(img2);
		document.body.appendChild(newDiv2);
		
		/*
		var flash=elemFlash.innerHTML;
		elemFlash.innerHTML='';
		*/
		//, elemFlash, flash
		img2.onclick=function(){closeDiv(newDiv, newDiv2);}
	}
	
	verifChargement(img);
	
}

function closeDiv(elem, elem2){
	//, elemFlash, flash
	document.body.removeChild(elem);
	document.body.removeChild(elem2);
	//elemFlash.innerHTML=flash;
}

function verifChargement (img){		
	if(img.complete == true ){
		if(chargementFini) chargementFini();
	}
	else{
		if(img.complete == undefined){
			if(chargementFini) {
				img.onload = function(){chargementFini()};
			}
		}
		else{
			window.setTimeout(function(){verifChargement(img)}, 10);
		}
	}
}




var obj;
var haut;
var vit;
var test=0;
var test2=0;
var test3=0;

function menu(id, hauteur,vitesse) {
if(test3==0) {
		test2=0;
		fermer_tout(id);
	}
	obj = id;
	haut = hauteur;
	vit = vitesse;	
	
		
		if(test==0) {
			// document.getElementById('menu78').style.visibility = 'hidden';
			/*var long_div=d.getElementById(id).parentNode.getElementsByTagName("div").length;
				for(j=0;j<long_div;j++) {
						d.getElementsByTagName("div")[j].style.visibility='hidden';
				}*/		
			
			
			if(test2==0){
			document.getElementById(id).style.height='1px';
			document.getElementById(id).style.width='7px';
			document.getElementById(id).style.visibility = 'visible';
			}
			document.getElementById(id).style.opacity=1;
			document.getElementById(id).style.MozOpacity = 1;
			document.getElementById(id).style.filter = "alpha(opacity=" + 100 + ")";
			//test2=0;
		}
		var h=document.getElementById(id).style.height;	
		h=h.split('px');
		h = Number(h[0]) + vit;		
		test3=1;
		
		 if(h<haut & test2==0) {	 
		 document.getElementById(id).style.height= h+'px';	
		 test=1; 
			setTimeout("menu(obj, haut, vit)",0);	
		}
		else {
			var w=document.getElementById(id).style.width;	
			w=w.split('px');
			w = Number(w[0]) + vit;		
			
			 if(w<171 & test2==0) {	 
			 document.getElementById(id).style.width= w+'px';	
				setTimeout("menu(obj, haut, vit)",0);	
			}
			else {
				test3=0;
				document.getElementById(id).style.width= 171+'px';
			}
			
			
		}
 	
}

var g_test;
var test_o=0;
function fermer_menu(id, vitesse) {	
	obj = id;
	vit = vitesse;
	
		if(g_test!=1){
			if(test_o==0) {
				document.getElementById(id).style.opacity=1.3;
				document.getElementById(id).style.MozOpacity=1.3;
				document.getElementById(id).style.filter = "alpha(opacity=130)";
			}
			var o=document.getElementById(id).style.opacity;
			var o_ie=o*100;
			
			if(o>0) {	 
				document.getElementById(id).style.opacity= (o-vit);
				document.getElementById(id).style.MozOpacity= (o-vit);
				vit2=vit*100;
				document.getElementById(id).style.filter = "alpha(opacity=" + (o_ie-vit2) + ")";
			
			 test_o=1;
			 setTimeout("fermer_menu(obj, vit)",0);
			}
			else {
				
				//window.setTimeout("hidden(obj)",250);
				document.getElementById(id).style.visibility = 'hidden';
				//document.getElementById(id).style.border = '1px solid red';
				test=0;
				test2=1;
				test_o=0;
			}
		}
		else {
			document.getElementById(id).style.opacity=1.3;
			document.getElementById(id).style.filter = "alpha(opacity=" + 130 + ")";
		}

	
}

function hidden(id){
document.getElementById(id).style.visibility = 'hidden';
test=0;
				test2=1;
				test_o=0;
}

function fermer_tout(id){
	for(i=75;i<96;i++){
		if(document.getElementById('menu'+i)) {
			if(id!='menu'+i) document.getElementById('menu'+i).style.visibility='hidden';
		}
	}
	
}

function scroll_bas() {
	//if(screen.width<=800)	
	document.body.scrollLeft=13;
	document.documentElement.scrollLeft=13;	
}


function affich_fleche(id, fleche_h, fleche_b, haut_max){
	if(document.getElementById){
		if(document.getElementById(id)){
			haut_div=document.getElementById(id).offsetHeight;
			if(haut_div>haut_max){
				if(document.getElementById(fleche_h)){
					if(document.getElementById(fleche_b)) {
						document.getElementById(fleche_h).style.visibility='visible';
						document.getElementById(fleche_b).style.visibility='visible';	
					}
				}
				
			}			
		}
	}
	
}

//alert(document.getElementById('sous_droite2').offsetHeight);

function ouvre_seul(id) {
	var d = document.getElementById(id);
	if (d) {
				var long_div=document.getElementsByTagName("div").length;
				for(j=0;j<long_div;j++) {
					if(document.getElementsByTagName("div")[j].className=='menu') {
						document.getElementsByTagName("div")[j].style.display='none';
					}
				}
		d.style.display='block';
		//d.style.zIndex=10;
	}
}
////////////////////////////////////////////////
function ferme_seul2(id) {
	var d = document.getElementById(id);
	if (d) {d.style.display='none';
	//d.style.zIndex=1;
	}
}

function ferme_seul(id) {
	var d = document.getElementById(id);
	obj=id;
	if (d) {
		window.setTimeout("ferme_seul3(obj)",250);
	}
}

function ferme_seul3(id) {
	if(g_test==0) {
		document.getElementById(id).style.display='none';
		//document.getElementById(id).style.zIndex=1;
	}
}
