var numpg=0;

function file(fichier){
	/*----------------------- chareger le DivZoomConteneur  -------------------*/
     if(window.XMLHttpRequest) // FIREFOX
          xhr_object_1 = new XMLHttpRequest();
     else if(window.ActiveXObject) // IE
          xhr_object_1 = new ActiveXObject("Microsoft.XMLHTTP");
     else
          return(false);
     xhr_object_1.open("GET", fichier, false);
     xhr_object_1.send(null);
     if(xhr_object_1.readyState == 4) return(xhr_object_1.responseText);
     else return(false);
	 /*------------------------------------------------------------------------*/
     }
	 
function heideMe(){ 
	//-------------------------- cacher le div DivZoomConteneur.
	var DivZoomConteneur=document.getElementById('DivZoomConteneur');
	var DivZoomHider=document.getElementById('DivZoomHider');
	DivZoomHider.className='DivZoomConteneurCSSHeden';
	DivZoomConteneur.className='DivZoomConteneurCSSHeden';
	afficherScrollBar();
	//------------------------------------------------
}
function ZoomImgIn(nbrImgAfficher,idProdAficher){
	
	jebedAtih(nbrImgAfficher,idProdAficher);
	//jebedAtih(nbrImgAfficher,idProdAficher);
	// jebedAtih(nbrImgAfficher,idProdAficher);
	
	}
function jebedAtih(nbrImgAfficher,idProdAficher){ 
	//-------------------------- afficher le DivZoomConteneur.DivZoomConteneur
	
	/*initialiser les dives*/
	
	var DivZoomConteneur=document.getElementById('DivZoomConteneur');
	var DivZoomHider=document.getElementById('DivZoomHider');
	DivZoomHider.className = 'DivZoomHiderCSSShowen';
	DivZoomConteneur.className='DivZoomConteneurCSSShowen';
	
	//sitesourc="http://microchoixad:8082";
	//sitesourc="http://www.microchoix.ma";
	
	texte = file('zoomuploads/ZoomMe.ASP?nbrimg='+nbrImgAfficher+'&idProd='+idProdAficher);
	DivZoomConteneur.innerHTML = texte;
	
	/*initialiser les dives*/
	positionscrol= '0px'; //f_scrollTop()+'px'
	
	document.getElementById('DivZoomHider').style.top= positionscrol;
	document.getElementById('DivZoomConteneur').style.top= positionscrol;
	
	if(f_clientHeight()<700)
	{
		document.getElementById('DivZoomHider').style.height = '700 px';// height
		document.getElementById('DivZoomHider').style.width = f_clientWidth()+' px';// width
		//alert('height=600 & width='+f_clientWidth());
	}else{
		document.getElementById('DivZoomHider').style.height = f_clientHeight()+' px';// height
		document.getElementById('DivZoomHider').style.width = f_clientWidth()+' px';// width
		//alert('height='+ f_clientHeight() +' & width='+f_clientWidth());
	}
	//---------- debut affichage des miniature
	redimImgMenuZoom(nbrImgAfficher);
	/*document.getElementById('tailImgW').value=document.getElementById('imgZoomApercu').width;
	document.getElementById('tailImgH').value=document.getElementById('imgZoomApercu').height;*/
	cacherScrollBar();
	//resizeImg();
	zoomerImage();
	verifierImgsSize();
	resizeImg();
	document.getElementById('DivImgZoomApercu').style.overflow='auto';
	
	
}
function redimImgMenuZoom(nbrImgAfficher){
	
	switch (nbrImgAfficher) 
	{
		case 2:
			var ImgZoomMiniatur1=document.getElementById('ImgZoomMiniatur1');
			var ImgZoomMiniatur2=document.getElementById('ImgZoomMiniatur2');
			
			if( ImgZoomMiniatur1.height < ImgZoomMiniatur1.width ){ 
				ImgZoomMiniatur1.className='ImgZoomMiniatureLsupH';
			}
			else{
				ImgZoomMiniatur1.className='ImgZoomMiniatureHsupL';
			}
			
			if( ImgZoomMiniatur2.height < ImgZoomMiniatur2.width ){ 
				ImgZoomMiniatur2.className='ImgZoomMiniatureLsupH';
			}
			else{
				ImgZoomMiniatur2.className='ImgZoomMiniatureHsupL';
			}

		break;
		case 3:
			var ImgZoomMiniatur1=document.getElementById('ImgZoomMiniatur1');
			var ImgZoomMiniatur2=document.getElementById('ImgZoomMiniatur2');
			var ImgZoomMiniatur3=document.getElementById('ImgZoomMiniatur3');
			
			if( ImgZoomMiniatur1.height < ImgZoomMiniatur1.width ){ 
				ImgZoomMiniatur1.className='ImgZoomMiniatureLsupH';
			}
			else{
				ImgZoomMiniatur1.className='ImgZoomMiniatureHsupL';
			}
			
			if( ImgZoomMiniatur2.height < ImgZoomMiniatur2.width ){ 
				ImgZoomMiniatur2.className='ImgZoomMiniatureLsupH';
			}
			else{
				ImgZoomMiniatur2.className='ImgZoomMiniatureHsupL';
			}
			
			if( ImgZoomMiniatur3.height < ImgZoomMiniatur3.width ){ 
				ImgZoomMiniatur3.className='ImgZoomMiniatureLsupH';

				
			}
			else{
				ImgZoomMiniatur3.className='ImgZoomMiniatureHsupL';
			}	
		break;	
		case 4:
		//alert('ok4');
			var ImgZoomMiniatur1=document.getElementById('ImgZoomMiniatur1');
			var ImgZoomMiniatur2=document.getElementById('ImgZoomMiniatur2');
			var ImgZoomMiniatur3=document.getElementById('ImgZoomMiniatur3');
			var ImgZoomMiniatur4=document.getElementById('ImgZoomMiniatur4');
			
			if( ImgZoomMiniatur1.height < ImgZoomMiniatur1.width ){ 
				ImgZoomMiniatur1.className='ImgZoomMiniatureLsupH';
			}
			else{
				ImgZoomMiniatur1.className='ImgZoomMiniatureHsupL';
			}
			
			if( ImgZoomMiniatur2.height < ImgZoomMiniatur2.width ){ 
				ImgZoomMiniatur2.className='ImgZoomMiniatureLsupH';
			}
			else{
				ImgZoomMiniatur2.className='ImgZoomMiniatureHsupL';
			}
			
			if( ImgZoomMiniatur3.height < ImgZoomMiniatur3.width ){ 
				ImgZoomMiniatur3.className='ImgZoomMiniatureLsupH';
				
			}
			else{
				ImgZoomMiniatur3.className='ImgZoomMiniatureHsupL';
			}	
						
			if( ImgZoomMiniatur4.height < ImgZoomMiniatur4.width ){ 
				ImgZoomMiniatur4.className='ImgZoomMiniatureLsupH';
				
			}
			else{
				ImgZoomMiniatur4.className='ImgZoomMiniatureHsupL';
			}	
		break;	
		default:
		
			var ImgZoomMiniatur1=document.getElementById('ImgZoomMiniatur1');
			if( ImgZoomMiniatur1.height < ImgZoomMiniatur1.width ){ 
				ImgZoomMiniatur1.className='ImgZoomMiniatureLsupH';
			}
			else{
				ImgZoomMiniatur1.className='ImgZoomMiniatureHsupL';
			}
	}
	//----------------- fin d'affichage des images miniatures.		
	//alert(nbrImgAfficher);
	//PositionnerDivZoomApercu(nbrImgAfficher);
	zoomerImage();
	verifierImgsSize();

}

function PositionnerDivZoomApercu(){//nbrImagesZoom
	//----------------- debut mise en page contenu ----------

	anassWd2 = 900;
	anassHd2 = 600; 
	docWidth=f_clientHeight();
	
	if(docWidth<600){
		hDoc = 600;	
	}else{
		hDoc = docWidth;	
	}
	
	wDoc = f_clientWidth();
	
	/*   ajustement des div sur l'image  */
	positionscrol=f_scrollTop();
	valWDivZoomConteneur = anassWd2 ;
	valHDivZoomConteneur = anassHd2;
	PosXDivZoomConteneur=(wDoc - valWDivZoomConteneur)/2 ;
	PosYDivZoomConteneur=10 + positionscrol; //(hDoc - valHDivZoomConteneur)/2 ;
	//alert('step:2')
	/**/
	if(window.XMLHttpRequest) // FIREFOX
 	{
	document.getElementById('DivZoomHider').style.top = positionscrol + 'px';
		}
	document.getElementById('DivZoomHider').style.top = positionscrol + 'px';
	//document.getElementById('DivZoomConteneur').style.top = positionscrol + 'px';
	document.getElementById('DivZoomConteneur').style.left = PosXDivZoomConteneur + 'px';
	document.getElementById('DivZoomConteneur').style.top = PosYDivZoomConteneur + 'px';
	//cacherScrollBar();
	//----------------- fin mise en page contenu -----------------------------------
}
function cacherScrollBar()   	
  {  
	  if(window.XMLHttpRequest) // FIREFOX
		{
			  document.body.style.overflow='hidden'; 
		}
	  else if(window.ActiveXObject) // IE
		{
			  document.body.className='bodyconfProp';    		
		}
  	}    
function afficherScrollBar()   
  {
	 if(window.XMLHttpRequest) // FIREFOX
		{
			  document.body.style.overflow=''; 
		}
	 else if(window.ActiveXObject) // IE
		{
			  document.body.className='body';   		
		}    		 
} 


function afficherImg(imgAAfficher){
	document.getElementById('imgZoomApercu').src=imgAAfficher;
	/*document.getElementById('tailImgW').value=document.getElementById('imgZoomApercu').width;
	document.getElementById('tailImgH').value=document.getElementById('imgZoomApercu').height;*/
	zoomerImage();
}

function update () {
	document.forms[0].elements['sc4h'].value = f_scrollLeft();
	document.forms[0].elements['sc4v'].value = f_scrollTop();
	setTimeout('update()', 200);
	document.forms[0].elements['v0'].value = navigator.userAgent;
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
//-----------------------------------------------------------------------------
//				sureveiller l'image apércu
//-----------------------------------------------------------------------------

function verifierImgsSize(){
	var DivZoomHider=document.getElementById('DivZoomHider');
	if (DivZoomHider.className == 'DivZoomHiderCSSShowen' ){ 
	PositionnerDivZoomApercu();
	setTimeout("verifierImgsSize()",1000);
	}
}

function recupereImgSize(){
	tailWImgAct=document.getElementById('imgZoomApercu').width;
	tailHImgAct=document.getElementById('imgZoomApercu').height;
}
	
function resizeImg(){//varEtatZoom
	var tailWMax=790;
	var tailHMax=500;

		tailWImgAct=document.getElementById('imgZoomApercu').width;
		tailHImgAct=document.getElementById('imgZoomApercu').height;
		
		if(tailHImgAct<20){
			tailHImgAct=500;
		}
		document.getElementById('DivImgZoomApercu').style.overflow='Auto';
		//alert('haeden');
		if (tailWImgAct <= tailWMax && tailHImgAct <= tailHMax)
		{
			document.getElementById('DivImgZoomApercu').style.overflow='hidden';
		}
		//	recupereImgSize();
		var myStr=document.getElementById('DivImgZoomApercu').style.height;
		lentStr=myStr.length-2;
		result=myStr.substring(0,lentStr);
		result=(result - tailHImgAct)/2;
		
		

		if (tailHImgAct <= tailHMax)
		{
			//alert(document.getElementById('imgZoomApercu').src);
			xPad=250-(tailHImgAct/2);
			xHaut=500-xPad;
			document.getElementById('DivImgZoomApercu').style.height=xHaut+'px';
			document.getElementById('DivImgZoomApercu').style.paddingTop=xPad+'px';
		}
}

//------------------------------------------------------------------------------
// Zoomer / dézoomer:
//******************************************************************************

function zoomerImage(){
	resizeImg();
	/*
	tailWImgAct=document.getElementById('imgZoomApercu').width;
	tailHImgAct=document.getElementById('imgZoomApercu').height;	
	//document.getElementById('imgZoomApercu').height;
	if (tailWImgAct >= 500 || tailHImgAct >= 500){
		resizeImg(1);
	}
	else{
		resizeImg(2);
	} 
	*/
}

