/* noticias .... gestion de las noticias */
/* el objetivo es saber que noticia es la que se encuentra en este momento en el scroll de el elemento */
/* de las noticias guardaremos el id del elemento noticia */

var noticiaImp;

	  
var noticia = new Class({
        options: {
                id:'',
				tipoNoticia:0
        },
        initialize: function(options){
                this.setOptions(options);
	    },
		setId : function(id) {
			this.id = id;
		},
		getId : function () {
			return this.id;
		},
		setTipoNoticia : function(tipoNoticia) {
			this.tipoNoticia = tipoNoticia;
		},
		getTipoNoticia : function () {
			return this.tipoNoticia;
		}
		
});

        
/* el gestor de noticias se encarga de llevar la cuenta del elemento que se encuetre actualmente en la cabeza de la pila y 
   de realizar los sucesivos scrolls */		
var GestorNoticias = new Class({
        options: {
                noticias: [],
                startIndex:0,
				myFx : null
        },
        initialize: function(options){
                this.setOptions(options);
                this.noticias = [];
				this.myFx =  new Fx.Scroll($('noticiasCuerpo'));
				
        },
		
		addNoticia : function(id,tipoNoticia) {
		  var noticiaNueva = new noticia();
		  noticiaNueva.setId(id);
		  noticiaNueva.setTipoNoticia(tipoNoticia);
		  this.options.noticias.include(noticiaNueva);
		},
		nextNoticiaIndice : function (indice) {
			this.myFx.toElement('noticia' + indice);
		},	
		
		
		nextNoticia : function() {
			
			if ((this.options.startIndex + 1) == this.options.noticias.length) {
				alert('ultima noticia de la Escuela de Arte La Palma.');
			} else {
			
				// controlamos el indice
				var anterior = this.options.startIndex;
			
				this.options.startIndex += 1;
			
				if (this.options.startIndex == this.options.noticias.length) {
					this.options.startIndex = 0;
				}
		
				
				// posicionamos la capa en el elemento 
				this.myFx.toElement(this.options.noticias[this.options.startIndex].getId()).chain(function() {
					
					
					// if (this.options.noticias[this.options.startIndex].getTipoNoticia() == 1) {
					
						$('datenoticia' + this.options.startIndex).set('tween', {
									duration: 2000,
									transition: Fx.Transitions.Quad.easeOut // This could have been also 'bounce:out'
								}).tween('color', '#000');
						
						$('datenoticia' + anterior).set('tween', {
								duration: 2000,
								transition: Fx.Transitions.Quad.easeOut // This could have been also 'bounce:out'
							}).tween('color', '#fff');

					// }
				
				}.bind(this));
				
			}
			
			
		},
		previousNoticia : function() {
		 
		 	if ((this.options.startIndex) == 0) {
				alert('primera noticia de la Escuela de Arte La Palma.');
			} else {
				
				
		    	// controlamos el indice
				var anterior = this.options.startIndex;
			
				// controlamos el indice
				this.options.startIndex -= 1;
			
				if (this.options.startIndex < 0) {
					this.options.startIndex = this.options.noticias.length - 1;
				}
			
				// posicionamos la capa en el elemento 
				
				this.myFx.toElement(this.options.noticias[this.options.startIndex].getId()).chain(function() {
					
					// if (this.options.noticias[this.options.startIndex].getTipoNoticia() == 1) {
				
				    
						$('datenoticia' + anterior).set('tween', {
								duration: 2000,
								transition: Fx.Transitions.Quad.easeOut // This could have been also 'bounce:out'
							}).tween('color', '#fff');
					
						$('datenoticia' + this.options.startIndex).set('tween', {
									duration: 2000,
									transition: Fx.Transitions.Quad.easeOut // This could have been also 'bounce:out'
								}).tween('color', '#000');
						
					// }
				
				}.bind(this));
			}
		},
		abajoNoticia : function () {
			this.myFx.toBottom();
		},
		arribaNoticia : function () {
			this.myFx.toTop();
		}
		
 });
		

window.addEvent('domready', function() {

    GestorNoticias.implement(new Options, new Events);
    noticia.implement(new Options, new Events);
    noticiaImp = new GestorNoticias();
 
	/*  var myFx = new Fx.Scroll($('noticiasCuerpo')).toBottom().chain(function(){
            this.toTop.delay(1000, this);
          }).chain(
			function(){
            this.toBottom.delay(1000, this);
          }
		  ); */


	     /* var myFxScroll = new Fx.Scroll('noticiasCuerpo', {
            offset: {
				'x': 0,
				'y': 0
			}
		  });

      myFxScroll.toElement('noticia5');
	  */
  });
      
