//*************** CONFIGURACIÓN ***************//

//***** Slides folder *****//
var _RUTA_FOTOS = "slide_fotos/";	// guarda la ruta (relativa) donde se encuentran las fotografías.
							// Por defecto, slide_fotos

String.prototype.endsWith = function(str) 
{return (this.match(str+"$")==str)}

//***** Nombre del campo imagen a utilizar, por defecto *****//
var _SLIDE_NOMBRE_IMG = "_SLIDE_NOMBRE_IMG";
var _SWF_OBJECT_ID = "_SWF_OBJECT_ID";
var _SWF_EMBED_ID = "_SWF_EMBED_ID";
var _SWF_PARAM_ID = "_SWF_EMBED_ID";

var width = 720;
var height = 540;

//***** Modos del slide *****//
var _MODO_SLIDE = "normal";	// normal - Solo previous y next
						// full_mode - Muestra todos los controles

//***** silde auto speed *****//
var _VELOCIDAD_SLIDE = 1000;	// in milliseconds

//******************* MOTOR *******************//
// constructor
function Slideshow(object_name)
{
	if(object_name == null)
	{
		this.object_name = "mySlide";
	}else{
		this.object_name = object_name;
	}
	
	this.images_list = new Array(); // the list of images
	this.position = 0; // set the current position to the first slide
	// métodos
	this.load_images = load_images;
	this.en_marcha = false;
	
	this.next = next;
	this.previous = previous;
	this.first = first;
	this.last = last;
	
	this.create_slide = create_slide;
}

// agregar imagen
// se pueden agragar varias imágenes a la vez, separadas por comas (,)
function load_images(lista)
{
	for(i = this.images_list.length; i < load_images.arguments.length; i++)
	{
		this.images_list[i] = load_images.arguments[i];
	}
}

// next image
function next()
{
	this.position++;
	if(this.position >= this.images_list.length)
	{
		this.position = 0;
	}
	loadNextImage(this.images_list, this.position );
}

function loadNextImage( images_list, position )
{
    var filename = images_list[position];
 
    if(! filename.toLowerCase().endsWith(".swf") )
    {
        document.getElementById(_SLIDE_NOMBRE_IMG).src = _RUTA_FOTOS + images_list[position];    
        document.getElementById(_SLIDE_NOMBRE_IMG).style.display = "";
        document.getElementById(_SWF_OBJECT_ID).style.display = "none";
    }
    else 
    {
       	document.getElementById(_SWF_OBJECT_ID).innerHTML = "<object width='"+width+"' height='"+height+"'><param name='movie' id='" + 
		            _SWF_PARAM_ID + "' value='" + _RUTA_FOTOS + images_list[position] + "'><embed border='0' id='" + 
	        	    _SWF_EMBED_ID + "' src='" + _RUTA_FOTOS + images_list[position] + "' width='"+width+"' height='"+height+"'></embed></object>";    

        document.getElementById(_SLIDE_NOMBRE_IMG).style.display = "none";
        document.getElementById(_SWF_OBJECT_ID).style.display = "";
    }
}

function previous()
{
	this.position--;
	if(this.position < 0)
	{
		this.position = this.images_list.length - 1;
	}
	loadNextImage(this.images_list, this.position );
}

function first()
{
	this.position = 0;
	loadNextImage(this.images_list, this.position );
}

function last()
{
	this.position = this.images_list.length - 1;
	loadNextImage(this.images_list, this.position );
}

// Create slides
// crea el slide con todos sus comportamientos
function create_slide()
{
	salida = "";
	salida = "<table border='1' cellspacing='0' cellpadding='10' align='center'>";
	salida += "<tr>";
	salida += "<td align='center' valign='middle' ";
	if( _MODO_SLIDE == "normal" )
	{
		 salida += " colspan='2'>";
	}else{
		salida += " colspan='6'>";
	}
	if(this.images_list.length == 0)
	{
		salida += "<b>:: No images defined ::</b>";
	}else{
		salida += "<img border='0' id='"+ _SLIDE_NOMBRE_IMG +"' src='" + _RUTA_FOTOS + this.images_list[this.position];
                salida += "' style='width:" + width + "px;height:" + height + "px;'>";
		salida += "<div  style='display:none' border='0' id='" + _SWF_OBJECT_ID + "'></div>";
    }
	salida += "</td>";
	if(this.images_list.length != 0)
	{
		// si hay imágenes definidas
		salida += "</tr>";
		// botón de first
		if(_MODO_SLIDE == "full_mode" )
		{
			salida += "<td align='center'>";
			salida += "<a id='first' href='#' onClick='" + this.object_name + ".first(); return false;'>:: first ::</a>";
			salida +="</td>";
		}
		// botones de previous y next
		salida += "<td align='center'>";
		salida += "<a id='previous' href='#' onClick='" + this.object_name + ".previous(); return false;'>:: previous ::</a>";
		salida += "</td>";
		salida += "<td align='center'>";
		salida += "<a id='next' href='#' onClick='" + this.object_name + ".next(); return false;'>:: next ::</a>";
		salida += "</td>";
		// botón de last
		if(_MODO_SLIDE == "full_mode" )
		{
			salida += "<td align='center'>";
			salida += "<a id='last' href='#' onClick='" + this.object_name + ".last(); return false;'>:: last ::</a>";
			salida += "</td>";
		}
		salida += "<tr>";
	}
	salida += "</table>";
	
	document.writeln(salida);
}


/***** END *****/