$(function(){

  $.getFeed({
    url: '/encoder-blog/feed/',
    success: function(feed) {
      $("#blog_feed").html("")
      $(feed.items.slice(0,6)).each(function(){
        date = this.updated.split(" ")
        month = date[2].toUpperCase()
        day = Number(date[1])
        year = Number(date[3])
        $("#blog_feed").append('<tr><th>'+month+' '+day+', '+year+'</th><td><a href="'+this.link+'">'+this.title+'</a></td></tr>');
      })
    }
  });

  // Home Page
  if ($("#home").length > 0 && $(".main_feature").length > 1) {
    startMainFeatureRotator();
  }

})

function startMainFeatureRotator(){
  if($.browser.msie && $.browser.version < 7) return;
  setTimeout(function(){
    switchToNextFeature();
  }, 5000);
}

var currentMainFeature = 0;
function switchToNextFeature(){
  // IE does weird things with alpha shadow fading, so speed up fading
  fadeTime = ($.browser.msie) ? 50 : 400;
  $($(".main_feature")[currentMainFeature]).fadeOut(fadeTime, function(){
    $($(".main_feature")[getNextMainFeature()]).fadeIn(fadeTime);
  });
  startMainFeatureRotator();
}

function getNextMainFeature(){
  currentMainFeature = currentMainFeature + 1;
  if(currentMainFeature >= $(".main_feature").length) {
    currentMainFeature = 0;
  }
  return currentMainFeature;
}
