/**
 * @author allkom
 * 
 * Manejo de ImageSlider
 */

imageSliderC = function(){
	
	this.id = 0;
	
	this.addNew = function( image, epigrafe, url ){
		
		pos = this.imageData.length;
		
		this.imageData[pos] = new Array();
		this.imageData[pos]['image'] = image;
		this.imageData[pos]['epigrafe'] = epigrafe;
		this.imageData[pos]['url'] = url;
			
	}
	
	this.change = function( pos ){
	
		if( pos == "next" ){
			if( this.imageData.length > this.imageCounter + 1 ){
				//si es menor, lo mostramos
				this.imageCounter++;
			}else{
				//dio al vuelta entera, vuelve a 0
				this.imageCounter = 0;
			}
		} else {
			if( this.imageCounter - 1 >= 0 ){
				//si es mayor o igual a 0, lo seteamos
				this.imageCounter--;
			}else{
				//dio la vuelta entera, vuelve al final
				this.imageCounter = this.imageData.length - 1;
			}
		}
		
		//Seteamos los datos a la vista
		$( 'imgSlider' + this.id ).src = this.imageData[this.imageCounter]['image'];
		//$('imgSlider').alt = this.imageData[this.imageCounter]['epigrafe'];
		$( 'txtFotos' + this.id ).update( this.imageData[this.imageCounter]['epigrafe'] );
		if( $( 'imgLink' + this.id ) != null ) {			
			$( 'imgLink' + this.id ).href =  this.imageData[this.imageCounter]['url'];
		}
	}
	
	this.imageCounter = 0;
	this.imageData = new Array();
}

function init_imageSlider( id ) {
	eval('imageSlider' + id + ' = new imageSliderC()');
	eval('imageSlider' + id + '.id = id');
	Event.observe( window, 'load', function(){
		if( $('imgNext'+id) != null ) {
			Event.observe( 'imgNext'+id, 'click', function(){
				eval('imageSlider'+id+'.change( \'next\' )');
			});
		}
		if( $('imgPrev'+id) != null ){
			Event.observe( 'imgPrev'+id, 'click', function(){
				eval('imageSlider'+id+'.change( \'prev\' )');
			});
		}
	});
}