var estado=true;

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

	var anotherEl = $('cont');
	var noticiaElement= $('titNoticia');
	var nuevoTween = new Fx.Tween(noticiaElement,{wait: false});
	
	
	var img=$('lista2').getElements('li');
	var toIncrement = 5;
	var itemsPP = 1;
	var increment = 240;
	var maxRightIncrement =  -(increment*($('lista2').getChildren('li').length / itemsPP) - increment)+5;

	
	$('titulo').addEvent('click', function(e) {
		    e.stop();
		  if(estado)
		      {  $('principal').fade('out');
		      		$('iphonecompatiblelogo').fade('out');
			 $('ruta').fade('out');
			  var noticias= function(){
				 anotherEl.morph('.noticiasOpen');
				 nuevoTween.start('left','-10px');
				 $('titulo').set('html','<b>X</b>');
				 $('novedad').fade('hide');
				 $('linea').fade('hide');
				 $('linea2').fade('hide');
				 estado=false;
			  };
			  noticias.delay(400);
			  
			  if(toIncrement==5){$('botonizqNoticias').fade('hide');}
			  if(toIncrement<5){$('botonizqNoticias').fade('in');}
			  
			
		  }
		    
		    else {
			  anotherEl.morph('.noticiasClose');
			  nuevoTween.start('left','402px');
			  $('titulo').set('html','+ info');
			  $('novedad').fade('in');
			  $('linea').fade('in');
			  $('linea2').fade('in');
			  estado=true;
			  var retrasar= function(){$('principal').fade('in');$('iphonecompatiblelogo').fade('in');$('ruta').fade('in');};
			  retrasar.delay(400);
			 
			 }

	});


	
	
	var fx = new Fx.Tween('lista2', {
		property: 'left',
		duration: 1000,
		transition: Fx.Transitions.Back.easeInOut,
		wait: false
		});

	if(img.length>3){
		$('botonizqNoticias').addEvent('click', function(event){ 
		    event = new Event(event);
			if(!$('antNoticias').hasClass('deactivated')) {
				event.stop();
			   if(toIncrement<5){
				event.stop();
						toIncrement = toIncrement+increment;
						fx.start(toIncrement);
					    	$('nextNoticias').erase('class');
						if(toIncrement>=0)
					        $('antNoticias').set('class', 'deactivated');
				}
				if (toIncrement-increment>=maxRightIncrement){
					$('botondrchNoticias').fade('in');
		    	} 
		    	if(toIncrement==5){$('botonizqNoticias').fade('out');}
						
			}	
		   }		  	  
	        .bind(this));
	
	
		$('botondrchNoticias').addEvent('click', function(event){ 
			event = new Event(event);
			if(!$('botondrchNoticias').hasClass('deactivated')) {
					event.stop();
				if(toIncrement>maxRightIncrement){
					event.stop();
					toIncrement = toIncrement-increment;
					fx.start(toIncrement);
					$('antNoticias').erase('class');
					if(toIncrement<=maxRightIncrement)
			                $('nextNoticias').set('class', 'deactivated');
				}
				if (toIncrement-increment<maxRightIncrement){
					$('botondrchNoticias').fade('out');
		    	}
		    	if(toIncrement<5){$('botonizqNoticias').fade('in');}
			}	
		}	  		  
		.bind(this));

	}
	
	else {	$('nextNoticias').fade('hide');
			$('nextNoticias').set('class', 'deactivated');
	      $('antNoticias').set('class', 'deactivated');}
	


    

	
});





