jQuery(document).ready(function(){
  // Hover do balloon de mais informacoes
  jQuery(".plus_description").hover(function(){
    jQuery(this).find(".balloon_description").fadeIn(200);
  }, function(){
    jQuery(this).find(".balloon_description").fadeOut(100);
  });

  // Acao do botao de mais detalhes
  jQuery(".plus_description").click(function(){

    });
  // mostra o primeiro job
  jQuery(".image_container").children(".job_image").each(function(){
    if(jQuery(this).is(":first-child")){
      jQuery(this).show();
    }
  });
  jQuery(".job_description_highlight").children(".container_job").each(function(){
    if(jQuery(this).is(":first-child")){
      jQuery(this).show();
    }
  });

  jQuery(".job_arrow").click(function(){
    if(jQuery(this).hasClass("right")){
      jQuery(".image_container").children(".job_image").each(function(){
        if(jQuery(this).is(":visible")){
          findRel = parseFloat(jQuery(this).attr("rel")) + 1;
          lastRel = jQuery(".image_container").children(":last-child").attr("rel");
          findLastRel = findRel+1
          if(findRel == lastRel) {
            return false;
          }
          else {
            jQuery(this).animate({
              left: "-680"
            }, function(){
              jQuery(this).hide();
            });
          }
        }
      });

      jQuery(".job_image[rel='"+findRel+"']").show().css("left", 680).animate({
        left: 10
      });
      jQuery(".job_arrow.right").attr("href", "#jobs/" + findRel);
      prevRel = findRel-1;
      jQuery(".job_arrow.left").attr("href", "#jobs/" + prevRel);
      jQuery(".container_job[rel='"+findRel+"']").show().siblings().hide();

    } else {
      jQuery(".image_container").children(".job_image").each(function(){
        if(jQuery(this).is(":visible")){
          findRel = parseFloat(jQuery(this).attr("rel")) - 1;
          if(findRel <= 0) {
            return false;
          }
          else {
            jQuery(this).animate({
              left: 680
            }, function(){
              jQuery(this).hide();
            });
          }
        }
      });
      jQuery(".job_image[rel='"+findRel+"']").show().css("left", "-680").animate({
        left: "10"
      });
      jQuery(".job_arrow.right").attr("href", "#jobs/" + findRel);
      if(findRel <= 1){
        prevRel = 1;
      } else {
        prevRel = findRel;
      }
      jQuery(".job_arrow.left").attr("href", "#jobs/" + prevRel);
      jQuery(".container_job[rel='"+findRel+"']").show().siblings().hide();
    }
  });
});

// Backbone routing

var AppRouter = Backbone.Router.extend({
  routes: {
    "*actions": "defaultRoute" // matches http://example.com/#anything-here
  },
  defaultRoute: function( actions ){
    // The variable passed in matches the variable in the route definition "actions"
    jobNumber = actions.split("/")[1];
    switch(actions) {
      case "jobs" :
        jQuery("#portfolio_content").ready(function(){
          jQuery("#pontfolio_content_jobs").show();
          jQuery("#pontfolio_content_jobs").show().siblings().hide();
        });
        break;
      case "jobs/"+jobNumber :
        jQuery("#portfolio_content").ready(function(){
          if(jQuery("#pontfolio_content_jobs").is(":hidden")){
            jQuery("#pontfolio_content_jobs").show().siblings().hide();
            jQuery(".job_image[rel='"+jobNumber+"']").show().siblings().hide();
            jQuery(".container_job[rel='"+jobNumber+"']").show().siblings().hide();
          }
        });
        break;
      case "info" :
        jQuery("#portfolio_content").ready(function(){
          if(jQuery("#pontfolio_content_info").is(":hidden")){
            jQuery("#pontfolio_content_info").show().siblings().hide();
          }
        });
        break;
      case "contact" :
        jQuery("#portfolio_content").ready(function(){
          if(jQuery("#pontfolio_content_contact").is(":hidden")){
            jQuery("#pontfolio_content_contact").show().siblings().hide();
          }
        });
        break;
      default:
        jQuery(document).ready(function(){
          jQuery("#pontfolio_content_jobs").show();
        });
        break;
    }
  }
});
// Initiate the router
var app_router = new AppRouter;
// Start Backbone history a neccesary step for bookmarkable URL's
Backbone.history.start();
