function calculeOffsetLeft(r){
  return calculeOffset(r,"offsetLeft")
}

function calculeOffsetTop(r){
  return calculeOffset(r,"offsetTop")
}

function calculeOffset(element,attr){
  var offset=0;
  while(element){
    offset+=element[attr];
    element=element.offsetParent
  }
  return offset
}

function deplace_pano(){
	//alert(document.forms["form_mini_pano"].elements["imgpano.y"]);
	//document.getElementById("conteneur_image").doScroll("left");
	//document.getElementById("conteneur_image").doScroll("scrollbarRight");
	
	var pano = document.getElementById("img_pano");
	var cible = document.getElementById("cible");
	
	var pano_left = calculeOffsetLeft(pano);
	var pano_top = calculeOffsetTop(pano);	
	var pano_width = pano.width; 
	var pano_height = pano.height;
	
	for(var i = 0; i < document.getElementById("form_mini_pano").length; i++) {
		alert(document.getElementById("form_mini_pano")[i]);
 	}
	
	cible.style.left = "1200px";
	window.location.href = "#cible";
}

function cache_zooms(){
	
	if(document.getElementById("cache_zooms").innerHTML == "Cacher les zooms"){
		for(var i = 0; i < document.images.length; i++) {
			mon_image = document.images[i];
			if(mon_image.id.substr(0,10) == "picto_zoom"){
				mon_image.style.visibility = "hidden";
			}
 		}
		document.getElementById("cache_zooms").innerHTML = "Afficher les zooms"
	}else{
		for(var i = 0; i < document.images.length; i++) {
			mon_image = document.images[i];
			if(mon_image.id.substr(0,10) == "picto_zoom"){
				mon_image.style.visibility = "visible";
			}
 		}
		document.getElementById("cache_zooms").innerHTML = "Cacher les zooms"
	}
}

function affiche_cadre(num_zoom){
	document.getElementById("cadre_zoom" + num_zoom).style.visibility = "visible";	
}

function cache_cadre(num_zoom){
	document.getElementById("cadre_zoom" + num_zoom).style.visibility = "hidden";
}

// START BULLE
function showpopDesc(idpopdesc,idpopdesc2,height_container_pano,y_container_pano,width_zoom,height_zoom,x_zoom,e) {
	
	var posx = 0;
	var posy = 0;
	var len_width_bulle;
	var width_bulle;
	var height_bulle;
	var width_ecran;
	
	if(!e) var e = window.event;
	
	if (e.pageX || e.pageY){
		posy = e.pageY - y_container_pano - height_zoom - 30;
		posx = x_zoom+width_zoom;
		
	}else if (e.clientX || e.clientY) {
		posy = e.clientY + document.documentElement.scrollTop - y_container_pano - height_zoom - 30;
		posx = x_zoom+width_zoom;
	}
	
	with(document.getElementById(idpopdesc).style){
		//Largeur bulle
		len_width_bulle = width.length;
		width_bulle = width.substr(0, len_width_bulle-2);
		//Largeur Ã©cran
		width_ecran = document.body.clientWidth;
		//On repositionnne la bulle sur la gauche si elle dÃ©passe de l'Ã©cran
		if (e.pageX*1 + width_bulle*1 + width_zoom  > width_ecran) {
			posx = x_zoom - width_bulle - width_zoom;
		}
		else if (e.clientX + width_bulle*1 + width_zoom  > width_ecran) {
			posx = x_zoom - width_bulle - width_zoom;
		}
		
		display = 'block';
		left = posx + 'px';
		top = parseInt(posy) + 'px';
	}
	
	height_bulle = document.getElementById(idpopdesc).offsetHeight;
	
	//On repositionne la bulle vers le haut si elle sort du container panoramique
	if (e.pageY*1 + height_bulle*1 > y_container_pano*1 + height_container_pano*1) {
		posy = e.pageY - height_bulle - height_zoom - 80;
	}
	else if (e.clientY + height_bulle*1 > y_container_pano*1 + height_container_pano*1) {
		posy = e.clientY - height_bulle - height_zoom - 80;
	}
	
	with(document.getElementById(idpopdesc).style){
		top = parseInt(posy) + 'px';
	}
	
	with(document.getElementById(idpopdesc2).style){
		display = 'block';
		left = posx + 'px';
		top = parseInt(posy) + 'px';
		height = height_bulle + 'px';
	}
}

function hidepopDesc(idpopdesc,idpopdesc2) {
	document.getElementById(idpopdesc).style.display='none';
	document.getElementById(idpopdesc2).style.display='none';
}

function loadImage(id_div, html) {
	document.getElementById(id_div).innerHTML = html;
}
// END BULLE

// POPUP FULLSCREEN
function fullScreen(page) {
	window.open(page,'','fullscreen=yes, scrollbars=yes , resizable=no');
}

// POSITIONNEMENT DE L'IMAGE
function positionnePanoFull(id_img,id_div_pano,id_div_loading) {
	var string_height = document.getElementById(id_img).style.height;
	var len_height = string_height.length;
	var height = string_height.substr(0, len_height-2);

	document.getElementById(id_div_pano).style.height = height+"px";
	document.getElementById(id_div_pano).style.marginTop = -(height/2)+"px";
	document.getElementById(id_div_pano).style.display = 'block';

	document.getElementById(id_div_loading).style.display = 'none';
	
	//Si la hauteur du panoramique est supÃ©rieur a la rÃ©solution de l'internaute on modifie le padding du container de l'image pour que celui-ci puisse la visualiser dans son intÃ©gralitÃ©
	if (height > screen.height) {
		document.getElementById(id_div_pano).style.paddingTop = 170+"px";
	}
}
