function declaraVariablesSeccion()
{		
	intervalo = null;	
	intervaloAux1 = null;
			
	nZoomActual = 1;
	
	imgs = new Array();
	imgsVisor = new Array();
	
	document.body.scroll="no";
	document.body.style.overflow = "hidden";
}


function cargaSeccion()
{	
	var asImagenes = new Array( "bmvalencia/ayuntamiento-valencia.jpg", "bmvalencia/bibliotecas-publicas-municipales-de-valencia.jpg",
							   	"comun/zoom.jpg", "comun/zoom-mas.jpg", "comun/zoom-menos.jpg", "comun/twitter.jpg", "comun/facebook.jpg", "comun/validator-w3.jpg" );
							
	document.getElementById( "ayuntamiento" ).style.display = "block";	
	
	//var sImagenes = "";
	//for( ima=0; ima <= 9; ima++ ) sImagenes += "bmvalencia/"+ima+".jpg,";
	
	asImagenes.push( "bmvalencia/0.jpg" );
	
	iniciarFotos();
	
	return asImagenes;	
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CARGA
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function resize()
{	
	var anTam = tamVentana();
	
	var nAnchura = 1000;
	var nAltura = 585;	
	
	nX = anTam[ 0 ]/2 - nAnchura/2;	
	nY = anTam[ 1 ]/2 - nAltura/2;
	
	if( nX < 0 ) nX = 0;
	if( nY < 0 ) nY = 0;
	
	document.getElementById( 'contenedor' ).style.left = nX+"px";
	document.getElementById( 'contenedor' ).style.top = nY+"px";
	
	document.getElementById( 'porcentaje' ).style.left = anTam[ 0 ]/2 - 40/2+"px";
	document.getElementById( 'porcentaje' ).style.top = anTam[ 1 ]/2 + 55+"px";
	
	document.getElementById( 'fondo' ).style.width = "100%";
	document.getElementById( 'fondo' ).style.height = "100%";
	
	if( document.getElementById( 'cargando' ) != null )
	{	
		document.getElementById( 'cargandoFondoBlanco' ).style.width = anTam[ 0 ]+"px";
		document.getElementById( 'cargandoFondoBlanco' ).style.height = anTam[ 1 ]+"px";
		
		document.getElementById( 'cargando' ).style.width = anTam[ 0 ]+"px";
		document.getElementById( 'cargando' ).style.height = anTam[ 1 ]+"px";			
	}	
	
	scrollTo( 0,0 );
}



function precarga()
{			
	sNavegador = getNavegador();	
	
	leerCSS();

	resize();	
	
	if( sNavegador == "ipad" ) pulsaZoom( 0,'95%' );
	
	document.getElementById( "megusta" ).innerHTML = '<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.bmvalencia.org&amp;locale=es_ES&amp;send=false&amp;layout=button_count&amp;width=450&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font=verdana&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true"></iframe>';
		
	var asImagenes = cargaSeccion();
				
	for( n=0; n < asImagenes.length; n++ )
	{	
		imgs[ n ] = new Image();
		imgs[ n ].src = "castellano/media/imagenes/"+asImagenes[ n ];
	}				
	
	nAux1 = 0;
	nBotonActual = asImagenes.length; //Numero de imgenes
	nZoomActual = (100 / nBotonActual) * ( nBotonActual - imgs.length + 1); //Porcentaje necesario: (100/numero de imagenes) - (Imagenes cargadas+1)
	
	intervalo = window.setInterval( "onProgress()", 1 );
}


function onProgress()
{		
	//Si el contador ha superado el porcentaje correspondiente a la imagen que se está cargando actualmente...
	if( nAux1 >= nZoomActual )
	{		
		//Si la imagen se ha cargado... la quitamos y pasamos a la siguiente, calculando su porcentaje
		if( imgs[ 0 ].complete != false ) 
		{
			imgs.splice( 0, 1 );
		
			nZoomActual = (100 / nBotonActual) * ( nBotonActual - imgs.length + 1); //Porcentaje necesario: (100/numero de imagenes) - (Imagenes cargadas+1);
			
			//alert( nAux1+","+nZoomActual+","+imgs.length+","+imgs[ 0].src+","+imgs[ 0].complete );
			
			if( imgs.length > 0 ) return;
			
			window.clearInterval( intervalo );
		}
		
		//Si aun no se ha cargado la imagen... paramos el contador y esperamos a que se cargue
		else return;
	}
	
	//Si el contador aun no ha superado el porcentaje correspondiente a la imagen que se está cargando actualmente... seguimos contando
	else
	{
		nAux1++;
		if( nAux1 <= 100 ) document.getElementById( "porcentaje" ).innerHTML = Math.ceil( nAux1 )+"%";
		
		return;
	}
	
	webCargada();	
}


function webCargada()
{	
	window.clearInterval( intervalo );
	
	document.getElementById( "porcentaje" ).style.display = "none";
	
	document.getElementById( "contenedor" ).style.visibility = "visible";	
	document.getElementById( "contenedor" ).style.display = "block";
	
	nZoomActual = 1;
	nBotonActual = 0;
	nAux1 = 1;		
		
	intervalo = window.setInterval( "filtroDesaparecer()", 1 );		
}


function filtroDesaparecer()
{
	nAux1 -= 0.1;		
			
	document.getElementById( "cargando" ).style.opacity = nAux1;
	document.getElementById( "cargando" ).style.filter = "alpha(opacity="+( nAux1*100 )+")";	

	document.getElementById( "cargandoFondoBlanco" ).style.opacity = nAux1;
	document.getElementById( "cargandoFondoBlanco" ).style.filter = "alpha(opacity="+( nAux1*100 )+")";
	 
	if( nAux1 <= 0 ) iniciocomun();	
}


function iniciocomun()
{	
	window.clearInterval( intervalo );		
		
	document.getElementById( "cargando" ).style.display = "none";
	document.getElementById( "cargandoFondoBlanco" ).style.display = "none";
	
	document.body.style.overflow = "auto";
	document.body.scroll="auto";
	
	nAux1 = 0;
	nAux2 = 0;
	
	nYTarjeta = 100;
	nMovTarjeta = -10;
	nAlphaTarjeta = 0;
	
	intervalo = window.setInterval( "bienvenido()", 1 );
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// IDIOMAS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function fueraIdioma( nBoton )
{
	var aBotonesIdioma = getElementsByClassName( document.getElementById( "idiomas" ), "idioma" );
	
	aBotonesIdioma[ nBoton ].style.border = "none";
	
}


function sobreIdioma( nBoton )
{
	var aBotonesIdioma = getElementsByClassName( document.getElementById( "idiomas" ), "idioma" );
	
	aBotonesIdioma[ nBoton ].style.border = "1px solid #999";
	
	nAux1 = nAux2 = 0;
	
	document.getElementById( "bienvenido" ).style.opacity = nAux1;
	document.getElementById( "bienvenido" ).style.filter = "alpha(opacity="+( nAux1*100 )+")";
	
	var asMensaje = new Array( "Bienvenido", "Benvingut", "Welcome" );
		
	document.getElementById( "bienvenido" ).innerHTML = asMensaje[ nBoton ];
	
	window.clearInterval( intervalo );	
	
	intervalo = window.setInterval( "bienvenido()", 1 );
}


function bienvenido()
{
	nAux1+=0.05;		
			
	document.getElementById( "bienvenido" ).style.opacity = nAux1;
	document.getElementById( "bienvenido" ).style.filter = "alpha(opacity="+( nAux1*100 )+")";	
	
	nAux2 += 1.25;
	document.getElementById( "bienvenido" ).style.fontSize = nAux2+"px";
	
	if( nAux1 > 1 && nAux2 > 30 ) 
	{
		document.getElementById( "bienvenido" ).style.fontSize = 30+"px";
	}
	
	/*
	if( nMovTarjeta != 0 )
	{
		nYTarjeta += nMovTarjeta;
		
		if( nMovTarjeta < 0 && nYTarjeta < -140 ) 
		{
			nMovTarjeta *= -1;
			document.getElementById( "tarjeta" ).style.zIndex = 20;
			document.getElementById( "idiomas" ).style.zIndex = 21;
		}
		else if( nMovTarjeta > 0 && nYTarjeta >150 ) nMovTarjeta = 0;	
		
		document.getElementById( "tarjeta" ).style.top = nYTarjeta+"px";
	}
	
	nAlphaTarjeta += .05;
	
	if( nAlphaTarjeta <= 2 )
	{
		document.getElementById( "tarjeta" ).style.opacity = nAlphaTarjeta;
		document.getElementById( "tarjeta" ).style.filter = "alpha(opacity="+100*nAlphaTarjeta+")";	
		
		if( nAlphaTarjeta >= 1 ) intervaloTarjeta = window.setInterval( "quitarTarjeta()", 10000 );
	}	
	*/
}


function quitarTarjeta()
{
	window.clearInterval( intervaloTarjeta );
	
	document.getElementById( "tarjeta" ).style.display = "none";
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ZOOM
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function pulsaZoom( nZoom, sZoom )
{
	if( bExplorer )
	{
		alert( "Este servicio no esta habilitado para Internet Explorer. Puede obtener el mismo resultado usando la herramienta Zoom del propio Navegador, situada en la esquina inferior derecha." );
	
		return;
	}
	
	if( sZoom != "" )
	{
		if( sZoom.indexOf( "%" ) >= 0 ) nZoom = sZoom.split( "%" )[ 0 ];
		else nZoom = sZoom;
	}
	
	if( nZoom >= 1 ) nZoomActual = nZoom/100;
	else nZoomActual += nZoom;
	
	if( nZoomActual < 0.5 ) nZoomActual = 0.5;	
	
	var sPropiedad = getPropiedadTransform();
	
	if( sPropiedad != "" ) document.getElementById('contenedor').style[ sPropiedad ] = "scale("+nZoomActual+")";

	document.getElementById('cuadroZoom').value = Math.floor( (nZoomActual*100) )+"%";	
		
	resize();
}


function sobreZoom( objDiv )
{	
	objDiv.style.opacity = .3;
	objDiv.style.filter = "alpha(opacity=30)";
}

function fueraZoom( objDiv )
{
	objDiv.style.opacity = 1;
	objDiv.style.filter = "alpha(opacity=100)";
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// FOTOS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function iniciarFotos()
{
	window.clearInterval( intervaloAux1 );	
	
	aFotos = getElementsByClassName( document.getElementById('espacioFotos'), "foto" );
		
	for( m=0; m < aFotos.length; m++ )
	{
		imgsVisor[ m ] = new Image();			
		imgsVisor[ m ].src = "castellano/media/imagenes/bmvalencia/"+m+".jpg";
	
		aFotos[ m ].style.opacity = 1;
		aFotos[ m ].style.filter = "alpha(opacity=100)";
		aFotos[ m ].style.zIndex = 0;
	}		
		
	nFotoAnterior = aFotos.length-1;
		
	if( aFotos.length > 1 )
	{		
		nSiguienteFoto = nFotoAnterior-1;	
		
		if( nSiguienteFoto < 0 ) nSiguienteFoto = nFotoAnterior;	
		
		nAuxProy2 = 0;
		
		intervaloAux1 = window.setInterval( "precargarSiguienteFoto()", 1 );	
	}
}

function precargarSiguienteFoto()
{ 
	if( imgsVisor[ nSiguienteFoto ].complete != false )
	{
		window.clearInterval( intervaloAux1 );		
		
		intervaloAux1 = window.setInterval( "fotos()", 5000 );
	}	
}



function fotos()
{
	window.clearInterval( intervaloAux1 );	
	
	if( aFotos[ nSiguienteFoto ] != null )
	{
		window.clearInterval( intervaloAux1 );
		
		aFotos[ nSiguienteFoto ].style.opacity = 0;
		aFotos[ nSiguienteFoto ].style.filter = "alpha(opacity=0)";
		aFotos[ nSiguienteFoto ].style.zIndex = aFotos.length+1;
		
		aFotos[ nFotoAnterior ].style.zIndex = 0;
		
		nAuxProy2 = 0;
	
		intervaloAux1 = window.setInterval( "mostrarSiguienteFoto()", 1 );	
	}
}


function mostrarSiguienteFoto()
{
	nAuxProy2 += 0.01;
	
	aFotos[ nSiguienteFoto ].style.opacity = nAuxProy2;
	aFotos[ nSiguienteFoto ].style.filter = "alpha(opacity="+nAuxProy2*100+")";
	
	if( nAuxProy2 >= 1 )
	{
		window.clearInterval( intervaloAux1 );		
		
		aFotos[ nFotoAnterior ].style.opacity = 0;
		aFotos[ nFotoAnterior ].style.filter = "alpha(opacity=0)";
	
		nFotoAnterior = nSiguienteFoto;

		nSiguienteFoto--;
		if( nSiguienteFoto < 0 ) nSiguienteFoto = aFotos.length-1;

		intervaloAux1 = window.setInterval( "precargarSiguienteFoto()", 1 );
	}
}
