/*------------------------------------------------------------------------------------------------------------------------------ 
 											Funcións para o manexo de galerias sahdowbox
											By Cancrexo Xuño 2010 (cancrexo@swishmax.es)
											

	Uso:
		creaGaleria(imaxes/00.jpg_sjb_imaxes/01.jpg_sjb_imaxes/03.jpg_sjb_/imaxes/04.jpg
		iniciaGaleria(n); n ==> id da foto a amosar en 1º lugar
	
------------------------------------------------------------------------------------------------------------------------------- */

function Galeria(){
	
	// ************************************************************************ 
	// PRIVATE VARIABLES AND FUNCTIONS 
	// ONLY PRIVELEGED METHODS MAY VIEW/EDIT/INVOKE 
	// *********************************************************************** 
		var fotos = new Array(); // Array de obexctos para shadowBox


	// ************************************************************************ 
	// PRIVILEGED METHODS 
	// MAY BE INVOKED PUBLICLY AND MAY ACCESS PRIVATE ITEMS 
	// MAY NOT BE CHANGED; MAY BE REPLACED WITH PUBLIC FLAVORS 
	// ************************************************************************ 
		
		/*	Método que basicamente mete no array un obxecto tal que asín:
			player: "img",
			content: ruta deica a foto
			title: "Titulo da imaxe"
			Resibe un obxecto con:
				string coa ruta completa a cada foto separadas por _sjb_ OBLIGATORIO
				foto a amosar inicialmente (indice) OPTATIVO
				string cos titulos das fotos separados por _sjb_ OPTATIVO
		------------------------------------------------------------------------------------------------------------*/
		this.init = function (obxecto){
			
			listado 		= new Array();		
			titulos 		= new Array();
			tituloActual 	= "";
			inicial 		= 0;
			
			if(obxecto.strFotos) 	listado = obxecto.strFotos.split("_sjb_"); 		// Listado de fotos separadas por _sjb_
			if(obxecto.strTitulos) 	titulos = obxecto.strTitulos.split("_sjb_"); 	// Titulos das fotos
			if(obxecto.inicial)		inicial = parseInt(obxecto.inicial, 10);		// Indice da foto a amosar inicialmente
			
			previo = 0; // Para saber que título coller no caso de que haxa menos que fotos. Collese o último válido
			
			this.galeriaReset();
			
			tipoPlayer = 'img';
			
			for(x = 0; x < listado.length; x++){
								
				if(titulos.length > x){
					tituloActual = titulos[x];
					previo = x;
				
				}else if(titulos[previo])tituloActual = titulos[previo];
				
				miObjecto = { title: tituloActual, player: tipoPlayer, content: listado[x]};
				
				this.fotos.push(miObjecto);
				
			}
			
			// Unha vez creado o array de obxectos, arrancamos o shadowBox 
			this.arranca(inicial);
		};
		
	
		// Resetea array de fotos
		this.galeriaReset = function(){
			this.fotos = new Array();	
		}
		
		// Arranca a galeria (resibe foto a amosar inisialmente - indice)

		this.arranca = function (actual){
			actual = parseInt(actual, 10);
			Shadowbox.open(this.fotos,  {continuous: true });
			Shadowbox.change(actual)
		}

		
	// ************************************************************************ 
	// PUBLIC PROPERTIES -- ANYONE MAY READ/WRITE 
	// ************************************************************************ 
		this.ejemplo = 0;
}


	// ************************************************************************ 
	// PUBLIC METHODS -- ANYONE MAY READ/WRITE 
	// Creados fora da 'clase' e definidos con prototype
	// ************************************************************************ 
	Galeria.prototype.chachi = function(){ this.clothing="khakis and black shirt" } 

	// ************************************************************************ 
	// PROTOTYOPE PROPERTIES -- ANYONE MAY READ/WRITE (but may be overridden) 
	// ************************************************************************ 
	Galeria.prototype.nadadenada = 2;
	
	
	// ************************************************************************ 
	// STATIC PROPERTIES -- ANYONE MAY READ/WRITE 
	// ************************************************************************ 
	Galeria.nada = 0;


