// -----------------------------------------------------------------------------------
//
//	Lightbox v2.0
//	by Lokesh Dhakar - http://www.huddletogether.com
//	3/27/06
//
//	For more information on this script, visit:
//	http://huddletogether.com/projects/lightbox2/
//
//	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//
//	Credit also due to those who have helped, inspired, and made their code available to the public.
//	Including: Scott Upton(uptonic.com), Peter-Paul Koch(quirksmode.org), Thomas Fuchs(mir.aculo.us), and others.
//
//
// -----------------------------------------------------------------------------------
/*

	Table of Contents
	-----------------
	Configuration
	Global Variables

	Extending Built-in Objects
	- Object.extend(Element)
	- Array.prototype.removeDuplicates()
	- Array.prototype.empty()

	lightbox Class Declaration
	- initialize()
	- start()
	- changeImage()
	- resizeImageContainer()
	- showImage()
	- updateDetails()
	- updateNav()
	- preloadNeighborImages()
	- end()

	Miscellaneous Functions
	- getPageScroll()
	- getPageSize()
	- getKey()
	- listenKey()
	- showSelectBoxes()
	- hideSelectBoxes()
	- pause()
	- addLoadEvent()
	- initLightbox()

	Function Calls
	- addLoadEvent(initLightbox)

*/
// -----------------------------------------------------------------------------------
// adaptacion de la libreria LIGHBOX de Lokesh Dhakar - http://www.huddletogether.com
//
//	Configuration
//
var fileLoadingImage = "/images/loading.gif";
var fileBottomNavCloseImage = "/images/close.gif";
var borderSize = 10;
var gBoo_mostrarAlbum=true
var carousel=null;
var anchoIniCarrusel=0;
var gBoo_FlechasDepCarrusel=true
// -----------------------------------------------------------------------------------

//
//	Global Variables
//
var imageArray = new Array;
var activeImage;

// -----------------------------------------------------------------------------------

//
//	Additional methods for Element added by SU, Couloir
//	- further additions by Lokesh Dhakar (huddletogether.com)
//
Object.extend(Element, {
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth;
	},
	setWidth: function(element,w) {
	   	element = $(element);
    	element.style.width = w +"px";
	},
	setHeight: function(element,h) {
   		element = $(element);
    	element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
//    	element.style.top = t +"px";
    	element.style.top = t +"px";
	},
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src;
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href;
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});

// -----------------------------------------------------------------------------------

//
//	Extending built-in Array object
//	- array.removeDuplicates()
//	- array.empty()
//
Array.prototype.removeDuplicates = function () {
	for(i = 1; i < this.length; i++){
		if(this[i][0] == this[i-1][0]){
			this.splice(i,1);
		}
	}
}

// -----------------------------------------------------------------------------------

Array.prototype.empty = function () {
	for(i = 0; i <= this.length; i++){
		this.shift();
	}
}

// -----------------------------------------------------------------------------------

//
//	lightbox Class Declaration
//	- initialize()
//	- start()
//	- changeImage()
//	- resizeImageContainer()
//	- showImage()
//	- updateDetails()
//	- updateNav()
//	- preloadNeighborImages()
//	- end()
//
//	Structuring of code inspired by Scott Upton (http://www.uptonic.com/)
//
var lightbox = Class.create()

lightbox.prototype = {

	// initialize()
	// Constructor runs on completion of the DOM loading. Loops through anchor tags looking for
	// 'lightbox' references and applies onclick events to appropriate links. The 2nd section of
	// the function inserts html at the bottom of the page which is used to display the shadow
	// overlay and the image container.
	//

	initialize: function() {
		//if (!document.getElementsByTagName){ return; }
		/*var anchors = document.getElementsByTagName('a');
		// loop through all anchor tags
		for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];

			var relAttribute = String(anchor.getAttribute('rel'));

			// use the string.match() method to catch 'lightbox' references in the rel attribute
			if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('pegatinas'))){
				anchor.onclick = function () {myLightbox.start(this); return false;}
			}

		}*/

		// The rest of this code inserts html at the bottom of the page that looks similar to this:
		//
		//	<div id="overlay"></div>
		//	<div id="lightbox">
		//		<div id="imageContainer">
		//			<img id="lightboxImage">
		//			<div style="" id="hoverNav">
		//				<a href="#" id="prevLink"></a>
		//				<a href="#" id="nextLink"></a>
		//			</div>
		//			<div id="loading">
		//				<a href="#" id="loadingLink">
		//					<img src="/Ebatzokia/images/loading.gif">
		//				</a>
		//			</div>
		//		</div>
		//		<div id="imageData">
		//			<div id="imageDetails">
		//				<span id="caption"></span>
		//				<span id="numberDisplay"></span>
		//			</div>
		//			<div id="bottomNav">
		//				<a href="#" id="bottomNavClose">
		//					<img src="/Ebatzokia/images/close.gif">
		//				</a>
		//			</div>
		//		<div id="formuComentarios">
		//		</div>
		//		</div>
		//	</div>


		var objBody = document.getElementsByTagName("body").item(0);

		if(!$('sombreado')){
			crearCapaSombreado()
		}
		objOverlay=$('sombreado')
		objOverlay.style.display = 'none';

		this.crearCarrusel(objBody);
		
		var objLightbox = document.createElement("div");
		objLightbox.setAttribute('id','lightbox');
		objLightbox.style.display = 'none';
		objBody.appendChild(objLightbox);

		var objImageContainer = document.createElement("div");
		objImageContainer.setAttribute('id','imageContainer');
		objImageContainer.onclick = null;
		objLightbox.appendChild(objImageContainer);

		var objLightboxImage = document.createElement("img");
		objLightboxImage.setAttribute('id','lightboxImage');
		objImageContainer.appendChild(objLightboxImage);

		var objHoverNav = document.createElement("div");
		objHoverNav.setAttribute('id','hoverNav');
		objImageContainer.appendChild(objHoverNav);

		var objPrevLink = document.createElement("a");
		objPrevLink.setAttribute('id','prevLink');
		objPrevLink.setAttribute('href','#');
		objHoverNav.appendChild(objPrevLink);

		var objNextLink = document.createElement("a");
		objNextLink.setAttribute('id','nextLink');
		objNextLink.setAttribute('href','#');
		objHoverNav.appendChild(objNextLink);

		var objLoading = document.createElement("div");
		objLoading.setAttribute('id','loading');
		objImageContainer.appendChild(objLoading);

		var objLoadingLink = document.createElement("a");
		objLoadingLink.setAttribute('id','loadingLink');
		objLoadingLink.setAttribute('href','#');
		objLoadingLink.borrar=true
		objLoadingLink.onclick = function() {myLightbox.end(this.borrar,this.zIndexCapaSombra);
			return false;
		}
		objLoading.appendChild(objLoadingLink);

		var objLoadingImage = document.createElement("img");
		objLoadingImage.setAttribute('src', fileLoadingImage);
		objLoadingLink.appendChild(objLoadingImage);

		var objImageData = document.createElement("div");
		objImageData.setAttribute('id','imageData');
		objLightbox.appendChild(objImageData);

		var objImageDetails = document.createElement("div");
		objImageDetails.setAttribute('id','imageDetails');
		objImageData.appendChild(objImageDetails);

		var objCaption = document.createElement("div");
		objCaption.setAttribute('id','caption');
		objImageDetails.appendChild(objCaption);

		var objNumberDisplay = document.createElement("span");
		objNumberDisplay.setAttribute('id','numberDisplay');
		objImageDetails.appendChild(objNumberDisplay);

		var objBottomNav = document.createElement("div");
		objBottomNav.setAttribute('id','bottomNav');
		objImageData.appendChild(objBottomNav);

		var enlMostrarForm=document.createElement("p")
		objImageData.appendChild(enlMostrarForm)

		var enlace=document.createElement("a")
		enlace.setAttribute("id","abrirForment")
		enlace.setAttribute("href","#")
		enlace.onclick=function (){
			url='comentarios_album.shtml?gTxt_ID='+this.regid+'&gTxt_Numresgistro119='+this.paginacion+'&'+Math.round(Math.random()*1223456789)
			window.location.href=url
			return false;
		}
		enlMostrarForm.appendChild(enlace)

		Element.setInnerHTML(enlace,literalEnlace)

		var enlaceVerComentarios=document.createElement("a")
		enlaceVerComentarios.setAttribute("id","verComentarios")
		enlaceVerComentarios.setAttribute("href","#")
		enlaceVerComentarios.onclick=function (){	 return false;}
		enlMostrarForm.appendChild(enlaceVerComentarios)

		Element.setInnerHTML(enlaceVerComentarios,literalVerComentarios)



		var objFormComent=document.createElement("div")
		objFormComent.setAttribute('id','formuComentarios');
		Element.hide(objFormComent)
		objImageData.appendChild(objFormComent);

		var formulario=document.createElement("form")
		formulario.setAttribute("action","")
		formulario.setAttribute("name","formulario")
		formulario.setAttribute("method","")
		objFormComent.appendChild(formulario)


		var divComentarios=document.createElement("div")
		formulario.appendChild(divComentarios)

		var etiqueta=document.createElement("label")
		divComentarios.appendChild(etiqueta)

		Element.setInnerHTML(etiqueta,literalLabel)

		var hiddenId=document.createElement("input")
		hiddenId.setAttribute("type","hidden")
		hiddenId.setAttribute("id","idHiden")
		hiddenId.setAttribute("name","wRegistro")
		hiddenId.setAttribute("value","")
		divComentarios.appendChild(hiddenId)

		var hiddenSeccion=document.createElement("input")
		hiddenSeccion.setAttribute("type","hidden")
		hiddenSeccion.setAttribute("id","seccion")
		hiddenSeccion.setAttribute("name","wTabla")
		hiddenSeccion.setAttribute("value","")
		divComentarios.appendChild(hiddenSeccion)

		var comentario=document.createElement("textarea")
		comentario.setAttribute("name","wComentario")
		comentario.setAttribute("id","comentarios")
		divComentarios.appendChild(comentario)


		var botonEnvio=document.createElement("a")
		botonEnvio.setAttribute("href","javascript:enviarComentario()")
		botonEnvio.setAttribute("id","enviar")
		botonEnvio.setAttribute("onfocus","this.blur();")
		divComentarios.appendChild(botonEnvio)

		Element.setInnerHTML(botonEnvio,literalEnvio)

		var objBottomNavCloseLink = document.createElement("a");
		objBottomNavCloseLink.setAttribute('id','bottomNavClose');
		objBottomNavCloseLink.setAttribute('href','#');
		objBottomNavCloseLink.setAttribute('onfocus','this.blur();')
		objBottomNavCloseLink.borrar=true
		objBottomNavCloseLink.onclick = function() {
				myLightbox.end(this.borrar,this.zIndexCapaSombra); 
			return false; }
		objBottomNav.appendChild(objBottomNavCloseLink);

		var objBottomNavCloseImage = document.createElement("img");
		objBottomNavCloseImage.setAttribute('src', fileBottomNavCloseImage);
		objBottomNavCloseLink.appendChild(objBottomNavCloseImage);
	},

	//
	//	start()
	//	Display overlay and lightbox. If image is part of a set, add siblings to imageArray.
	//
	start: function(imageLink) {
		gBoo_mostrarAlbum=true;
		if(!$('lightbox')){
			initialize();
		}

		zIndexCapaSombra=Element.getStyle($('sombreado'),'z-index')
		nuevoZIndex=new Number(zIndexCapaSombra)+100
		$('sombreado').setStyle({zIndex:nuevoZIndex});
		$('lightbox').setStyle({zIndex:nuevoZIndex+1});
		$('carousel_div').setStyle({zIndex:nuevoZIndex+1});
		
		if(Element.visible('sombreado')){
			$('bottomNavClose').borrar=false
			$('bottomNavClose').zIndexCapaSombra=zIndexCapaSombra
			$('loadingLink').borrar=false
			$('loadingLink').zIndexCapaSombra=zIndexCapaSombra
			
			
		}else{
			$('bottomNavClose').borrar=true
			$('loadingLink').borrar=true
		}
		
		if ($('header'))
		{
			//Element.scrollTo('header');
		}
		
		hideSelectBoxes();
		// stretch overlay to fill page and fade in
		var arrayPageSize = getPageSize();
		Element.setHeight('sombreado', arrayPageSize[1]);
		new Effect.Appear('sombreado', { duration: 0.2, from: 0.0, to: 0.5 });
		imageArray = [];
		imageNum = 0;
		//titulo="";
		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName('a');

		// if image is NOT part of a set..
		if((imageLink.getAttribute('rel') == 'pegatinas')){
			// add single image to imageArray
			imageArray.push(new Array(imageLink.getAttribute('href'), imageLink.getAttribute('title')));
		} else {
		// if image is part of a set..
			// loop through anchors, find other images in set, and add them to imageArray
			for (var i=0; i<anchors.length; i++){
				var anchor = anchors[i];
				if (anchor.getAttribute('href') && (anchor.getAttribute('rel') == imageLink.getAttribute('rel'))){
					imageArray.push(new Array(anchor.getAttribute('href'), anchor.getAttribute('title')));
					//titulo=anchor.getAttribute('title');

				}
			}

			imageArray.removeDuplicates();
			while(imageArray[imageNum][0] != imageLink.getAttribute('href')) { imageNum++;}
		}

		// calculate top offset for the lightbox and display
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15);

		Element.setTop('lightbox', lightboxTop+50);
		Element.setTop('carousel_div', lightboxTop-30);
		Element.show('lightbox');

		this.changeImage(imageNum);
	},

	//
	//	changeImage()
	//	Hide most elements and preload image in preparation for resizing image container.
	//
	changeImage: function(imageNum) {

		activeImage = imageNum;	// update global var

		// hide elements during transition
		Element.show('loading');
		Element.hide('lightboxImage');
		Element.hide('hoverNav');
		Element.hide('prevLink');
		Element.hide('nextLink');
		Element.hide('imageData');
		Element.hide('numberDisplay');
		Element.hide('formuComentarios');

		imgPreloader = new Image();

		// once image is preloaded, resize image container
		imgPreloader.onload=function(){
			Element.setSrc('lightboxImage', imageArray[activeImage][0]);
			myLightbox.resizeImageContainer(imgPreloader.width, imgPreloader.height);
		}
		imgPreloader.src = imageArray[activeImage][0];
	},

	//
	//	resizeImageContainer()
	//
	resizeImageContainer: function( imgWidth, imgHeight) {

		// get current height and width
		this.wCur = Element.getWidth('imageContainer');
		this.hCur = Element.getHeight('imageContainer');

		// scalars based on change from old to new
		this.xScale = (imgWidth / this.wCur) * 100;
		this.yScale = (imgHeight / this.hCur) * 100;

		// calculate size difference between new and old image, and resize if necessary
		wDiff = (this.wCur - borderSize * 2) - imgWidth;
		hDiff = (this.hCur - borderSize * 2) - imgHeight;
		if(!( hDiff == 0)){ new Effect.Scale('imageContainer', this.yScale, {scaleX: false, duration: 0.6, queue: 'front'}); }
		if(!( wDiff == 0)){ new Effect.Scale('imageContainer', this.xScale, {scaleY: false, delay: 0.6, duration: 0.6}); }

		// if new and old image are same size and no scaling transition is necessary,
		// do a quick pause to prevent image flicker.
		if((hDiff == 0) && (wDiff == 0)){
			if (navigator.appVersion.indexOf("MSIE")!=-1){ pause(250); } else { pause(100);}
		}

		Element.setHeight('prevLink', imgHeight);
		Element.setHeight('nextLink', imgHeight);
		Element.setWidth( 'imageData', imgWidth);

		this.showImage();
	},

	//
	//	showImage()
	//	Display image and begin preloading neighbors.
	//
	showImage: function(){
		Element.hide('loading');
		new Effect.Appear('lightboxImage', { duration: 0.5, queue: 'end', afterFinish: function(){	myLightbox.updateDetails(); } });
		this.preloadNeighborImages();
	},

	//
	//	updateDetails()
	//	Display caption, image number, and bottom nav.
	//
	updateDetails: function() {

		Element.show('carousel_div')
		if(gBoo_mostrarAlbum){
			gBoo_mostrarAlbum=false;
			this.crearElementosCarrusel(imageArray,imageNum)
		}
		Element.show('caption');
		textoCaption=imageArray[activeImage][1].split("#");
		contenidoCaption="<p>"+textoCaption[0]+"</p>"
		$('abrirForment').regid=textoCaption[1]
		$('abrirForment').paginacion=textoCaption[2]
		
		
		if (textoCaption.length==2)
		{
			Element.hide('formuComentarios')
			Element.hide('comentarios')
			Element.hide('verComentarios')
			Element.hide('abrirForment')
		}
		if (textoCaption.length==4)
		{
			contenidoCaption="<p>"+textoCaption[0]+"</p>"
			$('idHiden').value=textoCaption[1];
			$('seccion').value=textoCaption[2];
			$('verComentarios').onclick=function ()
			{
				cargaListaComentariosFoto(textoCaption[1],203)
			}
		}
		if (textoCaption.length>5)
		{
			contenidoCaption="<p>";
			for (i=0;i<8;i++)
			{
				if ((i % 2)>0)
				{
					contenidoCaption+=textoCaption[i]+"</p>"
				} else {
					contenidoCaption+="<p><span class=\"label\">"+textoCaption[i]+"</span>";
				}
			}


			$('idHiden').value=textoCaption[8];
			$('seccion').value=textoCaption[9];
			$('verComentarios').onclick=function ()
			{
				cargaListaComentarios('verComentariosPegatina.shtml?wId='+textoCaption[8])
			}
		}

		// if imaeis part of set display 'Image x of x')
		if(imageArray.length > 1){
			Element.show('numberDisplay');
			//Element.setInnerHTML( 'numberDisplay', "Image " + eval(activeImage + 1) + " / " + imageArray.length);
			contenidoCaption+="<p>"+literalImagen +" "+ eval(activeImage + 1) +" "+ literalBarra +" "+ imageArray.length+"</p>"
		}
		Element.setInnerHTML( 'caption', contenidoCaption);
		new Effect.Parallel(
			[ new Effect.SlideDown( 'imageData', { sync: true, from: 0.0, to: 1.0 }),
			  new Effect.Appear('imageData', { sync: true }) ],
			{ duration: 0.65, afterFinish: function() { myLightbox.updateNav();} }
		);
	},

	//
	//	updateNav()
	//	Display appropriate previous and next hover navigation.
	//
	updateNav: function() {

		Element.show('hoverNav');

		// if not first image in set, display prev image button
		if(activeImage != 0){
			Element.show('prevLink');
			document.getElementById('prevLink').onclick = function() {
				myLightbox.changeImage(activeImage - 1);
				if(gBoo_FlechasDepCarrusel){
					carousel.scrollTo(activeImage)
				}
				return false;
			}
		}

		// if not last image in set, display next image button
		if(activeImage != (imageArray.length - 1)){
			Element.show('nextLink');
			document.getElementById('nextLink').onclick = function() {
				myLightbox.changeImage(activeImage + 1);
				if(gBoo_FlechasDepCarrusel){
					carousel.scrollTo(activeImage)
				}

				return false;
			}
		}
		
		reAjustarCapaSombra()
	},

	//
	//	preloadNeighborImages()
	//	Preload previous and next images.
	//
	preloadNeighborImages: function(){

		if((imageArray.length - 1) > activeImage){
			preloadNextImage = new Image();
			preloadNextImage.src = imageArray[activeImage + 1][0];
		}
		if(activeImage > 0){
			preloadPrevImage = new Image();
			preloadPrevImage.src = imageArray[activeImage - 1][0];
		}

	},

	//
	//	end()
	//
	muestraForm:function ()
	{
		Element.show('formuComentarios');
	},
	end: function(borrar,zIndex) {
		if ($('lightbox')){
			Element.hide('lightbox');
		}
		
		if ($('carousel_div')){
			Element.hide('carousel_div');
		}
		
		if(borrar){
			new Effect.Fade('sombreado', { duration: 0.2});
			showSelectBoxes();
		}else{
			$('sombreado').setStyle({zIndex:zIndex});
		}
	},
	
	crearCarrusel: function(gObj_CapaPadre) {
	/*
	Nombre:crearCarrusel
	Versión:1.0
	Fecha:7/5/7
	Autor:Gaizka Anton
	Entrada:
		gObj_CapaPadre(obj)=Referencia de la capa donde hay que situar el carrusel.
	
	Salida:NO HAY PARAMETROS DE SALIDA
	Descripción:Este metodo crea los nodos HTML para constuir el carrusel.
	
	La estructura a crear es la que sigue:
	<div class="carousel_div">
		<div class="wrapper" id="wrapper_carousel">
			<div id="prev-arrow-container">
				<img id="prev-arrow" src="http://prototype-carousel.xilinus.com/images/left3-disabled.gif?1163492051" />
			</div>
			<div class="carousel-component" id="html-carousel">
				<div class="carousel-clip-region">
					<ul class="carousel-list">
						<li>
							<img alt="Image1" class="thumb" src="http://prototype-carousel.xilinus.com/images/image1.png?1163492051" />Image 1
						</li>
					</ul>
				</div>
			</div>
			<div id="next-arrow-container">
				<img id="next-arrow" src="http://prototype-carousel.xilinus.com/images/right3-enabled.gif?1163492051" />
			</div>
		</div>
	</div>
	*/	
		//Si no esta creado		
		if(!$('carousel_div')){
		//Creación del container
			gObj_ContDiv=crearNodo('div',gObj_CapaPadre,'carousel_div')
			
			gObj_Contenedor=crearNodo('div',gObj_ContDiv,'wrapper_carousel')
			Element.addClassName(gObj_Contenedor,'wrapper')
	
			//Definicion de la 'flechita' de pagina anterior
			gObj_Pre=crearNodo('div',gObj_Contenedor,'prev-arrow-container')
			
			gObj_ImgPre=crearNodo('img',gObj_Pre,'prev-arrow')
			
			//Definicion del cuerpo propio del carrusel
			gObj_CarPeque=crearNodo('div',gObj_Contenedor,'html-carousel')
			Element.addClassName(gObj_CarPeque,'carousel-component')

			gObj_CarRegion=crearNodo('div',gObj_CarPeque,'html-carousel-clip-region')
			Element.addClassName(gObj_CarRegion,'carousel-clip-region')

			gObj_CarLista=crearNodo('ul',gObj_CarRegion,'listaCarrusel')
			Element.addClassName(gObj_CarLista,'carousel-list')
			
			//Definicion de la 'flechita' de pagina siguiente
			gObj_Next=crearNodo('div',gObj_Contenedor,'next-arrow-container')
			
			gObj_ImgNext=crearNodo('img',gObj_Next,'next-arrow')
			
			buttonStateHandler('prev-arrow', false) 
			buttonStateHandler('next-arrow-container', true) 
			
			Element.hide('carousel_div')
		}
		//Element.setHeight()
	},
	
	crearElementosCarrusel: function(gObj_ImageArray,gNum_ImageNum) {
	/*
	Nombre:crearElementosCarrusel
	Versión:1.0
	Fecha:7/5/7
	Autor:Gaizka Anton
	Entrada:
		gObj_ImageArray(array)=Array con los paths de las imágenes que intervienen en el carrusel
		gNum_ImageNum(int)= numero de la imagen que se esta mostrando para posicionar el carrusel
		
	Salida:NO HAY PARAMETROS DE SALIDA
	Descripción:Este metodo se invoca despúes de que el objeto lightbox haya obtenido todo el set de fotos.
	Este metodo creará los nodos correspondientes al carrusel, así como su inicialización
	*/	

	//obtenemos la lista donde irán las imagenes
	
		gObj_listaCarrusel=$('listaCarrusel');
		gObj_listaCarrusel.innerHTML=""//Borrar la lista
		anchoFoto=0
		for(var i=0;i<gObj_ImageArray.length;i++){
			//Creamos El elemento (Li)
			gObj_li=crearNodo('li',gObj_listaCarrusel)
			
			//Creamos la imagen thumbnail (img)
			gObj_img=crearNodo('img',gObj_li)
			gObj_img.setAttribute('src',gObj_ImageArray[i][0])//El Src esta en el primer nodo del array
			gObj_img.setAttribute('class','thumb')
			gObj_img.numImage=i
			gObj_img.onclick=function(){
				myLightbox.changeImage(this.numImage);
				return false;
			}
			if(i==0){
				anchoFoto=gObj_li.offsetWidth
			}
		}//Fin de bucle
		//alert(anchoFoto)
		//$('tracer').value=$('carousel_div').innerHTML
		if(carousel!=null){
			carousel.scrollTo(0)
			carousel.destroy()
		}
		Element.show('prev-arrow-container');
		Element.show('next-arrow-container');
		carousel = new Carousel('html-carousel',{animHandler:animHandler,animParameters:{duration:0.5},buttonStateHandler:buttonStateHandler,nextElementID:'next-arrow',prevElementID:'prev-arrow',size:gObj_ImageArray.length,scrollInc:6})
		gNum_AnchoFlechaPrev=Element.getWidth('prev-arrow-container');
		gNum_AnchoFlechaNext=Element.getWidth('next-arrow-container');
		gNum_AnchoCarrusel=Element.getWidth('html-carousel');

		Element.setWidth('html-carousel',1)
		if(anchoIniCarrusel==0){
			anchoIniCarrusel=Element.getWidth('wrapper_carousel')
		}

		Element.setWidth('wrapper_carousel',anchoIniCarrusel)
		
		gNum_AnchoContCarrusel=Element.getWidth('wrapper_carousel');
		gBoo_FlechasDepCarrusel=true
		totalTamano=anchoFoto*gObj_ImageArray.length
		if(gNum_AnchoContCarrusel>totalTamano){
			gNum_AnchoContCarrusel=totalTamano+5
			Element.hide('prev-arrow-container');
			Element.hide('next-arrow-container');
			gNum_AnchoFlechaPrev=0
			gNum_AnchoFlechaNext=0
			gBoo_FlechasDepCarrusel=false
		}
		gNum_AnchoFinalCarrusel=gNum_AnchoContCarrusel-gNum_AnchoFlechaPrev-gNum_AnchoFlechaNext-5
		new Effect.Scale('html-carousel', gNum_AnchoFinalCarrusel* 100, {scaleY: false, delay: 0.6, duration: 0.6});
		gNum_AnchoContCarrusel=Element.getWidth('wrapper_carousel');
		gNum_Peque=gNum_AnchoFlechaPrev+gNum_AnchoFlechaNext+2
		totalTamano+=gNum_Peque
		if(gNum_AnchoContCarrusel>totalTamano){
			gNum_AnchoContCarrusel=totalTamano
		}

		Element.setWidth('wrapper_carousel',gNum_Peque)
		if(document.all){//Explorer, no me preguntes.
			gNum_Peque=30
		}

		new Effect.Scale('wrapper_carousel', (gNum_AnchoContCarrusel / gNum_Peque) * 100, {scaleY: false, delay: 0.6, duration: 0.6});
	}
}

// -----------------------------------------------------------------------------------

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------

//
// getKey(key)
// Gets keycode. If 'x' is pressed then it hides the lightbox.
//
function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();

	if(key == 'x'){ hideLightbox(); }
}

// -----------------------------------------------------------------------------------

//
// listenKey()
//
function listenKey () {	document.onkeypress = getKey; }

// ---------------------------------------------------

function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
	if(!window.document.altaEuskoLink){
		flashes=$$(".flashOculto")
		for (i = 0; i != flashes.length; i++) {
			flashes[i].style.visibility = "visible";
		}
		if ($('ventana'))
		{
		} else {
			if ($('flash'))
			{
				Element.show($('flash'));
			}
		}
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
	
	flashes=$$(".flashOculto");
	for (i = 0; i != flashes.length; i++) {
		flashes[i].style.visibility = "hidden";
	}
	if ($('flash'))
	{
		Element.hide($('flash'));
	}



}

// ---------------------------------------------------

//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
//
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

// ---------------------------------------------------

//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}

function crearNodo(tipoNodo,nodoPadre) {
	/*
	Nombre:crearNodo
	Versión:1.0
	Fecha:7/5/7
	Autor:Gaizka Anton
	Entrada:
		tipoNodo(str)=Aqui se recoje el nodo HTML a crear (img,a, div...).
		nodoPadre(obj)=Aqui se recoje la referencia al nodo que contendra el nuevo elemento creado.
		arguments(2)(str)=Tercer Parametro opcional, que me indica el id del nuevo nodo.
		
	Salida:
		nuevoNodo(obj)=La función devuelve un objeto con referencia al nodo recien creado
		
	Descripción:La finalidad de este metodo no es otra que agilizar la visión del codigo para crear nodos HTML.
	*/	

	var nuevoNodo = document.createElement(tipoNodo);
		
	//Si se pasa tercer parámetro, este será el ID del nuevo nodo
	if(arguments.length>2){
		nuevoNodo.setAttribute('id',arguments[2]);
	}
		
	nodoPadre.appendChild(nuevoNodo);
		
	return nuevoNodo;
}

/*FUNCIONES PARA EL CARRUSEL*/
 function buttonStateHandler(button, enabled){
 if (button == "prev-arrow")
   $('prev-arrow').src = enabled ? "/images/left3-enabled.gif" : "/images/left3-disabled.gif"
 else
   $('next-arrow').src = enabled ? "/images/right3-enabled.gif" : "/images/right3-disabled.gif"
}

function animHandler(carouselID, status, direction) {
  var region = $(carouselID).down(".carousel-clip-region")
  if (status == "before") {
    Effect.Fade(region, {to: 0.3, queue: { position:'end', scope: "carousel" }, duration: 0.2})
  }
  if (status == "after") {
    Effect.Fade(region, {to: 1, queue: { position:'end', scope: "carousel" }, duration: 0.2})
  }
}


// ---------------------------------------------------

function initLightbox() { myLightbox = new lightbox(); myLightbox.initialize()}

addLoadEvent(initLightbox);	// run initLightbox onLoad
