function introAnimation(){
  if (document.cookie.length>1) {
    if (document.cookie.indexOf("webskillet_visited=1") != -1) {
      $('#title-wrapper span').show();
      $('#title-wrapper #logo').show();
      $('#sidebar').show();
      var q = location.search;
      var page = q.slice(q.indexOf('=')+1);
      if ( (page == 'resume') || (page == 'portfolio') || (page == 'contact') ) {
        loadPage(page+'.html');
      }
      return true;
    }
  }
  if ( (navigator.platform == 'BlackBerry') || (navigator.platform == 'iPhone') ) {
    $('#title-wrapper span').show();
    $('#title-wrapper #logo').show();
    $('#sidebar').show();
    var q = location.search;
    var page = q.slice(q.indexOf('=')+1);
    if ( (page == 'resume') || (page == 'portfolio') || (page == 'contact') ) {
      loadPage(page+'.html');
    }
    return true;
  }
  $('#title-wrapper #web').fadeIn(400,function(){
    $('#title-wrapper #skillet').fadeIn(400,function(){
      $('#title-wrapper #dot').fadeIn(400,function(){
        $('#title-wrapper #com').fadeIn(400,function(){
          $('#title-wrapper #logo').fadeIn(400);
          $('#sidebar').slideDown(1500,function(){
            var q = location.search;
            var page = q.slice(q.indexOf('=')+1);
            if ( (page == 'resume') || (page == 'portfolio') || (page == 'contact') ) {
              loadPage(page+'.html');
            }
          });
        });
      });
    });
  });
  document.cookie='webskillet_visited=1';
};

function loadPage(page){
  $('#content').hide();
  $('#content').load(page+' #content-inner',function(){
    $('#content').slideDown(1500);
    if (page == 'contact.html') {
      $('#redirect').remove();
      $('form').submit(function(){
        var $form = $(this);
        var data = $form.serialize();
        var contentHTML = $('#content').html();
        $('#content').slideUp(800,function(){
          $.post($form.attr('action'), data, function (data, textStatus) {
            if (textStatus != 'success') {
              contentHTML = '<div class="message">Sorry, there was an error submitting the form.  Please try again.</div>'+contentHTML;
              $('#content').html(contentHTML);
              $('#content').slideDown(1500);
            } else {
              loadPage('thankyou.html');
            }
          });
        });
        return false;
      });
    }
  });
}

$(document).ready(function(){
  // Apply this code to each link with class="menu"
  $("a.menu").each(function (i){  
    // Add an onClick behavior to this link  
    $(this).click(function(event) {  
      // Prevent the browser's default onClick handler  
      event.preventDefault();
      loadPage($(this).attr("href"));
    });  
  }); 
});

$(window).load(function(){
  introAnimation();
});
