Cufon.replace('#navigation a, .highlight', { fontFamily: 'berthold' });

var title_general = "";

$(document).ready(function() {
  
  // Init
  title_general = document.title;
  $(".arrow").css("opacity",0.5);
  $("#references_carousel a").each(function(){
    $(this).attr("rel",$(this).attr("href"));
    $(this).attr("href","javascript:;");
  });
  // Arrows
  $(".arrow").hover(
    function(){
      $(this).fadeTo('fast',1);
    },
    function(){
      $(this).fadeTo('fast',0.5);
    }
  );
  
  $.localScroll.defaults.axis = 'x';
 
  $.localScroll.hash({
    target: '#content',
    queue:true,
    duration:1,
    onBefore:function( e, anchor, $target ){
     fix_nav(anchor);     
    }
  });
  
  $("#content").serialScroll({
    navigation: '#navigation a',
    items: '.content_block',
    prev: '.arrow_prev',
    next: '.arrow_next',
    easing: 'swing',
    onBefore:function( e, anchor, $target ){
     fix_nav(anchor);
    }
  });
  
  $.localScroll({
    target: '#content',
    queue:true,
    duration:1000,
    hash:true,
    prev: '.arrow_prev',
    next: '.arrow_next',
    easing: 'swing',
    onBefore:function( e, anchor, $target ){
     fix_nav(anchor);     
    }
  });
  
  $("#references_scroll a").css("opacity",0.5);
  $("#references_scroll a").hover(
    function(){
      $(this).fadeTo('fast',1);
    },
    function(){
      $(this).fadeTo('fast',0.5);
    }
  );
  $("#references_scroll a").click(function(){
    var target = $(this).attr("rel");
    $("#references .active").fadeOut('slow',function(){
        $(this).removeClass("active");
        $(target).fadeIn(2000,function(){
          $(this).addClass("active");
        });
    });
  });
});

function fix_nav(anchor){
  $("#navigation li").removeClass("active");
  $("#nav_item_"+anchor.id).addClass("active");
  var title_txt = $("#nav_item_"+anchor.id+" a").text();
  Cufon.replace('#navigation a', { fontFamily: 'berthold' });
  document.title = title_txt+ " | "+title_general;
  
  if(anchor.id=="references"){
    $("#references_carousel").slideDown('slow',function(){
      $(this).addClass("active");
      $("#references_scroll").scrollable();
    });
  }else if($("#references_carousel").hasClass("active")){
    $("#references_carousel").slideUp('fast',function(){
      $(this).removeClass("active");
    });
  }
}
