/*
* Mediante esta función recuperamos el siguiente elemento del tagline
* Parametres:
* id: identificador del Tagline, per si hi ha m'es d'un tagline en una página
* objetocur: objecte del que volem agafar el següent element
*/
function next(id,objetocur) {
  var cur = objetocur;
	cur.fadeOut( 1000 );
	// Si hemos llegado al final
  if ( cur.attr('class') == 'last' )
	  // cogemos el primer elemento
		cur = $('#tagline'+id+' li:first');
	else
	  // sino cogemos el último
		cur = cur.next();
	cur.fadeIn( 1000 );
	

}

/*
* Mediante esta función iniciamos la animacion del tagline
*/
function animate(id,objetocur) {
  var cur = objetocur;
  cur.fadeOut( 1000 );
  // si estamos en el último elemento
  if ( cur.attr('class') == 'last' ){
    // vamos al primero
    cur = $('#tagline'+id+' li:first');
  } else {
    //sino cogemos el siguiente
 		cur = cur.next();
   }
      
  	cur.fadeIn( 1000 );
  	
  return cur;
  }

function animateButtons(id,objetoPunt){
  var curPunt = objetoPunt;
  if(curPunt.attr("class") == 'last_puntos'){
    var img = curPunt.children().children();
    img.attr("src","http://www.esade.edu/itemsweb/web2010/imagenes/puntogris.png"); 
    curPunt = $("#tagline_button"+id+" li:first");
    img = curPunt.children().children();
    img.attr("src","http://www.esade.edu/itemsweb/web2010/imagenes/puntogris_on.png"); 
  } else {
	  var img = curPunt.children().children();
	  img.attr("src","http://www.esade.edu/itemsweb/web2010/imagenes/puntogris.png");
	  curPunt = curPunt.next();
	  img = curPunt.children().children();
	  img.attr("src","http://www.esade.edu/itemsweb/web2010/imagenes/puntogris_on.png");  
  }
  return curPunt;
}

/*
* Mediante esta función mostramos la imagen que nos pasan clicando los botones
* de abajo del tagline
*/
function mostraFoto(numFoto, ident,objetocur){
  var i = 0;
  var act = $('#tagline'+ident+' li:first');
  var cur = objetocur;
  while (act.attr('id') != 'tagline_img' + numFoto) {
   //alert(''[cur, numFoto] = [''+cur.attr(''id'') + '', '' + numFoto+'']'');
    if ( act.attr('class') == 'last' )
      act = $('#tagline'+ident+' li:first');
    else
      act = act.next(ident,objetocur);
    i++;
  }
  cur.fadeOut(1);
  cur = act;
  cur.fadeIn(1);
  return cur;
}

function mostraPunt(numFoto, ident, objetoPunt){
  var i = 0;
  var act = $('#tagline_button'+ident+' li:first');
  var cur = objetoPunt;
  var trobat = false;
  var ret;
  while (!trobat) {
    var img = act.children().children();
    if (img.attr("src") == "http://www.esade.edu/itemsweb/web2010/imagenes/puntogris_on.png"){
      img.attr("src","http://www.esade.edu/itemsweb/web2010/imagenes/puntogris.png");
    }
    if (act.attr("id") == "tagline_img_button"+numFoto){
      img.attr("src","http://www.esade.edu/itemsweb/web2010/imagenes/puntogris_on.png");
      ret = act;
    } 
    
    if (act.attr('class') == 'last_puntos')
      trobat = true;
    else
      act = act.next();
  }
  return ret;

}




/*    if ( img.attr('src') == "http://itemsweb.esade.edu/web2010/imagenes/puntogris_on.png" ){
      img.attr("src","http://itemsweb.esade.edu/web2010/imagenes/puntogris.png")
      if (act.attr("class") == "last"){
        act = $('#tagline_button'+ident+' li:first');
      } else{
        act = act.next();
      }
      img = act.children().children();
      img.attr("src","http://itemsweb.esade.edu/web2010/imagenes/puntogris_on.png");
      trobat = true;
    } else {
      act = act.next();
    }*/

