﻿
/***********************************************
* Scrollable Menu Links-  Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use
***********************************************/


function DynamicGalery()
{
	
	//configure path for left and right arrows
	var goLeftImage = '';
	var goRightImage = '';
	var goLeftImageOn = '';
	var goRightImageOn = '';
	
	var menuwidth;		//configure menu width (in px):
	var menuheight;		//configure menu height (in px):
	var arrowswidth;
	var totalwidth;
	
	var scrolldir = "";	//Specify scroll buttons directions ("normal" or "reverse"):
	var scrollspeed;	//configure scroll speed (1-10), where larger is faster
		
	//specify menu content
	var lista_imagen = '';
	var menucontents = '';

	var obj_reference = '';

	var cross_scroll, ns_scroll
	
	var actualwidth = ''		
	var loadedyes

	var righttime
	var lefttime
	
	var iedom = document.all||document.getElementById;
	var leftdircode = '';
	var rightdircode = '';
	
	var LayerIdWithImagesHidden;
	
	var bVarsInitialized;
	
	this.setConfiguration = function (leftArrowImg, leftArrowImgOn, rightArrowImg, rightArrowImgOn, menuWidth, arrowsWidth, height)
	{
		this.goLeftImage  = leftArrowImg;
		this.goLeftImageOn  = leftArrowImgOn;
		this.goRightImage  = rightArrowImg;
		this.goRightImageOn  = rightArrowImgOn;
		this.menuwidth  = menuWidth;
		this.arrowswidth  = arrowsWidth;
		this.menuheight  = height;
		this.bVarsInitialized = true;
	}
	
	this.initConfigVars = function ()
	{
		this.goLeftImage  = 'skin/images/flecha_izquierda_galeria.gif';
		this.goLeftImageOn  = 'skin/images/flecha_izquierda_galeria_on.gif';
		this.goRightImage  = 'skin/images/flecha_derecha_galeria.gif';
		this.goRightImageOn  = 'skin/images/flecha_derecha_galeria_on.gif';
		this.menuwidth  = 520;
		this.arrowswidth  = 20;
		this.menuheight  = 80;
	}
	
	this.initClassVars = function ()
	{
		this.scrolldir  = "normal";
		this.scrollspeed  = 10;
		this.loadedyes = 0;
		this.leftdircode='onMouseover="' + this.obj_reference + '.moveright()" onMouseout="clearTimeout(' + this.obj_reference + '.righttime)"';
		this.rightdircode='onMouseover="' + this.obj_reference + '.moveleft()" onMouseout="clearTimeout(' + this.obj_reference + '.lefttime)"';
		this.totalwidth = this.menuwidth + this.arrowswidth + this.arrowswidth + 1;
	}
	
	/*	Funcion para pegar el cambiazo	*/
	this.changeImg = function (imgName, imgPath, descLayer, descItemLayer)
	{
		oImage = eval('document.forms[0].' + imgName);
		oImage.src = imgPath;
		document.getElementById(descLayer).innerHTML=document.getElementById(descItemLayer).innerHTML;
	}
	
	this.getImagesFromHiddenLayer = function (idLayer)
	{
		this.LayerIdWithImagesHidden = idLayer;
		var anchors = document.getElementById(idLayer);
		this.menucontents = '<nobr>' + anchors.innerHTML + '</nobr>';
		//alert(this.menucontents);
	}
	
	this.init = function ()
	{
		document.getElementById('previo_carga').style.display='none';
		document.getElementById('galeria_desliza').style.display='inline';
	}

	/*
		NOOOO - Rellena la capa 'test2' que se genera en el metodo 'load' con las imagenes que recogemos del div oculto, asignandolas a la variable 'menucontents'
	*/
	this.fillup = function ()
	{
		this.loadedyes=0;
		if (iedom)
		{
			this.cross_scroll=document.getElementById ? document.getElementById("test2") : document.all.test2
			this.cross_scroll.innerHTML = this.menucontents
			//this.actualwidth = document.all ? this.cross_scroll.offsetWidth : document.getElementById("temp").offsetWidth
			//this.actualwidth = document.all ? this.cross_scroll.offsetWidth : document.getElementById(this.LayerIdWithImagesHidden).offsetWidth
			this.actualwidth = this.cross_scroll.offsetWidth;
			//alert(this.actualwidth);
		}
		else if (document.layers)
		{
			this.ns_scroll=document.ns_scrollmenu.document.ns_scrollmenu2
			this.ns_scroll.document.write(menucontents)
			this.ns_scroll.document.close()
			this.actualwidth = this.ns_scroll.document.width
		}
		document.getElementById(this.LayerIdWithImagesHidden).innerHTML = '';
		this.loadedyes=1;
		//var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
		//if (!isIE) this.actualwidth = 3000;
		//alert(this.actualwidth);
	}
	
	this.load = function ()
	{
		if (bVarsInitialized != true) this.initConfigVars(); // Si no se ha configurado la galería, usamos la conf. por defecto
		this.initClassVars();
	
		if (this.scrolldir == "reverse")
		{
			var tempswap = this.leftdircode;
			this.leftdircode = this.rightdircode;
			this.rightdircode = tempswap;
		}
		
		/*if (iedom)
			document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100;left:-5000">'+
				this.menucontents+'</span>')
		*/		
		if (iedom||document.layers){
			with (document){
				write('<TABLE width=' + this.totalwidth + ' align="center" cellpadding=5 cellspacing="0" id="galeria_desliza" style="display:none"> ')
				write('<TR><TD align="center">&nbsp;</TD>')
/*poner class*/		//write('<TD id="galeria_desliza_top" style="background:url(skin/images/fondo_galeria_top.gif) bottom left repeat-x"></TD>')
				write('<TD id="galeria_desliza_top"></TD>')
				write('<TD align="center">&nbsp;</TD></TR>')
				write('<TR ><TD width=' + this.arrowswidth + ' align="center"><a href="#" '+this.leftdircode+'><img src="'+this.goLeftImage+'"border=0 onmouseout="this.src=\''+this.goLeftImage+'\'" onmouseover="this.src=\''+this.goLeftImageOn+'\'"></a> </td>')
				write('<TD id=navega_galeria width="'+this.menuwidth+'px">')  
				/*Cambiado de 30 a 10 para que no corte la última foto
				var aux = this.menuwidth - 30;*/
				var aux = this.menuwidth - 10;
				aux += "";
				if (iedom){
					write('<div style="position:relative;width:'+aux+'px;height:'+this.menuheight+'px;overflow:hidden; *margin-right: 7px;">')
					write('<div id="test2" style="position:absolute;left:0;top:0">')
					write('</div></div>')
				}
				else if (document.layers){
					write('<ilayer width='+this.menuwidth+' height='+this.menuheight+' name="ns_scrollmenu">')
					write('<layer name="ns_scrollmenu2" left=0 top=0></layer></ilayer>')
				}
				write('</td>')
				write('<TD width=' + this.arrowswidth + ' align="center"> <a href="#" '+this.rightdircode+'>')
				write('<img src="'+this.goRightImage+'"border=0 onmouseout="this.src=\''+this.goRightImage+'\'" onmouseover="this.src=\''+this.goRightImageOn+'\'"></a>')
				write('</td></tr>')
				write('<TR><TD align="center">&nbsp;</TD>')
/*poner class*/		//write('<TD id="galeria_desliza_bottom" style="background:url(skin/images/fondo_galeria_bottom.gif) top left repeat-x"></TD>')
				write('<TD id="galeria_desliza_bottom"></TD>')
				write('<TD align="center">&nbsp;</TD></TR></table>')
			}
		}
	}
	
	
	this.moveleft = function ()
	{
		var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
		//alert(isIE);
		if (this.loadedyes==1)
		{
			//alert(iedom);
			//alert(this.cross_scroll.style.left);
			//alert(this.menuwidth);
			//alert(this.actualwidth);
			//if (!isIE) this.menuwidth = 200;
			//alert("despues "+this.menuwidth);
			//this.actualwidth=654;
			//alert(this.actualwidth);
			if (iedom && parseInt(this.cross_scroll.style.left) > (this.menuwidth-this.actualwidth))
			{
				this.cross_scroll.style.left = parseInt(this.cross_scroll.style.left)-this.scrollspeed+"px"
			}
			else if (document.layers && this.ns_scroll.left > (this.menuwidth-this.actualwidth))
			{
				this.ns_scroll.left -= this.scrollspeed
			}
		}
		this.lefttime = setTimeout(this.obj_reference + ".moveleft()",50);
	}
	
	this.moveright = function (){
		if (this.loadedyes){ //alert('reger');
			if (iedom && parseInt(this.cross_scroll.style.left)<0)
				this.cross_scroll.style.left = parseInt(this.cross_scroll.style.left)+this.scrollspeed+"px"
			else if (document.layers && this.ns_scroll.left < 0)
				this.ns_scroll.left += this.scrollspeed
		}
		//this.righttime=setTimeout("this.moveright()",50);
		this.righttime=setTimeout(this.obj_reference + ".moveright()",50);
	}

}