(function($) {
  var element;
  
  $.fontAvailable = function(fontName) {
    var width, height;
    
    // prepare element, and append to DOM
    if(!element) {
      element = $( document.createElement( 'span' ))
          .css( 'visibility', 'hidden' )
          .css( 'position', 'absolute' )
          .css( 'top', '-10000px' )
          .css( 'left', '-10000px' )
          .html( 'abcdefghijklmnopqrstuvwxyz' )
          .appendTo( document.body );
    }
    
    // get the width/height of element after applying a fake font
    width = element
      .css('font-family', '__FAKEFONT__')
      .width();
    height = element.height();
    
    // set test font
    element.css('font-family', fontName);
    
    return width !== element.width() || height !== element.height();
  }
})(jQuery);

function initCufon() {
  $(document).ready(function() {
    $('body').addClass('cufon-enabled');
  });
  Cufon.replace('h2:not(.search .results h2), #search label');
  Cufon.replace('#navigation a', { textShadow: '#fff 1px 1px' });
}

function supportsTextShadow() {
  if ($.browser.safari)
    return true;
  
  if ($.browser.mozilla) {
    var valid  = '1.9.1'.split('.'),
        actual = $.browser.version.split('.');
    for (var i = 0; i < valid.length; i++) {
      if (parseInt(actual[i]) < parseInt(valid[i]))
        return false;
    }
    return true;
  }
  
  return false;
}

if (supportsTextShadow()) {
  $(document).ready(function() {
    if(!$.fontAvailable('Gill Sans'))
      initCufon();
  });
} else
  initCufon();

// Re-bind close.facebox to show the Splash page
$(document).bind('close.facebox', function() {
        $('#splash').show();
        $(document).unbind('keydown.facebox')
        $('#facebox').fadeOut(function() {
            $('#facebox .content').removeClass().addClass('content')
            $('#facebox .loading').remove()
        })        
});


$(document).ready(function() {
    $('a[rel=facebox]').click(function() {
		if($.browser.msie) {
			$('#splash').hide(); // Hide the Splash in IE
		}
	}).facebox();

    $('a[rel*=ifacebox]').click(function() {
		if($.browser.msie) {
			$('#splash').hide(); // Hide the Splash in IE
		}    
        $.facebox('<iframe src="' + this.href + '?facebox=true" width="658" height="458"></iframe>');
        return false;
    });
 

    $('input[placeholder], textarea[placeholder]').example(function() {
        return $(this).attr('placeholder');
    });
});