Cufon.replace('.box .left p, .newsletter .left label, #ancillary li a, #nav li a', { fontFamily: 'CgEgyptian' });
Cufon.replace('h2, .post h3, .about .content h3, .general .inner h3, .comments h5, #footer h3, .contact .form h3, .newsletter .content p, .newsletter .left h3', { fontFamily: 'CgEgyptianLt' });
Cufon.replace('.box .right .twitter p, .contact label, .contact .form div', { fontFamily: 'CgEgyptianMd', hover: true });
Cufon.replace('.post .content h2, .box h3, .box .follow, .post .content .date, #nav li.active a', { fontFamily: 'CgEgyptianBd' });
Cufon.replace('.box .follow, .post .comments .inner .toggle', { fontFamily: 'CgEgyptianBd' });

$(document).ready(function() {
  $('.comments .toggle').click(function() {
    $(this).parents('.comments').find('.inner').slideToggle();

    return false;
  });
  
  $('.addcomment').click(function() {
    $(this).parents('.post').find('.comments .inner').slideDown('normal', function() {
      scrollToElement($(this).find('form'));
      $(this).find('form input:first').focus();
    });
    
    return false;
  });
  
  $('.linkedinput input').focus(function() {
    $(this).parent().find('label').hide();
  });
  
  $('.linkedinput input').blur(function() {
    if ($(this).val() == '') {
      $(this).parent().find('label').show();
    }
  });
  
  $('.linkedinput input').each(function (idx, element) {
    if ($(this).val() != '') {
      $(this).parent().find('label').hide();
    }
  });
  
  $('.post').each(function(idx, element) {
    var $post = $(element);
    
    if (!$post.hasClass('single')) {
      var $text = $post.find('.text');
      var $inner = $text.find('.inner');
      
      if ($inner.innerHeight() > 217) {
        $text.find('.readmore').show();
        $text.find('.fade').show();
        
        $inner.css({
          height: '217px'
        });
      }
    }
  });
  
  $('a.modal').nyroModal({
    forceType: 'image'
  });
  
  $('.print').click(function() {
    if ($(this).parents('.cell').find('.readmore').is(':visible')) {
      window.location = $(this).attr('href') + '?print=true';
    } else {
      window.print();
    }
    
    return false;
  });
});

var scrollToElement = function(element, offset)
{
  if (!offset) {
    offset = 40;
  }
  
  if (element) {
    var targetOffset = element.offset().top - offset;
    $('html,body').animate({scrollTop: targetOffset}, 1000);
  }
  return false;
}

var scrollTo = function(id, offset) {
  if (id.substring(0, 8) == '#jumpto-') {
    id = '#' + id.substring(8, id.length);
  }

  return scrollToElement($(id), offset);
};
