initBody();
var fotoSeleccionada = '0';
var seleccionada = 0;

var arrayFotos = new Array(
	'bajada_call.jpg', 
	'casa_med_gir_web.jpg', 
	'girona-patio-museo.jpg', 
	'maimonides.jpg', 
	'menora_cordoba.jpg', 
	'patio-cordoba.jpg',
	'levi_toledo.jpg',
	'toledo_transito.jpg',
	'mallorca-banys-2.jpg',
	'lapida-1.jpg'
);

var nomsFotos = new Array(
	'Girona<br />El Call', 
	'Girona<br />El Call', 
	'Girona<br />Museo Judío', 
	'Córdoba<br />Maimónides', 
	'Córdoba<br />Menorah', 
	'Córdoba<br />Patio',
	'Toledo',
	'Toledo',
	'Mallorca<br />Baños',
	'Lápida'
);
var esVertical = new Array(
1, 
1, 
1, 
0, 
0, 
1, 
1, 
0,
0, 
1
);

function inicializar() {
	self.focus();
	if (window.location.search != '') {
		var query = window.location.search.substring(1);
		var q = query.split("&");
		for (i = 0; i < q.length; i++) {
			params = q[i].split("=");
			fotoSeleccionada = params[1];
			if (fotoSeleccionada == '') {
				fotoSeleccionada = '0';
			}	
		}
		seleccionada = parseInt(fotoSeleccionada);
	}
	else {
		seleccionada = 0;
	}
//		alert('seleccionada = ' + seleccionada);
	posarFotoSeleccionada();
}
var resizar = 1;
function onClickImatge(img1) {
	if (resizar) {
		img1.removeAttribute('height');
		resizar = 0;
	}
	else {
		if (esVertical[seleccionada]) {
			img1.setAttribute('height', '400');
			resizar = 1;
		}
	}
}

function posarFotoSeleccionada() {
	var imatge = document.getElementById("imgFoto");
	imatge.setAttribute('src', '');
	imatge.setAttribute('src', '../galeria/sefarad/' + arrayFotos[seleccionada]);
	if (esVertical[seleccionada]) {
		imatge.removeAttribute('width');
		imatge.setAttribute('height', '400');
		imatge.setAttribute('alt', 'Pulse para ampliar');
		imatge.setAttribute('title', 'Pulse para ampliar');
		resizar = 1;
	}
	else {
		imatge.removeAttribute('width');
		imatge.removeAttribute('height');
		imatge.removeAttribute('alt');
		imatge.removeAttribute('title');
		resizar = 0;
	}
	var trMenu = document.getElementById("trFotos");
	if (trMenu) {
		columnas = trMenu.getElementsByTagName('td');
		for (i = 0; i < arrayFotos.length; i++) {
			if (i < columnas.length) {
				tdFoto = columnas[i];
			}
			else {
				tdFoto = document.createElement('td');
				trMenu.appendChild(tdFoto);
			}
			tdFoto.setAttribute('className', 'textpetitgroc');
			tdFoto.setAttribute('class', 'textpetitgroc');
			tdFoto.setAttribute('width', '84');
			tdFoto.setAttribute('align', 'center');
			if (i == seleccionada) {
				tdFoto.innerHTML = '<b>' + nomsFotos[i] + '</b>';
			}
			else { 
//				tdFoto.innerHTML = '<a class="textpetitblanc" href="#" onclick="canviarFoto(' + i + ');" >' + nomsFotos[i] + '</a>';
				tdFoto.innerHTML = "<span class=\"textpetitblanc\" onmouseover=\"canviarCursor(this, 'link');\" onmouseout=\"canviarCursor(this, 'normal');\" onclick=\"canviarFoto('" + i + "');\" >" + nomsFotos[i] + '</span>';
			}
		}
	}

}
function canviarCursor(elem, tipus) {
	if (tipus == 'link') {
		document.body.style.cursor = 'pointer';
		elem.style.textDecoration = 'underline';
	}
	else {
		document.body.style.cursor = 'default';
		elem.style.textDecoration = 'none';
	}
}

function canviarFoto(sel) {
	seleccionada = sel;
	posarFotoSeleccionada();
	document.body.style.cursor = 'default';
}


function initBody() {
	if (document.all) {
		document.body.style.margin = '0px';
	}
	else if (document.body) {
		document.body.style.marginTop = '8px';
		document.body.style.marginBottom = '8px';
		document.body.style.marginLeft = '6px';
		document.body.style.marginRight = '0px';
	}
}

function posarTamanysBotiga() {
	var divCont = document.getElementById("divcontingut");
	divCont.style.height = '280px';
	divCont.style.paddingTop = '4px';
	var divLat = document.getElementById("divlateral");
	divLat.style.height = '280px';

}
function carregarCataleg(tipus) {
	if (tipus != '') {
		frames.framecataleg.location.href = tipus + '.html';
//		cargadoIframe();
	}

}
function cargadoIframe(fr) {
		win = fr.parent;
		var f = win.document.getElementById('framecataleg');
		var altura = '900';
		if (document.all) { // IE
			altura = document.body.scrollHeight;
		}
		else {
			altura = document.documentElement.scrollHeight;
		}
		f.height = altura;
//	var divPeu = document.getElementById("divpeu");
//	divPeu.visible = 'true';
	
}
function obrir(URL, winName) {
	var v = window.open(URL, winName, 
		'toolbar=no,location=no,directories=no,status=no,alwaysRaised=yes,resizable=yes,menubar=no,scrollbars=yes, width=520,height=520,top=0,left=90');
	v.focus();
}

function mouseOverMenu(tdLink) {
	tdLink.setAttribute('class', 'textmenuover');
	tdLink.getElementsByTagName('a')[0].setAttribute('class', 'textmenuover');
}

function mouseOutMenu(tdLink) {
	var link = tdLink.getElementsByTagName('a')[0];
//	presentar(tdLink);
	if (link.href != window.location.href) {
		tdLink.setAttribute('class', 'textmenu');
		link.setAttribute('class', 'textmenu');
	}
	else {
		tdLink.setAttribute('class', 'textmenuseleccionat');
		link.setAttribute('class', 'textmenuseleccionat');
	}
}


var timerPresentar;
var increment = 0.1;
var opacidad = 1.0;
var opacidadIE = 100;
var incrementIE = 10;
var idButton;
function presentar(id) {
	if (timerPresentar != 0) {
		clearInterval(timerPresentar);
	}
	idButton = id;
	opacidad = 1.0;
	opacidadIE = 100;
	timerPresentar = setInterval('reduirOpacitat();', 50);
}

function reduirOpacitat() {
	if (timerPresentar == 0) {
		return;
	}
	if (opacidad > 0.0) {
		opacidad -= increment;
		opacidadIE -= incrementIE;
		if (document.all) {
			idButton.style.filter = 'alpha(opacity=' + opacidadIE + ')';
		}
		else {
			idButton.style.opacity = opacidad;
		}
	}
	else {
		if (document.all) {
			idButton.style.filter = 'alpha(opacity=0)';
		}
		else {
			idButton.style.opacity = 0.0;
		}
		clearInterval(timerPresentar);
		timerPresentar = 0;
	}
}

function obrir(URL, winName) {
	var v = window.open(URL, winName, 
		'toolbar=no,location=no,directories=no,status=no,alwaysRaised=yes,resizable=yes,menubar=no,scrollbars=yes, width=520,height=520,top=0,left=90');
	v.focus();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var opacitats = new Array(45);
function crearArrayOpacitats(frames, maxOp) {
	coef = (Math.PI  / 2) / frames;
	for (i = 0; i < frames; i++) {
		opacitats[i] = 1.0 - Math.cos(i * coef);
	}
}
var altura = 0;
var ampleDivImatge = 0;
var altDivImatge = 0;
var idAmpliarImatge;
var ampleActual = 0;
var altActual = 0;
var incrementAmpleActual = 10;
var incrementAltActual = 10;
var divIm;
var divImatgeAmpliada;
var im;
var idIntervaloImatge;
var idFade1;
var maxOpacitat = .80;

function obrirImatge(nom) {
	var sup = window;
	if (parent) {
		sup = parent.window;
	}
	if (sup.innerWidth) {
		anchoBody = sup.innerWidth;
		alturaBody = sup.innerHeight;
		anchoScrollbars = 16;
	}
	else {
		anchoBody = sup.document.body.scrollWidth;
		alturaBody = sup.document.body.scrollHeight;
//		anchoScrollbars = 20;
		anchoScrollbars = 0;
	}
	if (altura == 0) {
		var divs = sup.document.getElementsByTagName('div');
		for (i = 0; i < divs.length; i++) {
			if (divs[i].className.indexOf('contingut') == 0) {
				altura = divs[i].offsetTop + divs[i].clientHeight;
				break;
			}
		}
	}
//	alert('altura: ' + altura + '; sup.document.body.scrollHeight: ' + sup.document.body.scrollHeight + '; sup.document.body: ' + sup.document.body.clientWidth + ' x ' + sup.document.body.clientHeight + ' pixels');
	if (altura < alturaBody) {
		altura = alturaBody;
	}
	if (altura > sup.document.body.clientHeight) {
		anchoBody -= anchoScrollbars; // per scrollbars
	}
	divImatgeAmpliada = sup.document.getElementById('imatgeAmpliada');
	divImatgeAmpliada.style.width = anchoBody;
	divImatgeAmpliada.style.height = altura;
	divImatgeAmpliada.style.visibility = 'visible';

	divIm = sup.document.getElementById('divImatge');
	divIm.style.visibility = 'visible';
	im = sup.document.getElementById('imatge');
	im.src = nom;
	if (sup.document.body.clientWidth > divIm.clientWidth) {
		divIm.style.left = (sup.document.body.clientWidth - divIm.clientWidth) / 2;
	}
	else {
		divIm.style.left = 0;
	}
	if (sup.document.body.clientHeight > divIm.clientHeight) {
		divIm.style.top = (sup.document.body.clientHeight - divIm.clientHeight) / 2;
	}
	else {
		divIm.style.top = 0;
	}
	im.style.visibility = 'visible';
	
	activarFadeImatge(divImatgeAmpliada);


}

function activarFadeImatge(id1) {
	crearArrayOpacitats(10, maxOpacitat);
	idFade1 = id1;
	if (idIntervaloImatge) clearInterval(idIntervaloImatge);
	opacIn = 0;
	canviarOpacitat(idFade1, opacIn);
	idFade1.style.visibility = 'visible';
	indexOpac = 0;

	idIntervaloImatge = setInterval('fadeImatge()', 10);

	var sup = window;
	if (parent) {
		sup = parent.window;
	}
	sup.scrollTo(0, 0);

}
function canviarOpacitat(idElement, opac) {
	if (idElement) {
		idElement.style.opacity = opac;
		if (document.all) {
			idElement.style.filter = 'alpha(opacity=' + (opac * 100) + ')';
		}
	}
}

function fadeImatge() {
	if (opacIn >= maxOpacitat || indexOpac >= opacitats.length) {
		if (idIntervaloImatge) clearInterval(idIntervaloImatge);
		idIntervaloImatge = 0;
		canviarOpacitat(idFade1, maxOpacitat )
		if (document.all) {
			var sup = window;
			if (parent) {
				sup = parent.window;
			}
			sup.scrollTo(0, 0);
		}
		return opacIn;
	}
	canviarOpacitat(idFade1, opacIn);
	opacIn = opacitats[indexOpac];
	indexOpac++;
	return opacIn;

}


function tancarImatge() {
	var sup = window;
	if (parent) {
		sup = parent.window;
	}
	var divImatgeAmpliada = sup.document.getElementById('imatgeAmpliada');
	divImatgeAmpliada.style.visibility = 'hidden';
	var im = sup.document.getElementById('imatge');
	im.style.visibility = 'hidden';
	var divIm = sup.document.getElementById('divImatge');
	divIm.style.visibility = 'hidden';
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function validarForm() {
	var textError = '';
	if (document.form1.realname.value == '') {
		textError = textError + '- Es obligatorio escribir su nombre.\n';
	}
	if (document.form1.email.value == '') {
		textError = textError + '- Debe indicar su dirección de email.\n';
	}
	if (document.form1.subject.value == '' && document.form1.texto.value == '' ) {
		textError = textError + '- No ha escrito ni asunto ni texto.\n';
	}
	if (textError != '') {
		textError = 'El formulario contiene errores:\n' + textError + 'Por favor, corrija los errores indicados y vuelva a enviar el formulario.\n';
		alert(textError);
		return false;
	}
	return true;
}
function inicializarLibros() {
	var s = window.location.search;
	if (s != '') {
		var query = s.substring(1);
		if (query == 'ok') {
			e = document.getElementById('mensaje');
			e.innerHTML = '<b>Gracias por contactar con nosotros. En breve nos comunicaremos con usted.</b>';
		}
	}
}

