var pos = 0;
var numfotos = 0;
var imagenes = new Array ();
var timer;

function slideinfo ()
{
	this.foto = "";
	this.html = "";
	this.link = "";
	this.timeout = "";
}

function slideshow ( data )
{
	pos = 0;

	var div = document.getElementById ("thumbnails");

	html = "";

	for ( var i = 0; i < data.length; i++ )
	{
		var clase = "";

			clase = "slideshow-thumbnails-active";

		html += "";
		html += "<a href='javascript:mostrar ( " + i + " )' class='" + clase + "' id='linkfoto" + i + "'> <!-- <img src='http://www.magicfantasy.es/images/" + data [i].foto + ".jpg' width='50' height='40' border=0 style='padding-left:1px;' /> --></a>";
		html += "";
	}

	html += "";

	numfotos = data.length;
	imagenes = data;
	div.innerHTML = html;

	if ( data [0].html != "" )
		document.getElementById ("fotodiv").innerHTML = data [0].html;
	else
		document.getElementById ("fotodiv").innerHTML = "<img src='http://www.magicfantasy.es/images/" + data [0].foto + ".jpg' border=0>";

	if ( timer )
		clearTimeout ( timer );

	if ( data [0].timeout != "" )
		timer = setTimeout ( adelante, data [0].timeout );
	else
		timer = setTimeout ( adelante, 40 );		
}

function adelante ()
{
	if ( timer )
		clearTimeout ( timer );
	
	if ( pos < numfotos - 1 )
		pos++;
	else
		pos = 0;

	for ( var i = 0; i < numfotos; i++ )
		document.getElementById ("linkfoto" + i).className = "slideshow-thumbnails-inactive";
		
	document.getElementById ("linkfoto" + pos).className = "slideshow-thumbnails-active";
	if ( imagenes [pos].html != "" )
		document.getElementById ("fotodiv").innerHTML = imagenes [pos].html;
	else
	{
		document.getElementById ("fotodiv").innerHTML = "<a href='" + imagenes [pos].link + "'><img src='http://www.magicfantasy.es/images/" + imagenes [pos].foto + ".jpg' border=0></a>";	
	}

	if ( imagenes [pos].timeout != "" )
		timer = setTimeout ( adelante, imagenes [pos].timeout );
	else
		timer = setTimeout ( adelante, 4000 );
}

function atras ()
{
	if ( timer )
		clearTimeout ( timer );
	
	if ( pos > 0 )
		pos--;
	else
		pos = numfotos - 1;

	for ( var i = 0; i < numfotos; i++ )
		document.getElementById ("linkfoto" + i).className = "slideshow-thumbnails-inactive";
		
	document.getElementById ("linkfoto" + pos).className = "slideshow-thumbnails-active";
	if ( imagenes [pos].html != "" )
		document.getElementById ("fotodiv").innerHTML = imagenes [pos].html;
	else
	{
		document.getElementById ("fotodiv").innerHTML = "<a href='" + imagenes [pos].link + "'><img src='http://www.magicfantasy.es/images/" + imagenes [pos].foto + ".jpg' border=0></a>";	
	}

	if ( imagenes [pos].timeout != "" )
		timer = setTimeout ( adelante, imagenes [pos].timeout );
	else
		timer = setTimeout ( adelante, 4000 );
}

function mostrar ( cual )
{
	if ( timer )
		clearTimeout ( timer );

	pos = cual;

	for ( var i = 0; i < numfotos; i++ )
		document.getElementById ("linkfoto" + i).className = "slideshow-thumbnails-inactive";
		
	document.getElementById ("linkfoto" + pos).className = "slideshow-thumbnails-active";
	if ( imagenes [pos].html != "" )
		document.getElementById ("fotodiv").innerHTML = imagenes [pos].html;
	else
	{
		document.getElementById ("fotodiv").innerHTML = "<a href='" + imagenes [pos].link + "'><img src='http://www.magicfantasy.es/images/" + imagenes [pos].foto + ".jpg' border=0></a>";
	}

	if ( imagenes [pos].timeout != "" )
		timer = setTimeout ( adelante, imagenes [pos].timeout );
	else
		timer = setTimeout ( adelante, 4000 );
}
