/**
 * Carga la galeria de imagenes para el item
 */
$().ready( function() {
  // Carga Galeria Thumbs
  if($("#galleryThumb").length) {
    createGalleryThumb();
  }

  // Carga Galeria Item Page
  if($("#galleryItemPage").length) {

  }

  // Carga Galeria Photo Page
  if($("#galleryPhotoPage").length) {

  }
});

// Arma Thumbs
function createGalleryThumb() {
  s = $("#galleryThumb div.img").length;
  wTot = $("#galleryThumb div.img").width() * s; //calcula el tamano del slider
  // @TODO: El tamano esta por css a 100, pasarlo a dinamico
  //$("#galleryThumbSlider").width(wTot + (s*6)); //setea el slider al tamano total
  w = $("#galleryThumb div.img").width() + 6;
  
  ts = s-1; //total de imgs
  t = 0; //img actual

  // Setea el contador HTML
  $("#galleryTotal").html(s);
  $("#galleryCount").html(t+1);

  // Boton prev listener
  $("#prev").mouseover(function() {
    $("#prev").addClass("prevHover");
    $("#prev").removeClass("prev");
  });

  $("#prev").mouseout(function() {
    $("#prev").addClass("prev");
    $("#prev").removeClass("prevHover");
  });

  // Boton next listener
  $("#next").mouseover(function() {
    $("#next").addClass("nextHover");
    $("#next").removeClass("next");
  });

  $("#next").mouseout(function() {
    $("#next").addClass("next");
    $("#next").removeClass("nextHover");
  });

  $("#next").click(function() {
    animate("next");
  });

  $("#prev").click(function() {
    animate("prev");
  });
}

function animate(dir){
  if(dir == "next") {
    t = (t>=ts) ? 0 : t+1; // para stopear: primera cond = ts
  } else {
    t = (t<=0) ? ts : t-1; // para stopear: primera cond = 0
  }
  $("#galleryCount").html(t+1);
  p = (t * w * - 1);
  $("#galleryThumbSlider").animate({ marginLeft: p }, 100);
}

