// JavaScript Document version 1.05
function centerPopUp (file,w,h,scrollbar,name){
var cx = Math.round ((screen.availWidth / 2) - (w / 2));
var cy = Math.round ((screen.availHeight / 2) - (h / 2));
scrollbar=(scrollbar == "undefined")?'no':scrollbar;
name=(name == "undefined")?'popUp':name;
window.open(file, name, 'height='+ h +', width='+ w +', top='+ cy +', left='+ cx +', toolbar=no, menubar=no, location=no, toolbar = no,resizable=yes, scrollbars='+scrollbar+', status=no');
}
function openPop (file,w,h,scrollbar,name){
scrollbar=(scrollbar == "undefined")?'no':scrollbar;
name=(name == "undefined")?'popUp':name;
window.open(file, name, 'height='+ h +', width='+ w +', top=0, left=0, toolbar=no, menubar=no, location=no, toolbar = no,resizable=yes, scrollbars='+scrollbar+', status=no');
}
////////////////////////////// messages d'alertes simple
function simpleAlert(msg){
	var al = new Alert_window();
	//al.setCloseButton("X","Fermer");
	al.create(msg);
}


function galerie(array,id) {
	var image;
	popLoader();
	var reqgalerie = new HTTP_request("inc/ajax/galerie.php",
				function(){
					if(reqgalerie.isSuccess()){
							image = reqgalerie.getText();
							popup_html(image,array,id);
							deletePopLoader();
					}
			}
			,'get');// nouvelle requete
			reqgalerie.sendRequest('array='+array+"&id="+id);
	
}


function popup_html(affichage,array,id){
	var affichage = affichage;
	var newDiv=document.createElement("div");
		
	/*	
	var newDiv2=document.createElement("div");
	newDiv2.style.position="absolute";
	newDiv2.style.zIndex=200;
	newDiv2.style.textAlign='left';
	newDiv2.style.width= "520px";
	newDiv2.style.padding='10px';
	newDiv2.style.border = '7px solid rgba(0, 0, 0, 0.8)';
	newDiv2.style.backgroundColor='#ffffff';
	newDiv2.style.marginLeft='-'+Math.round(520/2)+'px';
	newDiv2.style.left='50%';
	newDiv2.innerHTML = affichage; 
	document.body.appendChild(newDiv2);
	
	
	var temp=getViewSize()[1]-newDiv2.offsetHeight;
	if(temp>0){newDiv2.style.top=getScrollXY()[1]+(temp/2)+'px';}
	else{newDiv2.style.top=getScrollXY()[1]+'px';}

	*/
	var pop=new JsPop();
	pop.openPop((getViewSize()[1]), "auto","<div id='fauxframe'>"+affichage+"</div>");
	
		/*newDiv2.style.cursor="pointer";
				newDiv.onclick=function(){
				closeDiv(newDiv, newDiv2);
				}
				
				newDiv2.onclick=function(){
				closeDiv(newDiv, newDiv2);
				}*/
				if(document.getElementById("fleche_droite")) {
					document.getElementById("fleche_droite").onclick=function(){
					deletePopLoader();
					galerie(array,(id+1));
					}
				}
				if(document.getElementById("fleche_gauche")) {
					document.getElementById("fleche_gauche").onclick=function(){
					deletePopLoader();
					galerie(array,(id-1));
					}
				}
				
					document.getElementById("fermer").onclick=function(){
					deletePopLoader();
					}

				
				
								

}

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-Math.max((window.innerWidth - document.documentElement.clientWidth),0);
			myHeight=myHeight-Math.max((window.innerHeight - document.documentElement.clientHeight),0);
		}
		/*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 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 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 closeDiv(elem, elem2){
	//, elemFlash, flash
	document.body.removeChild(elem);
	document.body.removeChild(elem2);
	//elemFlash.innerHTML=flash;
}

