var index_videos=0;
var index_ultimos=0;
var index_vistos=0;
var acabar=true;

function menos_0(){
	if(posy_0>-tam_0){
	
		posy_0-=inc;
		//$("#scroll01").css("margin-left",posy);
		$("#lista_ultimos").animate({marginLeft:posy_0}, 200, "easein");
	}
}
function mas_0(){
	if(posy_0<0){
		posy_0+=inc;
		//$("#scroll01").css("margin-left",posy);
		$("#lista_ultimos").animate({marginLeft:posy_0}, 200, "easein");
	}
}

function menos_1(){
	if(posy_1>-tam_1){
	
		posy_1-=inc;
		//$("#scroll01").css("margin-left",posy);
		$("#lista_masvistos").animate({marginLeft:posy_1}, 200, "easein");
	}
}
function mas_1(){
	if(posy_1<0){
		posy_1+=inc;
		//$("#scroll01").css("margin-left",posy);
		$("#lista_masvistos").animate({marginLeft:posy_1}, 200, "easein");
	}
}

function menos_2(){
	//alert("hola");
	if(posx_0>-tam_3){
	
		posx_0-=inc;
		//$("#scroll01").css("margin-left",posy);
		//$("#lista_principal").animate({marginTop:posx_0}, 200, "easein");
		$("#lista_principal").animate({top:posx_0}, 200, "easein");
	}
}
function mas_2(){
	//alert("hola");
	if(posx_0<0){
		posx_0+=inc;
		//$("#scroll01").css("margin-left",posy);
		//$("#lista_principal").animate({marginTop:posx_0}, 200, "easein");
		$("#lista_principal").animate({top:posx_0}, 200, "easein");
	}
}

function menos_4(){
	if(posy_2>-tam_4){
	
		posy_2-=inc;
		//$("#scroll01").css("margin-left",posy);
		$("#lista_ultimos").animate({marginLeft:posy_2}, 200, "easein");
	}
}
function mas_4(){
	if(posy_2<0){
		posy_2+=inc;
		//$("#scroll01").css("margin-left",posy);
		$("#lista_ultimos").animate({marginLeft:posy_2}, 200, "easein");
	}
}

function menos_5(){
	if(posy_3>-tam_4){
	
		posy_3-=inc;
		//$("#scroll01").css("margin-left",posy);
		$("#lista_masvistos").animate({marginLeft:posy_3}, 200, "easein");
	}
}
function mas_5(){
	if(posy_3<0){
		posy_3+=inc;
		//$("#scroll01").css("margin-left",posy);
		$("#lista_masvistos").animate({marginLeft:posy_3}, 200, "easein");
	}
}


function bajar(relative, elements_to_show, p_index, p_message)
{
  index=eval(p_index);
  if((index+elements_to_show)<$(relative+" ul li").size())
  {
    if (acabar)
	{
	  acabar=false;
	  $(relative+" ul li#"+p_index+"-"+index).fadeOut('fast',
	  function()
	  {
	    $(relative+" ul li#"+p_index+"-"+(index+elements_to_show)).fadeIn('fast',
		function()
		{
	      acabar=true;
	      eval(p_index+'++');
		}
		); 
	  });
    }
  }
}

function subir(relative, elements_to_show, p_index, p_message)
{
  index=eval(p_index);
  if(index>0)
  {
    if (acabar)
	{
	  acabar=false;
	  index--;
	  $(relative+" ul li#"+p_index+"-"+(index+elements_to_show)).fadeOut('fast', 
	  function()
	  {
	    $(relative+" ul li#"+p_index+"-"+(index)).fadeIn('fast',
	    function()
	    {
	      acabar=true;
	      eval(p_index+'--');
	    });
	  });
    }
  }
}

//<!-- INICIO OPTIMIZACION CARGA IMAGENES -->
//Función permite implementar el comportamiento de un array hash.
function CellHash() {
	this.length = 0;
	this.items = new Array();
	for (var i = 0; i < arguments.length; i += 2) {
		if (typeof(arguments[i + 1]) != 'undefined') {
			this.items[arguments[i]] = arguments[i + 1];
			this.length++;
		}
	}

	this.getItem = function(in_key) {
		return this.items[in_key];
	}

	this.setItem = function(in_key, in_value) {
		var tmp_previous;
		if (typeof(in_value) != 'undefined') {
			if (typeof(this.items[in_key]) == 'undefined') {
				this.length++;
			}
			else {
				tmp_previous = this.items[in_key];
			}

			this.items[in_key] = in_value;
		}
	   
		return tmp_previous;
	}
}
//Función recorre las capas (DIV) cuya clase es grupo_serie.
//Para cada capa que estéisualizada, obtiene su id numéco.
//A partir de este id numéco podremos acceder a la tabla hash que contiene los src de las imánes pertenecientes a esa capa.
function showSecondTabActivo(){

	var gruposSerie = jQuery("div.grupo_serie");
	
	$.each(gruposSerie, function(indice, valor) { 

		var display = jQuery(valor).css("display");
		if (display == null || display == "none") return true;	//Avanzamos a la siguiente iteració			
		var idGrupo = jQuery(valor).attr("id");
		if (idGrupo == null) return true;
		var a_id = idGrupo.split("-");
		var secondTabId = a_id[2];
		//Visualizamos las imánes del second-tab seleccionado. 					
		setSecondTabImgs(secondTabId);
	});	
}

//Esta función permite establecer los src de los objetos imánes (<IMG>) que estáen la pestañndicada por secondTabId
//secondTabId se correponde con la parte numéca del id (second-tab-XX) asginado a cada pestañdiv.grupo_serie)
function setSecondTabImgs(secondTabId){
	
	if (secondTabId == null) return;
		
	var src_imagenes = imagesCellHash.getItem(secondTabId);		
	if (src_imagenes == null) return;

	for (var i in src_imagenes.items){
	
		if (i == null || i == "indexOf") continue; 	//Arreglo para que funcione en IE6.0.
			
		var src_img = jQuery("#"+i).attr("src");					
		if (src_img == null) break;
		//Si no encontramos empty.gif es porque ya se ha asignado el src => La imagen ya tiene su src.
		if (src_img.toLowerCase().indexOf("/assets/empty.gif") == -1) break;
		
		//Sustituimos el valor inicial empty.gif por el src real de la imagen.
		jQuery("#"+i).attr("src", src_imagenes.items[i]);
	}
}
//<!-- FIN OPTIMIZACION CARGA IMAGENES -->

function show_second_tab(p_id)
{
  $("div#scroll_video_nav ul li").removeClass();
  $("div.grupo_serie:visible").fadeOut('slow', 
    function()
	{
     	//<!-- INICIO OPTIMIZACION CARGA IMAGENES -->
	setSecondTabImgs(p_id);
	//<!-- FIN OPTIMIZACION CARGA IMAGENES --> 
	$("div.grupo_serie#second-tab-"+p_id).fadeIn('slow');
      	$("div#scroll_video_nav ul li#index_videos-"+p_id).attr('class','selected');
    }
  );
}

function mostrar_toolbar(p_id)
{
  array_capas = new Array ("comment_video","send_video", "link_video", "fav_video", "code_video");
  for (i=0;i<array_capas.length;i++)
  {
    if (array_capas[i]!=p_id)
	{
	  $("#"+array_capas[i]+":visible").fadeOut('fast');
	}
  }
  $("#"+p_id).fadeIn('fast');  
}

function ocultar_toolbar(p_id)
{
  $("#"+p_id+":visible").fadeOut('fast');  
  //$("#about_video").fadeIn('fast');  
}

function mostrar_toolbar2(p_id)
{
  array_capas = new Array ("comment_video","send_video", "link_video", "fav_video", "code_video");
  for (i=0;i<array_capas.length;i++)
  {
    if (array_capas[i]!=p_id)
	{
	  $("#"+array_capas[i]+":visible").fadeOut('fast');
	}
  }
  $("#"+p_id).fadeIn('fast');
	$("#donde_buscar").css("visibility","hidden");  
}

function ocultar_toolbar2(p_id)
{
  $("#"+p_id+":visible").fadeOut('fast');  
  $("#donde_buscar").css("visibility","visible");  
  //$("#about_video").fadeIn('fast');  
}

function show_parrilla(){

//$(".parrilla").load("parrilla.html");
$(".parrilla").show();
$("#parrilla").show();

}
function display_tab(id,item){
	$("ul.listado").hide();
	$("ul#lista-"+id).show();
	$("div.yo_menu ul li").removeClass();
	$("#"+item).addClass("select")
}
function display_tab2(id,item){
	$("div.bot_corner_efect ul").hide();
	$("ul#"+id).show();
	$("div.options ul li").removeClass();
	$("#"+item).addClass("select")
}

function capa_rss(item){
	$(".feed_links:visible").hide();
	$("#"+item).show();
	//$("#"+item).css("z-index","9999");
	//$("#capa_alpha").show();

}

function cerrar_rss(item){
	$("#"+item).hide();
	//$("#capa_alpha").hide();
}

function selectItem(id) {
	var liElement = document.getElementById('cell_'+id);
	if (liElement) {
		//highlight the selected video
		liElement.setAttribute('class','video_on'); //for Mozilla, Opera, ...
		liElement.setAttribute('className','video_on'); //for IE
	}
}


function paginaInicio(id)
{
	if (navigator.appName=="Microsoft Internet Explorer")
	{
		var homepage = window.location.href;
		id.style.behavior='url(#default#homepage)';id.setHomePage(homepage);
	}
	else
	{
		alert ("Presiona Crtl+D para agregar esta web a tus Favoritos"); 
	}
}
