function Galerias(aImagenesStr, aCaptionsStr, aLinks, eventoInit, eventoReload )
{
   this.pagactual = 0;
   this.length = aImagenesStr.length ;
   this.aRelImagenes = new Array;
   this.cfgmaxpaginacion = 8;

   //registra funciones de callback de inicio y recarga
   this.eventoReload = eventoReload;   
   this.eventoInit   = eventoInit;
   
   //precarga imagenes en Image
   for ( var i = 0; i < aImagenesStr.length; i++ ) {   	
	    var oImage = new Image;
    	oImage.src = aImagenesStr[i];
    	this.aRelImagenes.push(oImage);   
   }
   this.aRelCaptions = aCaptionsStr;
   this.aRelLinks = aLinks;
   this.eventoInit(this);
}

Galerias.prototype.reload = function()
{
	//funcion callback para actualizacion de HTML
	this.eventoReload(this);	
}

Galerias.prototype.start = function() {
	running = true;
	setTimeout("play()",duration*1000);
}

Galerias.prototype.play = function() {

}

Galerias.prototype.stop = function() {
	running = false;
}

Galerias.prototype.gotoSig = function()
{

	if (this.pagactual<(Math.ceil(this.length / this.cfgmaxpaginacion  ))-1 ){
		this.pagactual++ ;	
	}	else {
		this.pagactual=0;
	}

	this.reload();
}

Galerias.prototype.gotoAnt = function()
{
	if (this.pagactual>0 ){
		this.pagactual-- ;	
	}	else {
		this.pagactual = (Math.ceil( this.length / this.cfgmaxpaginacion  )-1);	
	}
	
	this.reload();
}

// paginacion
Galerias.prototype.pintaThumbs = function() {
	// maximo del indice de paginacion 
	texto ="";	
	
	var offset = 1;
	
	var relLinkPath = document.getElementById("_galerias-relacionadas-link");
	if (typeof relLinkPath != "undefined") {
		if (this.aRelLinks[0] != curObjPath) {
			relLinkPath.setAttribute("href", curSectionPath);
			offset = 0;
		} else {
			relLinkPath.setAttribute("href", curObjPath);
		} 
	}

	var minPaginacion =  (this.pagactual)* this.cfgmaxpaginacion + offset;
	
	var maxPaginacion = (this.pagactual+1)* this.cfgmaxpaginacion + offset;	

	if (maxPaginacion > this.length ) {		
		var maxPaginacion = this.length ;	
	}

	for (i=minPaginacion; i < maxPaginacion; i++) {
		texto = texto +"<div class='galerias-relacionadas_fotos_galeria'>";
		texto = texto +"<a href='"+this.aRelLinks[i]+"'><img src='"+this.aRelImagenes[i].src+"' ";	
		texto = texto +" width='79' height='51' border='0' /></a> "; 			
		texto = texto +"<h4><a href='" + this.aRelLinks[i] + "'>"+this.aRelCaptions[i]+"</a> </h4></div>";
	}//for	

	return texto;
}

// paginacion
Galerias.prototype.pintaBotones = function() {

	texto ="<a href='javascript:mygalleries.gotoAnt();'><img src='../img/anterior-galeria-off.jpg' alt='Ir a Galer&iacute;a anterior' width='31' height='11' align='left' border='0'/></a> ";
	texto +="<a href='javascript:mygalleries.gotoSig();'><img src='../img/siguiente-galeria-off.jpg' alt='Ir a Galer&iacute;a siguiente' width='31' height='11' align='right' border='0'/></a>";
	texto += this.pintaInfoPaginacion(); 
	return texto;
}

Galerias.prototype.pintaInfoPaginacion = function() {

	
	var maxPaginacion = (this.pagactual+1)* this.cfgmaxpaginacion  ;	

	if (maxPaginacion > this.length ) {		
		var maxPaginacion = this.length ;	
	}

	return maxPaginacion + " galerias de "+ this.length;
}

