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

	$$('.logo-team').each(function(e,i){
	
		var normal = e.getElement('.normal');
		var hover = e.getElement('.hover');
		var team = e.getParent('.team');
		
		e.addEvent('mouseenter',function(event){

			team.addClass('hover');
		
		});	
		e.addEvent('mouseleave',function(event){
		
			team.removeClass('hover');
		
		});
	
	});
	
	var SeleccionarEquipo = $('SeleccionarEquipo');
	var equipo_seleccionado = $('equipo_seleccionado');
	var mensaje = $('mensaje');
	var mensaje_apoyo = $('mensaje_apoyo');
	
	if(SeleccionarEquipo && equipo_seleccionado)
	{
		$$('.select-team').each(function(e,i){
		
			e.addEvent('click',function(event){
				event.stop();
				
				equipo_seleccionado.set('value',this.get('href').split('=')[1]);
				
				$$('.team').removeClass('selected');
				var team = this.getParent('.team');
				team.addClass('selected');
				
				var teamname = team.getElement('.titulo a').get('text');
				
				mensaje_apoyo.set('text',teamname);
				mensaje.set('value','Yo apoyo a los '+teamname+' para el XLIV SuperBowl #NFL #NFLMX http://bit.ly/nfltwitter');
				
				if(SeleccionarEquipo.hasClass('hide'))
				{
					SeleccionarEquipo.set('opacity',0.0).set('height','0px').removeClass('hide');
					
					var myFx = new Fx.Tween(SeleccionarEquipo, {
						'duration':'long',
						'onComplete':function(){
							new Fx.Tween(SeleccionarEquipo).start('opacity',0,1);
						}
					});
					myFx.start('height',0,245);
				}

				new Request({
					'url':'?equipo_favorito='+equipo_seleccionado.get('value'),
					'method':'get',
					'onSuccess':function(html){
					}
				}).send();
				
			});		
		});
	}
	
	var seguir = $('seguir');
	
	if(seguir)
	{
		seguir.addEvent('click',function(event){
		
			event.stop();
			
			new Request({
				'url':this.get('href'),
				'method':'get',
				'onSuccess':function(html){

					new Fx.Tween(seguir,{
						'onComplete':function(){
							var span = new Element('span').set('text','¡Ya son amigos!').set('opacity',0).inject(seguir,'after').tween('opacity',0,1);
							seguir.dispose();
						}
					}).start('opacity',1,0);
				}
			}).send();
		
		});
	}
	
	var amigos = $('ver-mas-amigos');
	
	if(amigos)
	{
		amigos.addEvent('click',function(event){
		
			event.stop();
			
			$$('.fan.hide').removeClass('hide');
			
			this.addClass('hide');		
		});
	}

	var AjaxPagination = document.getElement('.ajax-pagination');

	if(AjaxPagination)
	{
		var pagination = $$('a.page');
		if(pagination.length > 1)
		{
			pagination.each(function(e,i){
			
		
				e.addEvent('click',function(event){
			
					event.stop();
					var fx = new Fx.Tween(AjaxPagination,{'duration':'normal'}).start('opacity',0);
					var request = new Request({
						'url':this.get('href'),
						'method':'get',
						'onSuccess':function(html){
							fx.cancel();
							AjaxPagination.set('html',html).tween('opacity',1);
						}
					}).send();
						
					pagination.removeClass('selected');
					this.addClass('selected');
				});
		
			});
		}
	}


});

