function poner_contenido(hoy, idioma){
var etapa = 0;
etapa = parseInt(hoy);
poner_tira(hoy, idioma);
poner_noticias(hoy,idioma);
poner_pelicula(hoy,idioma);
poner_clasificacion(hoy, "SITE", idioma, 0);
//	poner_videos()
}


function poner_pelicula(hoy, idioma){
etapa = parseInt(hoy);
if (parseInt(hoy) > 4) etapa++;
if (parseInt(hoy) > 11) etapa++;
if (hoy == "p") etapa = 0;
if (hoy == "d1") etapa = 5;
if (hoy == "d2") etapa = 13;
if ((etapa==0) || (etapa == 5) || (etapa == 13)){
$("#sub_pelicula").html(etapas[etapa].fl + " - " + etapas[etapa].n1);
$("#html_pelicula").parent().parent().hide();
}
else{
$("#sub_pelicula").html(etapas[etapa].nu + etapas[etapa].a + " Etapa. " + etapas[etapa].n1 + " - " + etapas[etapa].n2);
etapa = parseInt(etapas[etapa].nu);
var mi_xml = "";
if (etapa < 10)
mi_xml = "PELI"+idioma+"0"+etapa+".xml";
else
mi_xml = "PELI"+idioma+etapa+".xml";
cadena = "";
$.ajax({
url: "/09/espanol/online/xml/"+mi_xml,	
type: "GET",
dataType: "xml",
cache: false,
async: false,
success: function(xml){
var nombre_xml = "";
$(xml).find("entrada").slice(0,3).each(function(i) {
if (etapa < 10)
nombre_xml = "PLIV"+idioma+$(this).attr("file")+"0"+etapa+"00.xml" ;
else
nombre_xml = "PLIV"+idioma+$(this).attr("file")+etapa+"00.xml" ;
cadena += '<div id="kmyhora" style="float:left; margin-left:0px"><div id="km">'+$(this).attr("km")+'</div><div id="hora">'+$(this).attr("hora")+'</div></div>';
$.ajax({
url: "/09/espanol/online/xml/"+nombre_xml,
type: "GET",
dataType: "xml",
cache: false,
async: false,
success: function(xml){
cadena += '<div class="noticia" style="float:left; width:480px; margin-left:10px;"><h2>'+$(xml).find("title").text()+'</h2>';
var t_t = $(xml).find("text").text().replace(/\n/g,"<br/>");
var re = /(\d+)\s\(([^\)]*)\)/gm;
t_t = t_t.replace(re,"<a href='javascript:AbrirCorredores(\"http://origin-aplicaciones.lavuelta.com/cgi-local/lavuelta29.cgi?cgifunction=Search&Dorsal=$1\")'>$2</a>");
cadena += '<div class="noticia-texto">'+t_t+'</div>';
cadena += '<div class="online_sep"></div></div>';
}
});
cadena += '<br class="online_clear">';
});
},
error: function(){$("#html_pelicula").parent().parent().hide();}
});
$("#html_pelicula").html(cadena);
setTimeout("poner_pelicula('"+hoy+"', '"+idioma+"')",1000*60);
}
}

function poner_noticias(hoy, idioma){
if (idioma=="ES"){
mi_idioma = "espanol";
str_no = "Información no disponible en este momento.";
}
if (idioma=="US"){
mi_idioma = "ingles";
str_no = "Information not available.";
}
if (idioma=="FR"){
mi_idioma = "frances";
str_no = "Information actuellement non disponible.";
}
$.ajax({
type:"GET",
url: "/09/"+mi_idioma+"/noticias/noticias"+hoy+".xml",
dataType: "xml",
cache: false,
success: function(datos){
if ($(datos).find("noticia").text()=="") {
$("#html_noticia").html(str_no);
}else{
var j=0;
var con="";
$(datos).find("noticia").eq(0).each(function(i) {
con+="<h2>"+$(this).find("tit").text()+"</h2><div class='noticia-texto'>"+$(this).find("texto").text().replace(/\n/g,"<br>")+"</div><br/><br/>";
j++;
});
$("#html_noticia").html(con);
}
},
error:function(){$("#html_noticia").html(str_no);}
});
}

function poner_tira(hoy, idioma){
var mi_hoy = hoy;
if (hoy == "p") mi_hoy = "0";
if (hoy == "d1") mi_hoy = "5";
if (hoy == "d2") mi_hoy = "12";
if (idioma == "ES") mi_idioma = "espanol";
if (idioma == "US") mi_idioma = "ingles";
if (idioma == "FR") mi_idioma = "frances";
var km = 0;
var cadena = "";
$.ajax({
type: "GET",
asyn: false,
url: "/09/js/perfil"+mi_hoy+".js",
success: function(datos){km = parseInt(datos);},
complete: function(){
cadena = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="968" height="110" id="FlashID" title="etapas">';
cadena += '<param name="movie" value="/09/imagenes/etapas.swf?idioma='+mi_idioma+'&etpm='+mi_hoy+'&km='+km+'">';
cadena += '<param name="quality" value="high">';
cadena += '<param name="wmode" value="opaque">';
cadena += '<param name="menu" value="false">';
cadena += '<param name="swfversion" value="6.0.65.0">';
cadena += '<param name="expressinstall" value="/09/js/expressInstall.swf">';
if (!$.browser.msie) cadena += '<object type="application/x-shockwave-flash" data="/09/imagenes/etapas.swf?idioma='+mi_idioma+'&etpm='+mi_hoy+'&km='+km+'" width="968" height="110">';
cadena += '<param name="quality" value="high">';
cadena += '<param name="wmode" value="opaque">';
cadena += '<param name="menu" value="false">';
cadena += '<param name="swfversion" value="6.0.65.0">';
cadena += '<param name="expressinstall" value="/09/js/expressInstall.swf">';
cadena += '<div>';
cadena += '<h4>El contenido de esta p&aacute;gina requiere una versi&oacute;n m&aacute;s reciente de Adobe Flash Player.</h4>';
cadena += '<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Obtener Adobe Flash Player" width="112" height="33" /></a></p>';
cadena += '</div>';
if (!$.browser.msie) cadena += '</object>';
cadena += '</object>';
$("#tira_etapas").html(cadena)			;
}
});
}

function poner_clasificacion(hoy, clas, idioma, retry){

switch (idioma){
case 'ES': 
str_pos="Pos.";
str_nombre="Nombre";
str_tiempo="Tiempo";
str_pt="Puntos";
str_oficiosa="OFICIOSA";
str_etapa="Individual";
str_general="General Individual";
str_montana="General de la Montaña";
str_puntos="General por Puntos";
str_combi="General Combinada";
str_dor="Dor.";
str_nac="Nac.";
str_equ="Equ.";
str_no="Información no disponible en este momento.";
break;
case 'US': 
str_pos="Pos.";
str_nombre="Name";
str_tiempo="Time";
str_pt="Points";
str_oficiosa="PROVISIONAL";
str_etapa="Individual Standing";
str_general="Overall Individual";
str_montana="Overall Climber";
str_puntos="Overall Points";
str_combi="Overall Allround";
str_dor="Nº";
str_nac="Nat.";
str_equ="Team";
str_no = "Information not available.";
break;
case 'FR': 
str_pos="Pos";
str_nombre="Nom";
str_tiempo="Temps";
str_pt="Points";
str_oficiosa="OFFICIEUSE";
str_etapa="Classement Individuel";
str_general="Général Individuel";
str_montana="Général Grimpeur";
str_puntos="Général par Points";
str_combi="Classement Général";
str_dor="Dor.";
str_nac="Nac.";
str_equ="Équ.";
str_no="Information actuellement non disponible.";
break;
}


if (!isNaN(hoy)){
etapa = parseInt(hoy);
if (parseInt(hoy) > 4) etapa++;
if (parseInt(hoy) > 11) etapa++;
}
else{
if (hoy == "p") etapa = 0;
if (hoy == "d1") etapa = 5;
if (hoy == "d2") etapa = 12;
}

//	if ((etapa!=0) && (etapa!=6) &&(etapa!=14)) 
n_etapa = ' - ' + etapas[etapa].nu + etapas[etapa].a + " Etapa. " + etapas[etapa].n1 + " - " + etapas[etapa].n2;
//	else n_etapa = ' - ' + etapas[etapa].nu + etapas[etapa].a + " Etapa. " + etapas[etapa].n1 + " - " + etapas[etapa].n2

var etapa = "";
etapa = hoy;
if (hoy == "p") etapa = "0";
if (hoy == "d1") etapa = "4";
if (hoy == "d2") etapa = "11";
if (etapa < 10) etapa = "0"+etapa;

mi_xml = clas+etapa+"00.xml";

$.ajax({
type:"GET",
url: "/09/espanol/resultados/clas/"+mi_xml,
dataType: "xml",
cache: false,
success: function(datos){
switch (clas){
case 'SITE':	tabla = '<div style="text-align:center; font-weight: bold;">'+str_etapa + n_etapa;
if ($(datos).find("standings").attr("oficiosa")!="0") tabla += ' - ' + str_oficiosa;
tabla += '</div><table class="tbClasCab"><tr><td class="tdClasC1">'+str_pos+'</td><td class="tdClasC2">'+str_dor+'</td><td class="tdClasC3">'+str_nombre+'</td><td class="tdClasC4">'+str_nac+'</td><td class="tdClasC5">'+str_equ+'</td><td class="tdClasC6">'+str_tiempo+'</td></tr></table>';
tabla += '<table class="tbClas tb_cebra">';
$(datos).find("rank").slice(0,10).each(function(i) {
if ($(this).attr("position") != "") tabla += '<tr><td class="tdClasC1">'+$(this).attr("position")+'</td>';
else tabla += '<tr><td class="tdClasC1"></td>';
tabla += '<td class="tdClasC2"><a href="/09/corredores/'+$(this).attr("number")+'.html" rel="facebox">'+$(this).attr("number")+'</a></td>';
tabla += '<td class="tdClasC3">'+$(this).attr("name")+'</td>';
tabla += '<td class="tdClasC4">'+$(this).attr("nationality")+'</td>';
tabla += '<td class="tdClasC5">'+$(this).attr("teamcode")+'</td>';
if (i==0) tabla += '<td class="tdClasC6">'+format_tiempo($(this).attr("time"))+'</td></tr>';
else tabla += '<td class="tdClasC6">'+format_diferencia($(this).attr("gap"))+'</td></tr>';
});
tabla += '</table>';
break;
case 'SITG':	tabla = '<div style="text-align:center; font-weight: bold;">'+str_general + n_etapa;
if ($(datos).find("standings").attr("oficiosa")!="0") tabla += ' - ' + str_oficiosa;
tabla += '</div><table class="tbClasCab"><tr><td class="tdClasC1">'+str_pos+'</td><td class="tdClasC2">'+str_dor+'</td><td class="tdClasC3">'+str_nombre+'</td><td class="tdClasC4">'+str_nac+'</td><td class="tdClasC5">'+str_equ+'</td><td class="tdClasC6">'+str_tiempo+'</td></tr></table>';
tabla += '<table class="tbClas tb_cebra">';
$(datos).find("rank").slice(0,10).each(function(i) {
if ($(this).attr("position") != "") tabla += '<tr><td class="tdClasC1">'+$(this).attr("position")+'</td>';
else tabla += '<tr><td class="tdClasC1"></td>';
tabla += '<td class="tdClasC2"><a href="/09/corredores/'+$(this).attr("number")+'.html" rel="facebox">'+$(this).attr("number")+'</a></td>';
tabla += '<td class="tdClasC3">'+$(this).attr("name")+'</td>';
tabla += '<td class="tdClasC4">'+$(this).attr("nationality")+'</td>';
tabla += '<td class="tdClasC5">'+$(this).attr("teamcode")+'</td>';
if (i==0) tabla += '<td class="tdClasC6">'+format_tiempo($(this).attr("time"))+'</td></tr>';
else tabla += '<td class="tdClasC6">'+format_diferencia($(this).attr("gap"))+'</td></tr>';
});
tabla += '</table>';
break;
case 'SIMG':	tabla = '<div style="text-align:center; font-weight: bold;">'+str_montana + n_etapa;
if ($(datos).find("standings").attr("oficiosa")!="0") tabla += ' - ' + str_oficiosa;
tabla += '</div><table class="tbClasCab"><tr><td class="tdClasC1">'+str_pos+'</td><td class="tdClasC2">'+str_dor+'</td><td class="tdClasC3">'+str_nombre+'</td><td class="tdClasC4">'+str_nac+'</td><td class="tdClasC5">'+str_equ+'</td><td class="tdClasC6">'+str_pt+'</td></tr></table>';
tabla += '<table class="tbClas tb_cebra">';
$(datos).find("rank").slice(0,10).each(function(i) {
if ($(this).attr("position") != "") tabla += '<tr><td class="tdClasC1">'+$(this).attr("position")+'</td>';
else tabla += '<tr><td class="tdClasC1"></td>';
tabla += '<td class="tdClasC2"><a href="/09/corredores/'+$(this).attr("number")+'.html" rel="facebox">'+$(this).attr("number")+'</a></td>';
tabla += '<td class="tdClasC3">'+$(this).attr("name")+'</td>';
tabla += '<td class="tdClasC4">'+$(this).attr("nationality")+'</td>';
tabla += '<td class="tdClasC5">'+$(this).attr("teamcode")+'</td>';
tabla += '<td class="tdClasC6">'+$(this).attr("points")+'</td></tr>';
});
tabla += '</table>';
break;
case 'SIPG':	tabla = '<div style="text-align:center; font-weight: bold;">'+str_puntos + n_etapa;
if ($(datos).find("standings").attr("oficiosa")!="0") tabla += ' - ' + str_oficiosa;
tabla += '</div><table class="tbClasCab"><tr><td class="tdClasC1">'+str_pos+'</td><td class="tdClasC2">'+str_dor+'</td><td class="tdClasC3">'+str_nombre+'</td><td class="tdClasC4">'+str_nac+'</td><td class="tdClasC5">'+str_equ+'</td><td class="tdClasC6">'+str_pt+'</td></tr></table>';
tabla += '<table class="tbClas tb_cebra">';
$(datos).find("rank").slice(0,10).each(function(i) {
if ($(this).attr("position") != "") tabla += '<tr><td class="tdClasC1">'+$(this).attr("position")+'</td>';
else tabla += '<tr><td class="tdClasC1"></td>';
tabla += '<td class="tdClasC2"><a href="/09/corredores/'+$(this).attr("number")+'.html" rel="facebox">'+$(this).attr("number")+'</a></td>';
tabla += '<td class="tdClasC3">'+$(this).attr("name")+'</td>';
tabla += '<td class="tdClasC4">'+$(this).attr("nationality")+'</td>';
tabla += '<td class="tdClasC5">'+$(this).attr("teamcode")+'</td>';
tabla += '<td class="tdClasC6">'+$(this).attr("points")+'</td></tr>';
});
tabla += '</table>';
break;
case 'SCOM':	 tabla = '<div style="text-align:center; font-weight: bold;">'+str_combi + n_etapa;
if ($(datos).find("standings").attr("oficiosa")!="0") tabla += ' - ' + str_oficiosa;
tabla += '</div><table class="tbClasCab"><tr><td class="tdClasC1">'+str_pos+'</td><td class="tdClasC2">'+str_dor+'</td><td class="tdClasC3">'+str_nombre+'</td><td class="tdClasC4">'+str_nac+'</td><td class="tdClasC5">'+str_equ+'</td><td class="tdClasC6">'+str_pt+'</td></tr></table>';
tabla += '<table class="tbClas tb_cebra">';
$(datos).find("rank").slice(0,10).each(function(i) {
if ($(this).attr("position") != "") tabla += '<tr><td class="tdClasC1">'+$(this).attr("position")+'</td>';
else tabla += '<tr><td class="tdClasC1"></td>';
tabla += '<td class="tdClasC2"><a href="/09/corredores/'+$(this).attr("number")+'.html" rel="facebox">'+$(this).attr("number")+'</a></td>';
tabla += '<td class="tdClasC3">'+$(this).attr("name")+'</td>';
tabla += '<td class="tdClasC4">'+$(this).attr("nationality")+'</td>';
tabla += '<td class="tdClasC5">'+$(this).attr("teamcode")+'</td>';
tabla += '<td class="tdClasC6">'+$(this).attr("points")+'</td></tr>';
});
tabla += '</table>';
break;
}
$("#html_clasificaciones").html(tabla);
$('a[rel*=facebox]').facebox();
$(".tb_cebra").each(function(i){$(this).find("tr:odd").addClass("tr_par");});
},
error:function(){
if ((retry == 1)||(etapa==0))
$("#html_clasificaciones").html('<div style=\"text-align:center; margin-top:60px\">'+str_no+'</div>');
else
poner_clasificacion(parseInt(etapa,10)-1, clas, idioma, 1);
}
});

}

function poner_videos(){
$.ajax({
type:"GET",
url: "/09/videos/videos.xml",
dataType: "xml",
cache: false,
success: function(datos){
con = '<ul>';
var j=0;
$(datos).find("video").each(function(i) {
con+='<li><a href="javascript:muestra_video(\''+$(this).attr("url")+'\')">'+$(this).attr("etapa")+'</a></li>';
ultima_url = $(this).attr("url");
j++;
});
con += '</ul>';
$("#sd_listado").html(con);
muestra_video(ultima_url);
$("#sd_listado ul").css("width",22*(j+1));
$('#sd_listado').serialScroll({
items:'li',
prev:'#sd_contenedor a.prev',
next:'#sd_contenedor a.next',
duration:100,
force:true,
cycle:false,
axis:'x',
easing:'linear',
step:1,
start:j-6
});
},
error:function(){$("#html_video").parent().parent().hide();}
});
}

function muestra_video(url){
$("#html_video").html('<object width="300" height="250"><param name="movie" value="'+url+'&hl=es&fs=1&rel=0&color1=0xfebd01&color2=0xfebd01"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+url+'&hl=es&fs=1&rel=0&color1=0xfebd01&color2=0xfebd01" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="300" height="250"></embed></object>');
}

function format_diferencia(tiempo){
var resultado = "";
if ((tiempo == "0:00:00")||(tiempo == "00:00:00"))
resultado = "m.t.";
else{
var h = tiempo.split(":")[0];
var m = tiempo.split(":")[1];
var s = tiempo.split(":")[2];
if ((h != "0")&&(h!="00"))
resultado = "a "+tiempo;
else
if (m != "00")
resultado = "a "+m+":"+s;
else
resultado = "a "+s;
}
return resultado;
}

function format_tiempo(tiempo){
var resultado = "";
var h = tiempo.split(":")[0];
var m = tiempo.split(":")[1];
var s = tiempo.split(":")[2];
if (h != "000")
resultado = tiempo;
else
if (m != "000")
resultado = m+":"+s;
else
resultado = s;
return resultado;
}
