$(document).ready(function(){
  prepararSite();
  projetosJSON = $.post("JsonEngine.asp", null, function(data, msg){
    projetosReais = data.projetos;
    init();
  }, "json");
});

function getJobs(){
  var jobHTML = "";
  for(j in projetoSelecionado.jobs){
    jobHTML   += "\n\n<li class='job'>";
    jobHTML   += "\n<div class='imagem'></div>";
    jobHTML   += "\n<div class='desnivel'></div>";
    jobHTML   += "\n<div class='descricao'><p>"+projetoSelecionado.jobs[j].descricao+"</p></div>";
    jobHTML   += "\n</li>\n";
  }
  return jobHTML;
}

function getThumbs(){
  var thumbHTML = "";
  for(j in projetoSelecionado.jobs){
    thumbHTML += "\n<li class='imagem'><img src='images/projetos/thumbs/"+projetoSelecionado.jobs[j].imagem.thumb+"'/></li>";
  }
  return thumbHTML;
}

$.fn.loadJobsImages = function(){
  var index = $(this).index();
  var imageData = projetoSelecionado.jobs[index].imagem;
  var image = $("<img style='top:0' height='"+imageData.altura+"' src=images/projetos/grandes/"+imageData.full+" class='grande' />");
  
  image.appendTo(this.find(".imagem")).hide().load(function(){

    if(index-1 == jobInicial) $(".thumbs .imagem").eq(jobInicial).click();
    $(this).pilotView().jobView();
    projetoSelecionado.jobs[index].imagem.loaded = true;
      $(this).stop(true, false).fadeIn(200, function(){
        if(index !== projetoSelecionado.jobs.length-1){
          $(".job").eq(index+1).loadJobsImages();
        } else {
          if(index==0) $(".thumbs .imagem").eq(jobInicial).click();
        }
      });
  });

  // $(".job img").eq(jobSelecionado).stop(true, true).jobView().parent().parent().animate({opacity: 1}, 200);

}
