var delay=0;
var tiempo_carrusel=1000;
var time="";
var n=1;
var item_actual="";
var tipo_paginacion="";

function inicia_carrusel(nota1,nota2,nota3){
	time=new PeriodicalExecuter(function(t){
			n++;
										if(n==1){
											carga_noticia(nota1,'');
											if(nota2!=="" && nota3!==""){
												$('imagen_carrusel_noticia'+nota3).removeClassName('cuadro1');
												$('imagen_carrusel_noticia'+nota2).removeClassName('cuadro1');
												$('imagen_carrusel_noticia'+nota1).addClassName('cuadro1');
												item_actual='imagen_carrusel_noticia'+nota1;
												return false;
											}else{
												$('imagen_carrusel_noticia'+nota1).addClassName('cuadro1');
												item_actual='imagen_carrusel_noticia'+nota1;
												return false;
											}
											
										}else if(n==2){
											carga_noticia(nota2,'');
											$('imagen_carrusel_noticia'+nota1).removeClassName('cuadro1');
											$('imagen_carrusel_noticia'+nota3).removeClassName('cuadro1');
											$('imagen_carrusel_noticia'+nota2).addClassName('cuadro1');
											item_actual='imagen_carrusel_noticia'+nota2;
											
											return false;
										}else if(n==3){
											carga_noticia(nota3,'');
											$('imagen_carrusel_noticia'+nota1).removeClassName('cuadro1');
											$('imagen_carrusel_noticia'+nota2).removeClassName('cuadro1');
											$('imagen_carrusel_noticia'+nota3).addClassName('cuadro1');
											item_actual='imagen_carrusel_noticia'+nota3;
											n=0;
											return false;
										
										}
											
								}, 7);
}

function carrusel_noticias(){
	$('foto_noticia').hide();
	$('titulo_noticia_carrusel').hide();
	$('contenido_noticia_carrusel').hide();
	$('fecha_noticia_carrusel').hide();
	
	Effect.Grow('fecha_noticia_carrusel',{ duration: 0.2 }); 
	Effect.Appear('titulo_noticia_carrusel',{ duration: 0.2 });
	Effect.Appear('fecha_noticia_carrusel',{ duration: 0.2 }); 
	Effect.Appear('titulo_noticia_carrusel',{ duration: 0.2 });
	Effect.Appear('contenido_noticia_carrusel', { duration: 0.2 });
	Effect.toggle('foto_noticia', 'appear', { duration: 0.2 });
	
	/*new Effect.Highlight('foto_noticia', {	
						startcolor: '#ffff99',
						endcolor: '#ffffff'
						
					});*/
	
	//Effect.Appear('', { duration: 1.0 });
}

function carga_noticia(id,pos){
	//time.stop();
	new Ajax.Request('carrusel_noticias.php?id='+id,{
		evalScripts:true,
		onSuccess:function(response){
			carrusel_noticias();
			var results=response.responseText.evalJSON(); 
		if(results){
			
			$('foto_noticia').innerHTML=results['foto_grande'];
			$('titulo_noticia_carrusel').innerHTML=results['titulo'];
			$('contenido_noticia_carrusel').innerHTML=results['sumilla'];
			$('fecha_noticia_carrusel').innerHTML=results['fecha'];
		if(pos!==""){
			$(item_actual).removeClassName('cuadro1');
			$('imagen_carrusel_noticia'+id).addClassName('cuadro1');
			time.stop();
		}
			//n--;
			
			
		}
		
		}	
	});
	
	
	/*
	if(pos==""){
		
		return false;	
		
	}else{
		time.stop();
		n=pos;
		
	}
	*/
	
}

function  detalle_evento(id){
	//$('fila_'+id).addClassName("evento_fecha");
		new Ajax.Updater('descripcion_evento','eventos_calendario.php?i='+id,{evalScripts:true});
	
}

function  quita_estilo(id){
	//$('fila_'+id).removeClassName("evento_fecha");
	$('descripcion_evento').update("");
}



function ver_noticias(tipo){
	mostrar_mensaje(1);
		new Ajax.Request('paginacion_noticias.php?tipo='+tipo,{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			$('paginas_noticias').innerHTML=results['data'];
			$('paginacion_noticias').innerHTML=results['info_navegacion'];	
			mostrar_mensaje(0);
		}
		
		}	
	});
}

function mostrar_mensaje(estado){
	if(estado==1){
		$('msg_ajax').show();	
	}else{
		$('msg_ajax').hide();
	}

}

function cargar_pagina(dir){
	new Ajax.Request(dir,{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			if(tipo_paginacion=="videos"){
				
				$('items_de_videos').hide();
				$('items_de_videos').innerHTML=results['data'];
				Effect.Appear('items_de_videos', { duration: 1.0 });
				$('paginacion_video_fechas').innerHTML=results['info_navegacion'];	
			}else{
			
				$('paginas_noticias').innerHTML=results['data'];
				$('paginacion_noticias').innerHTML=results['info_navegacion'];
			}
		}
		
		
		}
		
		});	
		
}		


function cargar_pagina2(dir){
	new Ajax.Request(dir,{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			
				
				$('items_fotos').hide();
				$('items_fotos').innerHTML=results['data'];
				Effect.Appear('items_fotos', { duration: 1.0 });
				$('paginacion_fotos').innerHTML=results['info_navegacion'];	
			
			
				
			
		}
		
		
		}
		
		});	
		
}	



function cargar_eventos(tipo){
	//mostrar_mensaje(1);
	
	new Ajax.Request('paginacion_eventos.php?tipo='+tipo,{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			//Shadowbox.clearCache(); Shadowbox.setup();
			
			$('eventos_paginados').innerHTML=results['data'];
			$('paginacion_eventos').innerHTML=results['info_navegacion'];	
		//	mostrar_mensaje(0);
			
			}
		}
		
		});	
}		

function cargar_videos(){
	tipo_paginacion="videos";
	new Ajax.Request('paginacion_videos.php',{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			
			$('items_de_videos').innerHTML=results['data'];
			$('items_de_videos').hide();
			Effect.Appear('items_de_videos', { duration: 1.0 });
			$('paginacion_video_fechas').innerHTML=results['info_navegacion'];	
	
			}
		}
		
		});	
}		

function cargar_categorias_fotos(tipo){
	tipo_paginacion="videos";
	new Ajax.Request('paginacion_fotos.php?t='+tipo,{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			
			$('items_de_videos').innerHTML=results['data'];
			$('items_de_videos').hide();
			Effect.Appear('items_de_videos', { duration: 1.0 });
			$('paginacion_video_fechas').innerHTML=results['info_navegacion'];	
	
			}
		}
		
		});	
}



function cargar_segmentos(id){
	new Ajax.Request('segmentos_programa.php?id_programa='+id,{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			$('titulo_segementos').innerHTML=results['titulo'];
			$('segmentos_programa').innerHTML=results['data'];
			$('segmentos_programa').hide();
			Effect.Appear('segmentos_programa', { duration: 1.0 });
			}
		}
		
		});	
}		

function cargar_video(id,url,tipo){
	//playerReady() ;
	
	var player=$('ply'); 
	player.sendEvent('LOAD',url);
	
	new Ajax.Request('videos.php?tipo='+tipo+'&id_segmento='+id,{
		evalScripts:true,
		onSuccess:function(response){
			
			var results=response.responseText.evalJSON(); 
		if(results){
			$('titulo_segemento_lcd').innerHTML=results['titulo'];
				//new Ajax.Updater('video_lcd','videos.php?video=yes&id_segmento='+id,{evalScripts:true});
			}
		}
		
		});	
	
}		


function cargar_video_test(id,url,tipo){
	
	var player2=$('ply'); 
	player2.sendEvent('LOAD',url);
	//Effect.ScrollTo('video_lcd');
	
	new Ajax.Request('videos.php?tipo='+tipo+'&id_segmento='+id,{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			$('titulo_segemento_lcd').innerHTML=results['titulo'];
					//new Ajax.Updater('video_lcd','videos.php?video_test=yes&id_segmento='+id,{evalScripts:true});
			}
		}
		
		});	
	
}


function cargar_video_categoria(id,url,tipo){
	var player3=$('ply'); 
	player3.sendEvent('LOAD',url);
	//new Effect.ScrollTo('video_lcd');
	new Ajax.Request('videos.php?tipo='+tipo+'&id_segmento='+id,{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			$('titulo_segemento_lcd').innerHTML=results['titulo'];
				//	new Ajax.Updater('video_lcd','videos.php?video_categoria=yes&id_segmento='+id,{evalScripts:true});
			}
		}
		
		});	
	
}


function cargar_publicidad(pagina)
{
	new Ajax.Updater('head','banners.php?p='+pagina+'&b=1',{evalScripts: true});
	new Ajax.Updater('publica1','banners.php?p='+pagina+'&b=2',{evalScripts: true});
	new Ajax.Updater('banner_2','banners.php?p='+pagina+'&b=3',{evalScripts: true});
	new Ajax.Updater('banner_3','banners.php?p='+pagina+'&b=4',{evalScripts: true});
	new Ajax.Updater('publica2','banners.php?p='+pagina+'&b=5',{evalScripts: true});
	
}

function cargar_header(pagina)
{
	new Ajax.Updater('head','banners.php?p='+pagina+'&b=1',{evalScripts: true});	
}


function cargar_publicidad_f1(pagina)
{
	new Ajax.Updater('head','banners.php?p='+pagina+'&b=1',{evalScripts: true});
	new Ajax.Updater('banner_01','banners.php?p='+pagina+'&b=2',{evalScripts: true});
	new Ajax.Updater('banner_02','banners.php?p='+pagina+'&b=3',{evalScripts: true});
	new Ajax.Updater('banner_03','banners.php?p='+pagina+'&b=4',{evalScripts: true});
	new Ajax.Updater('banner_04','banners.php?p='+pagina+'&b=5',{evalScripts: true});
	
}


function cargar_categorias_videos(tipo){
	tipo_paginacion="videos";
	new Ajax.Request('paginacion_categorias_videos.php?t='+tipo,{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			
			$('items_de_videos').innerHTML=results['data'];
			$('items_de_videos').hide();
			Effect.Appear('items_de_videos', { duration: 1.0 });
			$('paginacion_video_fechas').innerHTML=results['info_navegacion'];	
	
			}
		}
		
		});	
}		


function cargar_videos_test(){
	tipo_paginacion="videos";
	new Ajax.Request('paginacion_test.php',{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			
			$('items_de_videos').innerHTML=results['data'];
			$('items_de_videos').hide();
			Effect.Appear('items_de_videos', { duration: 1.0 });
			$('paginacion_video_fechas').innerHTML=results['info_navegacion'];	
	
			}
		}
		
		});	
}		


function cargar_segmentos_test(id){
	new Ajax.Request('segmentos_test.php?ir='+id,{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			$('titulo_segementos').innerHTML=results['titulo'];
			$('segmentos_programa').innerHTML=results['data'];
			$('segmentos_programa').hide();
			Effect.Appear('segmentos_programa', { duration: 1.0 });
			}
		}
		
		});	
}		


function cargar_segmentos_videos(id){
	new Ajax.Request('segmentos_video.php?ir='+id,{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			$('titulo_segementos').innerHTML=results['titulo'];
			$('segmentos_programa').innerHTML=results['data'];
			$('paginacion_videos').innerHTML=results['info_navegacion'];
			$('segmentos_programa').hide();
			Effect.Appear('segmentos_programa', { duration: 1.0 });
			}
		}
		
		});	
}

function cargar_items_videos(url,i){
	new Ajax.Request(url,{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			$('titulo_segementos').innerHTML=results['titulo'];
			$('segmentos_programa').innerHTML=results['data'];
			$('paginacion_videos').innerHTML=results['info_navegacion'];
			$('segmentos_programa').hide();
			Effect.Appear('segmentos_programa', { duration: 1.0 });
			}
		}
		
		});	
}




function cargar_segmentos_categorias(id){
	new Ajax.Request('segmentos_video.php?ir='+id,{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			$('titulo_segementos').innerHTML=results['titulo'];
			$('segmentos_programa').innerHTML=results['data'];
			$('segmentos_programa').hide();
			Effect.Appear('segmentos_programa', { duration: 1.0 });
			}
		}
		
		});	
}


function cargar_fotos(id){
	new Ajax.Request('segmentos_fotos.php?ir='+id,{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			$('titulo_segementos').innerHTML=results['titulo'];
			$('items_fotos').innerHTML=results['data'];
			$('paginacion_fotos').innerHTML=results['info_navegacion'];
			$('items_fotos').hide();
			Effect.Appear('items_fotos', { duration: 1.0 });
			}
		}
		
		});	
}	


var player = null; 
function playerReady() { 
	player = $('ply'); 
	player.sendEvent('STOP')

}

function ver_entrevistas(){
	mostrar_mensaje(1);
		new Ajax.Request('paginacion_entrevistas.php',{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			$('paginas_noticias').innerHTML=results['data'];
			$('paginacion_noticias').innerHTML=results['info_navegacion'];	
			mostrar_mensaje(0);
		}
		
		}	
	});
}






function inicia_carrusel_entrevistas(nota1,nota2,nota3){
	time=new PeriodicalExecuter(function(t){
			n++;
										if(n==1){
											carga_entrevista(nota1,'');
											if(nota2!=="" && nota3!==""){
												$('imagen_carrusel_noticia'+nota3).removeClassName('cuadro1');
												$('imagen_carrusel_noticia'+nota2).removeClassName('cuadro1');
												$('imagen_carrusel_noticia'+nota1).addClassName('cuadro1');
												item_actual='imagen_carrusel_noticia'+nota1;
												return false;
											}else{
												$('imagen_carrusel_noticia'+nota1).addClassName('cuadro1');
												item_actual='imagen_carrusel_noticia'+nota1;
												return false;
											}
											
										}else if(n==2 && nota2!==""){
											carga_entrevista(nota2,'');
											$('imagen_carrusel_noticia'+nota1).removeClassName('cuadro1');
											$('imagen_carrusel_noticia'+nota3).removeClassName('cuadro1');
											$('imagen_carrusel_noticia'+nota2).addClassName('cuadro1');
											item_actual='imagen_carrusel_noticia'+nota2;
											
											return false;
										}else if(n==3 && nota3!==""){
											carga_entrevista(nota3,'');
											$('imagen_carrusel_noticia'+nota1).removeClassName('cuadro1');
											$('imagen_carrusel_noticia'+nota2).removeClassName('cuadro1');
											$('imagen_carrusel_noticia'+nota3).addClassName('cuadro1');
											item_actual='imagen_carrusel_noticia'+nota3;
											n=0;
											return false;
										
										}
											
								}, 7);
}

function carrusel_entrevistas(){
	$('foto_noticia').hide();
	$('titulo_noticia_carrusel').hide();
	$('contenido_noticia_carrusel').hide();
	$('fecha_noticia_carrusel').hide();
	
	Effect.Grow('fecha_noticia_carrusel',{ duration: 0.2 }); 
	Effect.Grow('titulo_noticia_carrusel',{ duration: 0.2 });
	Effect.Appear('fecha_noticia_carrusel',{ duration: 0.2 }); 
	Effect.Appear('titulo_noticia_carrusel',{ duration: 0.2 });
	Effect.Appear('contenido_noticia_carrusel', { duration: 0.2 });
	Effect.toggle('foto_noticia', 'appear', { duration: 0.2 });
	
	/*new Effect.Highlight('foto_noticia', {	
						startcolor: '#ffff99',
						endcolor: '#ffffff'
						
					});*/
	
	//Effect.Appear('', { duration: 1.0 });
}


function carga_entrevista(id,pos){
	//time.stop();
	new Ajax.Request('carrusel_entrevistas.php?id='+id,{
		evalScripts:true,
		onSuccess:function(response){
			carrusel_entrevistas();
			var results=response.responseText.evalJSON(); 
		if(results){
			
			$('foto_noticia').innerHTML=results['foto_grande'];
			$('titulo_noticia_carrusel').innerHTML=results['titulo'];
			$('contenido_noticia_carrusel').innerHTML=results['sumilla'];
			$('fecha_noticia_carrusel').innerHTML=results['fecha'];
		if(pos!==""){
			$(item_actual).removeClassName('cuadro1');
			$('imagen_carrusel_noticia'+id).addClassName('cuadro1');
			time.stop();
		}
			//n--;
			
			
		}
		
		}	
	});
	
	
	/*
	if(pos==""){
		
		return false;	
		
	}else{
		time.stop();
		n=pos;
		
	}
	*/
	
}



function inicia_carrusel_novedades(nota1,nota2,nota3){
	time=new PeriodicalExecuter(function(t){
			n++;
										if(n==1){
											carga_novedad(nota1,'');
											if(nota2!=="" && nota3!==""){
												$('imagen_carrusel_noticia'+nota3).removeClassName('cuadro1');
												$('imagen_carrusel_noticia'+nota2).removeClassName('cuadro1');
												$('imagen_carrusel_noticia'+nota1).addClassName('cuadro1');
												item_actual='imagen_carrusel_noticia'+nota1;
												return false;
											}else{
												$('imagen_carrusel_noticia'+nota1).addClassName('cuadro1');
												item_actual='imagen_carrusel_noticia'+nota1;
												return false;
											}
										}else if(n==2){
											carga_novedad(nota2,'');
											$('imagen_carrusel_noticia'+nota1).removeClassName('cuadro1');
											$('imagen_carrusel_noticia'+nota3).removeClassName('cuadro1');
											$('imagen_carrusel_noticia'+nota2).addClassName('cuadro1');
											item_actual='imagen_carrusel_noticia'+nota2;
											
											return false;
										}else if(n==3){
											carga_novedad(nota3,'');
											$('imagen_carrusel_noticia'+nota1).removeClassName('cuadro1');
											$('imagen_carrusel_noticia'+nota2).removeClassName('cuadro1');
											$('imagen_carrusel_noticia'+nota3).addClassName('cuadro1');
											item_actual='imagen_carrusel_noticia'+nota3;
											n=0;
											return false;
										
										}
											
								}, 7);
}

function carrusel_entrevistas(){
	$('foto_noticia').hide();
	$('titulo_noticia_carrusel').hide();
	$('contenido_noticia_carrusel').hide();
	$('fecha_noticia_carrusel').hide();
	
	Effect.Grow('fecha_noticia_carrusel',{ duration: 0.2 }); 
	Effect.Grow('titulo_noticia_carrusel',{ duration: 0.2 });
	Effect.Appear('fecha_noticia_carrusel',{ duration: 0.2 }); 
	Effect.Appear('titulo_noticia_carrusel',{ duration: 0.2 });
	Effect.Appear('contenido_noticia_carrusel', { duration: 0.2 });
	Effect.toggle('foto_noticia', 'appear', { duration: 0.2 });
	
	/*new Effect.Highlight('foto_noticia', {	
						startcolor: '#ffff99',
						endcolor: '#ffffff'
						
					});*/
	
	//Effect.Appear('', { duration: 1.0 });
}


function carga_novedad(id,pos){
	//time.stop();
	new Ajax.Request('carrusel_novedades.php?id='+id,{
		evalScripts:true,
		onSuccess:function(response){
			carrusel_entrevistas();
			var results=response.responseText.evalJSON(); 
		if(results){
			
			$('foto_noticia').innerHTML=results['foto_grande'];
			$('titulo_noticia_carrusel').innerHTML=results['titulo'];
			$('contenido_noticia_carrusel').innerHTML=results['sumilla'];
			$('fecha_noticia_carrusel').innerHTML=results['fecha'];
		if(pos!==""){
			$(item_actual).removeClassName('cuadro1');
			$('imagen_carrusel_noticia'+id).addClassName('cuadro1');
			time.stop();
		}
			//n--;
			
			
		}
		
		}	
	});
	

	
}


function ver_novedades(){
	mostrar_mensaje(1);
		new Ajax.Request('paginacion_novedades.php',{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			$('paginas_noticias').innerHTML=results['data'];
			$('paginacion_noticias').innerHTML=results['info_navegacion'];	
			mostrar_mensaje(0);
		}
		
		}	
	});
}

function cargar_videos_test_2(marca){
	tipo_paginacion="videos";
	new Ajax.Request('paginacion_test_2.php?m='+marca,{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			
			$('items_de_videos').innerHTML=results['data'];
			$('items_de_videos').hide();
			Effect.Appear('items_de_videos', { duration: 1.0 });
			$('paginacion_video_fechas').innerHTML=results['info_navegacion'];	
	
			}
		}
		
		});	
}	

function cargar_detalles_modelo(m){
	new Ajax.Updater('foto_auto','resultados_autos.php?id='+m,{evalScripts:true});

}

function cargar_modelos(m){
	new Ajax.Updater('modelo_auto','lista_marcas.php?id='+m,{evalScripts:true});

}


function cargar_categorias_test(m){
	new Ajax.Request('paginacion_roadtest.php?m='+m,{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			
			$('paginacion_test').innerHTML=results['data'];
			$('paginas_test').innerHTML=results['info_navegacion'];	
		
			
			}
		}
		
		});	
}	

function cargar_pestanas(c,p){
	new Ajax.Updater(c,p,{evalScripts:true});

}



function cargar_videos_4x4(){
	new Ajax.Request('paginacion_4x4.php',{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			
			$('videos_4x4').innerHTML=results['data'];
			$('paginas_4x4').innerHTML=results['info_navegacion'];	
		
			
			}
		}
		
		});	
}


function cargar_videos_motos(){
	new Ajax.Request('paginacion_motos.php',{
		evalScripts:true,
		onSuccess:function(response){
			var results=response.responseText.evalJSON(); 
		if(results){
			
			$('videos_moto_n').innerHTML=results['data'];
			$('paginas_moto_n').innerHTML=results['info_navegacion'];	
		
			
			}
		}
		
		});	
}





