/**************************************************************************/
/************** Fotogaleria creada por Telémaco Sistemas S.L **************/
/**************************************************************************/

var g_img=0;
var g_num=0;
var g_panelUlt=g_imgpanel=9;
var g_panelPri=0;
var g_load=0;
var g_time=1000;
var g_play=0;

function muestraImg(id)
{
  if(g_load)
    return;
  
  g_load=1;
  controlador_panel();
  
  /*var img_ocultar = document.getElementById("img_"+g_img).style;
  img_ocultar.display = "none";  */  
  ocultar_img();
  
  
  document.getElementById("pie_"+g_img).style.display = "none";    
 
  var num_img_ant = document.getElementById("num_img_"+g_img).style;
  num_img_ant.backgroundColor = "#fff";      
  num_img_ant.color = "#999";  

  var num_img_ant2 = document.getElementById("num_img2_"+g_img).style;
  num_img_ant2.backgroundColor = "#fff";      
  num_img_ant2.color = "#999";
  
  g_img = id;

  Effect.Appear("img_"+id);  
  document.getElementById("pie_"+id).style.display = "";

  var num_img = document.getElementById("num_img_"+id).style;
  num_img.backgroundColor = "#990000";      
  num_img.color = "#fff";  
  
  var num_img2 = document.getElementById("num_img2_"+id).style;
  num_img2.backgroundColor = "#990000";      
  num_img2.color = "#fff";    
}

function muestraImgSig(id)
{                
  if(g_load)
    return;
  
  g_load=1;  
  controlador_panel();
  
  /*var img_ocultar = document.getElementById("img_"+g_img).style;
  img_ocultar.display = "none";*/
  ocultar_img(); 
  
  document.getElementById("pie_"+g_img).style.display = "none";    


  var num_img_ant = document.getElementById("num_img_"+g_img).style;
  num_img_ant.backgroundColor = "#fff";      
  num_img_ant.color = "#999";  
  
  var num_img_ant2 = document.getElementById("num_img2_"+g_img).style;
  num_img_ant2.backgroundColor = "#fff";      
  num_img_ant2.color = "#999";  
  
  if(!id){
    g_img=0;
  }  
    
  if(g_img==g_num-1 && id>0)
    g_img=id=0;
  else
    id = g_img += id;
    
  if(g_img==-1){
    g_img=id=g_num-1;
  }    

  Effect.Appear("img_"+id);
    
  document.getElementById("pie_"+id).style.display = "";    

  var num_img = document.getElementById("num_img_"+id).style;
  num_img.backgroundColor = "#990000";      
  num_img.color = "#fff";  
  
  var num_img2 = document.getElementById("num_img2_"+id).style;
  num_img2.backgroundColor = "#990000";      
  num_img2.color = "#fff";  
  
  if(g_img>=g_panelUlt)
    PanelControl(1);
  else if(g_img<g_panelPri)
    PanelControl(0);       
}

function ImgPlay(play)
{    

  if(g_load && g_load)
    return;
    
  g_play=1;
  g_load=1;
  controlador_panel();
          
  if(play==1){
    document.getElementById("btn_play").style.display = "none";
    document.getElementById("btn_stop").style.display = "";      
    document.getElementById("btn_play2").style.display = "none";
    document.getElementById("btn_stop2").style.display = "";          
  }  
  else if(!play){
    clearTimeout(timer); 
    g_play=1;
  }
    
  /*var img_ocultar = document.getElementById("img_"+g_img).style;
  img_ocultar.display = "none";  */
  ocultar_img();
  
  document.getElementById("pie_"+g_img).style.display = "none";
 
  var num_img_ant = document.getElementById("num_img_"+g_img).style;
  num_img_ant.backgroundColor = "#fff";      
  num_img_ant.color = "#999";   
  
  var num_img_ant2 = document.getElementById("num_img2_"+g_img).style;
  num_img_ant2.backgroundColor = "#fff";      
  num_img_ant2.color = "#999";    

 if(g_img==g_num-1){
    id=0;
    g_img=0;
  }
  else
    id = g_img +=1;    
  
  Effect.Appear("img_"+id);
  document.getElementById("pie_"+id).style.display = "";
  
  var num_img = document.getElementById("num_img_"+id).style;
  num_img.backgroundColor = "#990000";      
  num_img.color = "#fff";
  
  var num_img2 = document.getElementById("num_img2_"+id).style;
  num_img2.backgroundColor = "#990000";      
  num_img2.color = "#fff";  

  if(play)
    timer = setTimeout("ImgPlay(2)", 6000);
  else{
    document.getElementById("btn_play").style.display = "";
    document.getElementById("btn_stop").style.display = "none";      
    document.getElementById("btn_play2").style.display = "";
    document.getElementById("btn_stop2").style.display = "none";          
  }
  
  if(g_img>=g_panelUlt)
    PanelControl(1);
  else if(g_img<g_panelPri)
    PanelControl(0);    
}

function carga_fotogaleria(num, imgpanel){
  g_num = num;
  g_panelUlt = g_imgpanel = imgpanel;
  controlador_panel();
}

function PanelControl(polaridad){  
  if(polaridad){
    document.getElementById("num_panel_"+g_panelPri).style.display = "none";
    document.getElementById("num_panel_"+g_panelUlt).style.display = "";        
    document.getElementById("btn_menos").style.display = "";  
    document.getElementById("num_panel2_"+g_panelPri).style.display = "none";
    document.getElementById("num_panel2_"+g_panelUlt).style.display = "";        
    document.getElementById("btn_menos2").style.display = "";      
    
    if(g_panelUlt==g_num-1){
      document.getElementById("btn_mas").style.display = "none";
      document.getElementById("btn_mas2").style.display = "none";      
    }
    
    if(g_img==g_num-1){
      document.getElementById("btn_mas").style.display = "none";
      document.getElementById("btn_mas2").style.display = "none";      
      g_panelPri=g_num-g_imgpanel;
      g_panelUlt=g_num;
      
      for(var n=0;n<g_num;n++){
        if(n<g_panelPri){
	      document.getElementById("num_panel_"+n).style.display = "none";      
	      document.getElementById("num_panel2_"+n).style.display = "none";      	      
	    }
        else{
    	  document.getElementById("num_panel_"+n).style.display = "";                        
    	  document.getElementById("num_panel2_"+n).style.display = "";                        
    	}    	  
	  }
    }
    else{
      g_panelUlt++;
      g_panelPri++;
    }
  }
  else{
    if(g_img==0){
      g_panelPri=0;
      g_panelUlt=g_imgpanel;
      
      for(var n=0;n<g_num;n++){
        if(n<g_imgpanel){
    	  document.getElementById("num_panel_"+n).style.display = "";                
    	  document.getElementById("num_panel2_"+n).style.display = "";                    	  
    	}
        else{
	      document.getElementById("num_panel_"+n).style.display = "none";      
	      document.getElementById("num_panel2_"+n).style.display = "none";      	      
	    }
	  }
    }
    else{
      g_panelUlt--;
      g_panelPri--;
    }
    
    document.getElementById("num_panel_"+g_panelPri).style.display = "";
    document.getElementById("num_panel_"+g_panelUlt).style.display = "none";      
    document.getElementById("btn_mas").style.display = "";        
    
    document.getElementById("num_panel2_"+g_panelPri).style.display = "";
    document.getElementById("num_panel2_"+g_panelUlt).style.display = "none";      
    document.getElementById("btn_mas2").style.display = "";            
        
    if(!g_panelPri){
      document.getElementById("btn_menos").style.display = "none";
      document.getElementById("btn_menos2").style.display = "none";      
    }
  }    
}

function controlador_panel(){
  Element.show("loadpanel1");  
  window.setTimeout("Element.hide('loadpanel1')", g_time);    
  Element.show("loadpanel2");  
  window.setTimeout("Element.hide('loadpanel2')", g_time);
  window.setTimeout("g_load=0", g_time);
}

function ocultar_img(){
  for(var n=0;n<g_num; n++){
    if(document.getElementById("img_"+n)){
      document.getElementById("img_"+n).style.display = "none";
    }
  }
}
/***************************************************************/