
var nom_generic_imatges = "BitxoPortadaImg";

function moviment(opcions){
  
  $('#'+opcions['nomCapa']).css('margin-left',opcions['marginLeftFinit']); 
  if(opcions['tipusMoviment']=="") opcions['tipusMoviment']="linear";
  $('#'+opcions['nomCapa']).animate({marginLeft: opcions['marginLeftInit']}, opcions['time'], opcions['tipusMoviment'] , function(){
    $('#'+opcions['nomCapa']).css('margin-left',opcions['marginLeftFinit']);     
       moviment(opcions);
  });
}



var options01 =
  {
    nomCapa:"BitxoPortadaText1",
    marginLeftInit: "-950px",
    marginLeftFinit: "950px",    
    tipusMoviment:'linear',
    time: 25000
  }
  
var options02 =
  {
    
    nomCapa:"BitxoPortadaText2",
    marginLeftInit: "950px",
    marginLeftFinit: "-950px",
    tipusMoviment:'linear',
    time: 25000
  }

var numero_imatge_portada = 1;
var numero_imatge_maxim = 0;
var imatge_fadeout =  1;
var imatges_a_mostrar=new Array();

function canvi_imatge_potrada () {
  
  //alert(numero_imatge_portada);
  numero_imatge_portada_mes = numero_imatge_portada + 1;
  numero_imatge_fitxer = numero_imatge_portada + 2;
  
  if(imatge_fadeout==1)
      imatge_fadeout_mes = 2;
    else
      imatge_fadeout_mes = 1;
  
  if(numero_imatge_fitxer>numero_imatge_maxim)
    numero_imatge_fitxer = numero_imatge_fitxer - numero_imatge_maxim;
  
  if(numero_imatge_portada==numero_imatge_maxim)
    numero_imatge_portada_mes = 1;  
  /*
  $('#tnumero_imatge_portada').html(numero_imatge_portada);
  $('#tnumero_imatge_portada_mes').html(numero_imatge_portada_mes);
  $('#tnumero_imatge_fitxer').html(numero_imatge_fitxer);
  */
  
  $('#'+nom_generic_imatges+imatge_fadeout).fadeOut(1500,function(){
    //alert(numero_imatge_fitxer);
    $('#'+nom_generic_imatges+imatge_fadeout).attr('src',imatges_a_mostrar[numero_imatge_fitxer]);
    $('#'+nom_generic_imatges+imatge_fadeout_mes).css('z-index','110');
    $('#'+nom_generic_imatges+imatge_fadeout).css('z-index','105');
    $('#'+nom_generic_imatges+imatge_fadeout).css('display','block');
    if(numero_imatge_portada==numero_imatge_maxim) 
      numero_imatge_portada = 1;
    else
      numero_imatge_portada ++;
    
    if(imatge_fadeout==1)
      imatge_fadeout = 2;
    else
      imatge_fadeout = 1;
  });
}

function count_images() {
  
  numero_imatge_maximX = 0 ;
 
  $('#BitxoPortadaLogosImatges .BitxoPortadaImgCount').each(function(){
    numero_imatge_maximX++;
    imatges_a_mostrar[numero_imatge_maximX] = $(this).attr('src');
  });
  numero_imatge_maxim = numero_imatge_maximX;
  return numero_imatge_maxim;
  
}

function tancar_ofertes() {
  if($('#ofertes').css('display')!='none') {
    $('#ofertes').fadeOut(function(){
      $('#ofertesVel').css('display','none');
    });
  }
}

jQuery(function($){
   count_images();
   
   $('#BitxoPortadaImg1').attr('src',imatges_a_mostrar[1]);
   $('#BitxoPortadaImg2').attr('src',imatges_a_mostrar[2]);
   
   moviment(options01);
   moviment(options02);
   setInterval('canvi_imatge_potrada()',6000);
   setTimeout('tancar_ofertes()',20000)
});

 

