/* Author: Collin Reisdorf
  
*/
$(function(){
  if($('.tab_content').length > 0)  createTabs('#tab_blocks');
  getBlogFeed(1);
  
  // email deobfuscator
  $('.ob_email').each(function(){
    var $this = $(this);
    $this.html('<a href="mailto:'+$this.text().split(' at ').join('@')+'">'+$this.text().split(' at ').join('@')+'</a>')
  })
  console.log($('.ob_email').text());
});

/*
  Adds the blog feed to the footer on all pages.
  
  @param length The number of entries to add.
*/
function getBlogFeed(length)
{
  $('#blog_feed').rssfeed('http://blog.modk.it/rss.xml', {
    limit: length,
    date:false,
    titletag:'h5',
    errormsg:'<h4>Modkit Blog</h4><h5>Oh Snap!</h5><p>Unable to load the Modkit Blog right now. Please check back later.<p>'
  });
}

/*
  Creates working tabs on project and example pages.
  Code snagged from: http://www.sohtanaka.com/web-design/simple-tabs-w-css-jquery/
*/
function createTabs(firstTab)
{
  if(!firstTab) firstTab = 'li:first';
  
  //On Click Event
  $('ul.tabs li').click(function() {

    $('ul.tabs li').removeClass('active'); //Remove any 'active' class
    $(this).addClass('active'); //Add 'active' class to selected tab
    $('.tab_content').hide(); //Hide all tab content

    var activeTab = $(this).find('a').attr('href'); //Find the href attribute value to identify the active tab + content
    $(activeTab).fadeIn(); //Fade in the active ID content
    return false;
  });
  
  //When page loads...
  $('.tab_content').hide(); //Hide all content
  $('ul.tabs '+firstTab).addClass('active').show().click();
}
