var race = {

	init : function() {
		$("tr:odd").css("background-color", "#eeeeee");
		$('li').bind('click', function(esto){
			var texto, identificador;
			identificador = "#"+$(this).attr('id')+"a";
			
			texto = $(identificador).html();
			$.colorbox(
			{
				"html" : texto
			});
		});

		$('.inscripciones').live('click', function(esto){
			var texto, identificador;
			identificador = "#"+$(this).attr('id')+'km';
			texto = $(identificador).html();
			$.colorbox({"html" : texto});
		});
		race.ciclar();
		race.ciclarFotos();
		race.calcularFecha();
	},
	
	escuchar : function() {
		console.log('escuchar');
		
	},
	
	ciclar : function () {
		
		var lis, datos, elHtml, cuantos;
		lis = $('#tipsSemana li');
		cuantos = lis.length;
		if( !$('#tipsSemana').is('*') ) return;
		if( $('#tips').data('cancelarCiclo') ) return;
		var data = lis;
		var siguiente = $('#tips').data('siguiente') || 0;
		var actual = data[siguiente];

		//Definimos vista
		elHtml = $(actual).html();

		$('#tips').html(elHtml);
		$('#tips').find('span').fadeIn();
		//Preparamos siguiente
		var next = siguiente + 1;
		next = cuantos == next ? 0 : next;
		$('#tips').data('siguiente',next);
		//Nos llamamos a nosotros mismos
		setTimeout('race.ciclar()',7500);
	},
	
	ciclarFotos : function() {
		var fotoLis, datosFotos, fotosHtml, cuantas, fotoData, siguiente, actual, next;
		fotoLis = $('#fotos li');
		cuantas = fotoLis.length;
		
		if( !$('#fotos').is('*') ) return;
		if( $('#gallery').data('cancelarCiclo') ) return;
		fotoData = fotoLis;
		siguiente = $('#gallery').data('siguiente') || 0;
		actual = fotoData[siguiente];
		
		//View
		fotosHtml = $(actual).html();
		$('#gallery').html(fotosHtml);
		$('#gallery').find('img').fadeIn();
		next = siguiente + 1;
		next = cuantas == next ? 0 : next;
		$('#gallery').data('siguiente', next);
		
		setTimeout('race.ciclarFotos()', 5000);
		
	},
	
	calcularFecha : function () {
		var d, timeLimit, dms, texto;
		if( $("#finInscripciones").is('*') ) {
			texto = $("#finInscripciones").html();
//			d = new Date();
//			dms = d.getTime() - 21600000;
// 			timeLimit = 1329487200000;
//			timeLimit = 1329487113600;
//			timeLimit = 1329418800000;
			
// 			if(timeLimit <= dms) 
			$.colorbox({"html" : texto});
		}
	}
};

