var depl_delta=0
var depl=-5
var xs=0
var stop_scroling=0
var timer_scrol=0
var delta=20
var max_right
var gal_center
var doc_gal

var nb_img_affiche
var inter_thumb
var nb_img
var width_photo
var margin_all_thumbs
var url_photo_sel
function shop_gal_debugg(tmp,tmp2){
	var disp_debug=document.getElementById("shop_gal_popup_debug")
	var tmp3=disp_debug.innerHTML
	disp_debug.innerHTML=tmp3+tmp2+":"+tmp+"<br>"
	//document.getElementById("shop_gal_popup").style.width='1800px'
}

function shop_gal_open_popup(url){
	
	var disp=document.getElementById("shop_gal_popup").style.display
	if((disp=="none")||(disp=='')){
		var scroll_top = document.body.scrollTop;
		var scroll_left = document.body.scrollLeft;
		var clientWidth = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
		var clientHeight = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
	
		txt=file_get(url)
		txt=unescape(txt)
		txt=txt.split("[/]");
		nb_img_affiche=txt[1]*1
		inter_thumb=txt[2]*1
		nb_img=txt[3]*1
		width_photo=txt[4]*1
		margin_all_thumbs=txt[5]*1
		url_photo_sel=''+txt[6]+''
		id_photo=txt[7]
		bords_popup=10
		popup_height=clientHeight-50
		
		bug=margin_all_thumbs+bords_popup
		
		popup_width=nb_img_affiche*(width_photo+2+margin_all_thumbs+inter_thumb)+bords_popup+bug
		document.getElementById("shop_gal_popup").style.width = popup_width
		pos_left = scroll_left + (clientWidth/2) - popup_width/2;
		pos_top = scroll_top + (clientHeight/2) - popup_height/2;
		document.getElementById("shop_gal_popup").style.top = pos_top
		document.getElementById("shop_gal_popup").style.left = pos_left
		document.getElementById("shop_gal_popup").innerHTML=txt[0]
		document.getElementById("shop_gal_popup").style.display="block"
		/*
		shop_gal_debugg(escape(url),"url")
		shop_gal_debugg(scroll_top,"scroll_top")
		shop_gal_debugg(scroll_left,"scroll_left")
		shop_gal_debugg(clientWidth,"clientWidth")
		shop_gal_debugg(clientHeight,"clientHeight")
		shop_gal_debugg(nb_img_affiche,"nb_img_affiche")
		shop_gal_debugg(inter_thumb,"inter_thumb")
		shop_gal_debugg(nb_img,"nb_img")
		shop_gal_debugg(width_photo,"width_photo")
		shop_gal_debugg(margin_all_thumbs,"margin_all_thumbs")
		shop_gal_debugg(id_photo,"id_photo")
		shop_gal_debugg(popup_width,"popup_width")
		*/
		start_gal_popup3()
	}
}

function start_gal_popup3(){
	doc_gal=document.getElementById('all_thumbs')
	doc_gal.style.left="0px"
	max_right = nb_img*(width_photo+2+inter_thumb)-nb_img_affiche*(width_photo+2+inter_thumb)
	gal_center = Math.round(document.getElementById('cont_all_thumbs').style.width.replace('px','')/2)
	tmp=nb_img_affiche*(width_photo+2)+(inter_thumb*(nb_img_affiche+1))
	document.getElementById('cont_all_thumbs').style.width=tmp
	document.getElementById('div_zoom_cont').style.width="100%" 
	document.getElementById('div_zoom_cont').style.height=popup_height-300
}

function stop_scrol(){
	stop_scroling=1
	clearInterval(timer_scrol);
	}
	
function scrol_go(dir,from){
	if(from==0) delta=15
	if(from==1) delta=40
	var centre = gal_center-doc_gal.style.left.replace('px','')
	stop_scroling=0
	depl=parseInt(doc_gal.style.left)
	depl+=depl_delta
	if(dir==0){
		depl_delta=-delta
	}
	else{
		depl_delta=delta
	}	
	var new_posleft = doc_gal.style.left.replace('px','')*1+depl_delta*2

	if((depl<=0)&&(depl>=-(max_right))){
			if(dir==0){
				if(new_posleft<-max_right){
					depl=-max_right
				}
			}
			if(dir==1){
				if(new_posleft>=0){
					depl=0
				}
			}
			doc_gal.style.left=depl
	}

	if(stop_scroling==1){
	}
	else{
		timer_scrol=setTimeout('scrol_go('+dir+','+delta+')', 25);
	}
}

function load_img(image){
	document.getElementById('div_zoom').innerHTML='' // vide avant de remettre photo
	document.getElementById('div_zoom').innerHTML="<img id='gal_img_zoom_div' src="+image+" valign=middle>";
	//---Center Y--------
	document.getElementById('div_zoom').style.top=0
	var tmp1=document.getElementById('gal_img_zoom_div').height
	var tmp2=document.getElementById('div_zoom_cont').clientHeight
	if(tmp1<tmp2){
		var tmp3=Math.round((tmp2/2)-(tmp1/2))
		document.getElementById('div_zoom').style.top=tmp3
	}
}

function gal_close(){
	document.getElementById("shop_gal_popup").innerHTML=""
	document.getElementById("shop_gal_popup").style.display="none"
}
