$(document).ready(function(){
  
  // Transitions & effects
  // Logo  
  if(!$.browser.msie){
    $("#logo").attr("href","javascript:;");
    $("#logo").hover(
      function(){
        if(!$(this).hasClass("active")){
          $(this).addClass("active");
          $(this).fadeTo('fast',0.8);
        }
      },
      function(){
        if($(this).hasClass("active")){
          $(this).fadeTo('slow',1,function(){$(this).removeClass("active");});
        }
      }
    );
  }
  
  
  // Project images
  $("#project img").css("opacity",0.8);
  $("#project img").hover(
    function(){
      if(!$(this).parent().parent().hasClass("h_active")){
        $(this).parent().parent().addClass("h_active");
        $(this).parent().parent().find(".project_description").slideDown('slow');
        $(this).fadeTo('fast',1);
      }
    },
    function(){
      if($(this).parent().parent().hasClass("h_active")){
        $(this).fadeTo('slow',0.8,function(){$(this).parent().parent().removeClass("h_active");});
        $(this).parent().parent().find(".project_description").slideUp('fast');
      }
    }
  );
  
  
  // Pager
  var active_project = 1;
  var nr_of_projects = $("#project").children().size();

  $(".pager").click(function(){

    if($(this).hasClass("next") && Number($("#project_"+active_project).attr("id").replace("project_",""))==nr_of_projects){
      active_project=1;
    }else if($(this).hasClass("next")){
      active_project++;
    }
    if($(this).hasClass("prev") && Number($("#project_"+active_project).attr("id").replace("project_",""))==1){
      active_project=nr_of_projects;
    }else if($(this).hasClass("prev")){
      active_project--;
    }
    $("#project .active").fadeOut('fast',function(){$(this).removeClass("active");});
    $("#project_title").html($("#project_"+active_project+" h2").html());
    $("#project_"+active_project).fadeIn('slow',function(){$(this).addClass("active");});
  });
  
  
  // Positioning
  var vp_width = $(window).width();
  var vp_height = $(window).height();
  
  $("section").addClass("positioned");
  $("#projects").css("left",vp_width+"px");
  $("#contact").css("left",(vp_width*2)+"px");
  
  
  // Scrolling  
  $("nav a").click(function(e){
    e.preventDefault();
    var target = $(this).attr("href");
    $("#wrapper").scrollTo(target,1000);
  });
  
  
  // Links
  $("#project a").attr("target","_blank");  
 
});

function load_project(project){
  $("#project_title").html(project.title+" <span>"+project.subtitle+"</span>");
  $("#project").html(project.description);
}