var curpost = -1;
var base = "http://joshpyles.com/";
var pageURL = "page/";
var posts;

$(function(){
  $(".partner").hover(function(){
    $(this).find(".title").fadeIn("fast");
  }, function(){
    $(this).find(".title").fadeOut("fast");
  });
  
  posts = $(".post").get();
  
  $.mapKey("down", nextPost);
  $("li.next a").mapKey("right");
  $("li.prev a").mapKey("left");
  $.mapKey("up", prevPost);
  
});

function nextPost(){
  if(curpost >= (posts.length-1)){
    //we're at the last post
    //go to the next page instead
    window.location = $(".next a").attr("href");
  }else{
    curpost++;
    $.scrollTo(posts[curpost], {duration: 300});
  }
}

function prevPost(){
  if(curpost <= 0){
    //we're at the first post
    //go back a page
    window.location = $(".prev a").attr("href");
  }else{
    curpost--;
    $.scrollTo(posts[curpost], {duration: 300});
  }
}

function nextPage(){
  var loc = window.location;
  var page = loc.pathname.split("/");
  var page = page[page.length-1];
  if(page == undefined){
    page = 1;
  }
  page++;
  window.location = base+pageURL+page;
}

function prevPage(){
  var loc = window.location;
  var page = loc.pathname.split("/");
  page = page[page.length-1];
  if(page == undefined){
    page = 1;
  }else{
    page--;
    window.location = base+pageURL+page; 
  }
}