var numpg=0;

function file(fichier){
	/*----------------------- chareger le DivZoomConteneur  -------------------*/
     if(window.XMLHttpRequest) // FIREFOX
          xhr_object = new XMLHttpRequest();
     else if(window.ActiveXObject) // IE
          xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
     else
          return(false);
     xhr_object.open("GET", fichier, false);
     xhr_object.send(null);
     if(xhr_object.readyState == 4) return(xhr_object.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://server-2006:5555";
	sitesourc="http://www.microchoix.ma";
	
	texte = file(sitesourc+'/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();
	document.getElementById('DivImgZoomApercu').style.overflow='auto';
	verifierImgsSize();
	
}
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 = 800;
	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(){
/*
	PositionnerDivZoomApercu();
	setTimeout("verifierImgsSize()",1000);
*/
	var DivZoomHider=document.getElementById('DivZoomHider');
	if (DivZoomHider.className == 'DivZoomHiderCSSShowen' ){ 
	//alert('hana');
	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;
		
		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);
		
		//alert('ok resizeImg() :: result= ' + result + " tailHImgAct= " + tailHImgAct + " tailWImgAct= " + tailWImgAct);
		
		result=(result - tailHImgAct)/2;
		
		//alert('pading : ' + result );
				
		if (tailHImgAct <= tailHMax)
		{
			document.getElementById('DivImgZoomApercu').style.paddingTop=result+'px';
			var novaHeiDiv=(500-result);
			document.getElementById('DivImgZoomApercu').style.height=novaHeiDiv+'px';
		}
					
					
		PositionnerDivZoomApercu();
}

//------------------------------------------------------------------------------
// 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);
	} 
	*/
}

//------------------------------------------------------------------------------
//          mouvement de la sourie
//******************************************************************************
/*function position(e)
	{
		var DivImgZoomApercu=document.getElementById('DivImgZoomApercu');        
	x = (navigator.appName.substring(0,3) == "Net") ? e.pageX : event.x+DivImgZoomApercu.scrollLeft;
	y = (navigator.appName.substring(0,3) == "Net") ? e.pageY : event.y+DivImgZoomApercu.scrollTop;
	window.status = "Souris X:"+x+" / Y:"+y;
	}
/*if(navigator.appName.substring(0,3) == "Net")
	document.captureEvents(Event.MOUSEMOVE);
document.getElementById('DivImgZoomApercu').onmousemove = position;*/

/*function init(){
image.onMouseMove=mov;
this.onMouseMove=mov1;
}*/
/*
function mov1(){  

var DivImgZoomApercu=document.getElementById('DivImgZoomApercu');        
var ImgZoomApercu=document.getElementById('ImgZoomApercu');   
mw=800;
mh=500;
xm= (navigator.appName.substring(0,3) == "Net") ? e.pageX : event.x+DivImgZoomApercu.scrollLeft;
ym= (navigator.appName.substring(0,3) == "Net") ? e.pageY : event.y+DivImgZoomApercu.scrollTop;	


if(xm>mw){ xm=mw };
if(xm<0){ xm=0 };
if(ym>mh){ ym=mh };
if(ym<0){ ym=0 };
/*
hdiffh=ImgZoomApercu.height-mh;
hdiffw=ImgZoomApercu.height-mw;

		var myStrH=ImgZoomApercu.style.height;
		lentStrH=myStrH.length-2;
		IZApercuH=myStrH.substring(0,lentStrH);

		var myStrW=ImgZoomApercu.style.height;
		lentStrW=myStrW.length-2;
		IZApercuW=myStrW.substring(0,lentStrW);

if( IZApercuW <= mw || IZApercuH <= mh){
			//alert('test 1 ok');
		//if (ImgZoomApercu._x > -(ImgZoomApercu._height-mh)){
			ImgZoomApercu.style.position='fixed';
			posX=-((xm/mw)*(IZApercuW-mw));
			posY=-((ym/mh)*(IZApercuH-mh));
			ImgZoomApercu.style.left=posX+'px';	
			ImgZoomApercu.style.top=posY+'px';	
		//}
		
		window.status = "Souris posX:"+posX+" / posY:"+posY;
		
	}*/
	/*else{
			//ImgZoomApercu.style.position='absolute';
	}*/
	
	//window.status = "Souris X:"+xm+" / Y:"+ym;
//}
/*function mov(){
	
	this._x+=(this._x-this._x)*0.2;
	this._y+=(this._y-this._y)*0.2;
}*/
