//capa zoom i capa event
var capaPopup;
          
//array imatges js
var fotos_js = new Array();
          
//guardem la foto
function foto(g_nom,g_wid,g_hei){
    this.g_nom = g_nom;
    this.g_wid = g_wid;
    this.g_hei = g_hei;
}
	
	
//inicialitzem layers necessaris
function init() {
    capaPopup = document.getElementById('popup');
}
	
//afegim la funció init a la seqüčncia de carrega de la plana
if( navigator.userAgent.indexOf('MSIE')!=-1 ){
    window.attachEvent('onload', init );
}else if ( navigator.userAgent.indexOf('Gecko')!=-1 ){
    window.addEventListener( 'load', init, true );
}

function fotoOn(idFoto,contextPath){
    
	//ocultem la foto
    fotoOff();

    //obtenim l'objecte de la foto actual
    foto = fotos_js[idFoto];
    
	//obtenim el html de plantilla
	var strHtml = '';
	strHtml+= '<div class="boxBorderPopUp" style="z-index:1;width:'+(foto.g_wid+2)+'px;height:'+(foto.g_hei+2)+'px;position:absolute;">';
	strHtml+= '		<div class="boxImgPopUp" onclick="javascript:fotoOff();" style="background-image:url('+foto.g_nom+');z-index:1;width:'+foto.g_wid+'px;height:'+foto.g_hei+'px;position:absolute;cursor:pointer;">';
	strHtml+= '			<div class="boxDesImgPopUp">';
	strHtml+= '	       		<span class="desImg"></span>';
	strHtml+= '		    </div>';
	strHtml+= '			<div class="boxCerrarImgPopUp"><a href="javascript:fotoOff();"><span class="closePopUp">cerrar</span></a></div>';
	strHtml+= '		</div>';
	strHtml+= '</div>';
	strHtml+= '<div style="background-image:url('+contextPath+'/img/elems/bor_popup_der.gif);z-index:0;width:'+(foto.g_wid+8)+'px;height:'+foto.g_hei+'px;position:absolute;top:7px;left:7px;"></div>';
	
	//seteam contingut
	capaPopup.innerHTML = strHtml;
	capaPopup.style.width = foto.g_wid;
	capaPopup.style.height = foto.g_hei;
	
	var NS = (navigator.appName=="Netscape")?true:false;
	
	var x,y;
	if (NS){ // all other Explorers
		//Netscape
		anc_doc = window.innerWidth;
	    alt_doc = window.innerHeight;
		x = self.pageXOffset;
		y = self.pageYOffset;
	} else {
		//Internet Explorer
		anc_doc = document.documentElement.offsetWidth;
	    alt_doc = document.documentElement.offsetHeight;
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	
	v_x=parseInt( (( anc_doc - foto.g_wid) / 2)+ x);
    v_y=parseInt( (( alt_doc - foto.g_hei) / 2)+ y);
	
	//asegura posicionar almenos a 30 px del margen superior del navegador
    if (v_y<30){
	    v_y = 30;
    }

	capaPopup.style.top = v_y+'px';
	capaPopup.style.left = v_x+'px';

	//mostrem la capa de la foto
	capaPopup.style.zIndex = 3;
	capaPopup.style.display='inline';
}

function fotoOnConNombre(idFoto,contextPath, nombre, cerrar){
    
	//ocultem la foto
    fotoOff();

    //obtenim l'objecte de la foto actual
    foto = fotos_js[idFoto];
    
	//obtenim el html de plantilla
	var strHtml = '';
	strHtml+= '<div class="boxBorderPopUp" style="z-index:1;width:'+(foto.g_wid+2)+'px;height:'+(foto.g_hei+2)+'px;position:absolute;">';
	strHtml+= '		<div class="boxImgPopUp" onclick="javascript:fotoOff();" style="background-image:url('+foto.g_nom+');z-index:1;width:'+foto.g_wid+'px;height:'+foto.g_hei+'px;position:absolute;cursor:pointer;">';
	strHtml+= '			<div class="boxDesImgPopUp">';
	strHtml+= '	       		<span class="desImg">'+ nombre +'</span>';
	strHtml+= '		    </div>';
	strHtml+= '			<div class="boxCerrarImgPopUp"><a href="javascript:fotoOff();"><span class="closePopUp">' + cerrar + '</span></a></div>';
	strHtml+= '		</div>';
	strHtml+= '</div>';
	strHtml+= '<div style="background-image:url('+contextPath+'/img/elems/bor_popup_der.gif);z-index:0;width:'+(foto.g_wid+8)+'px;height:'+foto.g_hei+'px;position:absolute;top:7px;left:7px;"></div>';
	
	//seteam contingut
	capaPopup.innerHTML = strHtml;
	capaPopup.style.width = foto.g_wid;
	capaPopup.style.height = foto.g_hei;
	
	var NS = (navigator.appName=="Netscape")?true:false;
	
	var x,y;
	if (NS){ // all other Explorers
		//Netscape
		anc_doc = window.innerWidth;
	    alt_doc = window.innerHeight;
		x = self.pageXOffset;
		y = self.pageYOffset;
	} else {
		//Internet Explorer
		anc_doc = document.documentElement.offsetWidth;
	    alt_doc = document.documentElement.offsetHeight;
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	
	v_x=parseInt( (( anc_doc - foto.g_wid) / 2)+ x);
    v_y=parseInt( (( alt_doc - foto.g_hei) / 2)+ y);
	
	//asegura posicionar almenos a 30 px del margen superior del navegador
    if (v_y<30){
	    v_y = 30;
    }

	capaPopup.style.top = v_y+'px';
	capaPopup.style.left = v_x+'px';

	//mostrem la capa de la foto
	capaPopup.style.zIndex = 3;
	capaPopup.style.display='inline';
}

//ocultem la capa del popup de la foto
function fotoOff(){
    capaPopup.style.display = 'none';
}
