$(document).ready(function(){
  
  Cufon.replace('h2#callout-sub a, #major .case-studies h2 a, .entry h2, .entry h2 a, .entry-detail h2', { 
    fontFamily: 'Akzidenz-Light',
    hover: {
      color: '#000000'
	}
  });
  Cufon.replace('h1#callout, #foot-forms h2, #minor h2, #error h2, #default #case-studies h2, #tweets h3, h1, #previews h2, #comments h2, #minor h3, #major .entry h3, #major .entry-detail h3', { 
    fontFamily: 'Akzidenz-Light'
  });
  Cufon.replace('.skybox .entry h2, #head p#phone', {  
    fontFamily: 'Akzidenz-Medium'
  });

  $('.skybox a.trigger').live('click', function () {
    var _this = $(this);
    $(_this).toggleClass('open');
    if($(_this).hasClass('open')) {
      $(_this).text("- Close");
      $(_this).parent().stop().animate({
        left: "0px",
        width: "928px"
      }, 750).css("zIndex","100")
    } else {
      $(_this).text("+Details");
      $('.one').stop().animate({
        width: "288px"
      }, 250, function() {
        $(this).css("zIndex","")
      });
      $('.two').stop().animate({
        width: "288px",
        left: "320px"
      }, 250, function() {
        $(this).css("zIndex","")
      });
      $('.three').stop().animate({
        width: "288px",
        left: "640px"
      }, 250, function() {
        $(this).css("zIndex","")
      })        
    }
  });
  
  $("#tweets").tweet({
    username: "metzconsulting",
    avatar_size: 0,
    count: 4,
    loading_text: "loading tweets..."
  });
  
  $('form#metz-code input').focus(function(){
    $(this).parent().parent().parent().css({
      backgroundImage: "url(/i/bg-metz-code-ring.gif)"
    });
  });

  $('form#metz-code input').blur(function(){
    $(this).parent().parent().parent().css({
      backgroundImage: "url(/i/bg-metz-code.gif)"
    });
  });

  // Store lightbox
  
  $("#previews").each(function() {
    $(this).find('a').lightBox({imageLoading:'../i/lightbox-ico-loading.gif',imageBtnClose:'../i/lightbox-btn-close.gif',imageBtnPrev:'../i/lightbox-btn-prev.gif',imageBtnNext:'../i/lightbox-btn-next.gif',imageBlank:'../i/lightbox-blank.gif'});
  });
  

  // Anchor link smooth scrolling

  $('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
    && location.hostname == this.hostname) {
      var $target = $(this.hash);
     $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
      if ($target.length) {
        var targetOffset = $target.offset().top;
        $('html,body').animate({scrollTop: targetOffset}, 1000);
        return false;
      }
    }
  });

  // Slide Toggle
  
  $('.toggle').click(function() {
    var entry = $(this).parent().children('span');
    var text = $(this).text();
    if ($(entry).is(':hidden')) {
      $(this).html('Hide details &times;');
    } else {
      $(this).html('Show details &darr;');
    }
    $(entry).slideToggle();
  });  
  
  // search for text replacement
  
  var value = $('#search_form input').val();
  $('#search_form input').focus(function () {
    $(this).val('');
  });
  $('#search_form input').blur(function () {
    $(this).val(value);
  });  
  
});
