// JavaScript Document
var global_pas=0.03;
var global_delai=null; /////////// dure pdt laquelle l'image est opaque //////////


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;
	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%';
		
		newDiv2.style.cursor='hand';
		if(newDiv2.style.cursor=='')newDiv2.style.cursor='pointer';
		
		var daWidth=img.width;
		var daHeight=img.height;
		
		img=document.createElement("img");
		img.src=urlImg;
		
		img2=document.createElement("img");
		img2.src=urlFermer;
		img2.style.marginTop='10px';
		
		//newDiv2.style.top='100px';
		newDiv2.style.marginLeft='-'+Math.round((daWidth+20)/2)+'px';
		
		newDiv2.appendChild(img);
		newDiv2.appendChild(img2);		
		
		
		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 IE6=vIE();
		if(IE6<=6 && IE6>0){
			var Iframe=document.createElement("iframe");
			Iframe.style.position="absolute";
			Iframe.style.zIndex=100;
			Iframe.style.border='none';
			Iframe.style.backgroundColor='#000000';
			
			Iframe.style.width=600;
			Iframe.style.height=newDiv2.offsetHeight;
			Iframe.style.top=newDiv2.style.top;
			Iframe.style.marginLeft=newDiv2.style.marginLeft;
			
		
			//document.body.appendChild(Iframe);
}

		newDiv2.onclick=function(){closeDiv(newDiv, newDiv2); if(Iframe){document.body.removeChild(Iframe);}}
	}
	verifChargement(img);	
}


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-Math.max((window.innerWidth - document.documentElement.clientWidth),0);
		myHeight=myHeight-Math.max((window.innerHeight - document.documentElement.clientHeight),0);
	}
  }  
   return [ myWidth, myHeight ];
}
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);
		}
	}
}
function vIE(){return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;}
