/**
 * Created by IntelliJ IDEA.
 * User: Chris
 * Date: 1/3/12
 * Time: 1:31 PM
 * To change this template use File | Settings | File Templates.
 */


(function() {
      
   /* Hide content while attempting to load fonts. */
   $('html').css('visibility','hidden');

   $(document).ready( function() {
      
      /* Email links: sneakily alter the link */
      $(".email-link").attr("href", "mailto:chris@chriskrycho.com");
      
      /* Generate the Typekitify bookmarklet */
      $('.generator').submit( function (e) {
         e.preventDefault();
         $name = $('#submit').attr('value');
         $action = $(this).attr('action');
         $.post(
            $action,
            $('.generator').serialize(),
            function(data) {
               if (data) {
                  $bookmarklet = '<div class="overlay">';
                  $bookmarklet += '<a href="#" class="overlay-closer">x</a>';
                  $bookmarklet += '<a class="bookmarklet" href="' + data + '">' + $name + '</a>';
                  $bookmarklet += '<p>Drag me to your bookmarks bar!</p>';
                  $bookmarklet += '</div>';
                  $('body').prepend($bookmarklet).find('.overlay-closer').click(function(e) {
                     e.preventDefault();
                     $('.overlay').fadeOut(270);
                     setTimeout(
                        function() {
                           $('.overlay').remove();
                        },
                        270
                        );
                  });
                  $('.overlay').hide().fadeIn(270);
               }
            }
         );
      });
      
   });
   
   /* Attempt to load Typekit fonts */
   try {
      Typekit.load({
         active: function() {
            if (jQuery.support.opacity) {
               $(document).ready( function() { // because Chrome started loading differently 
                  $('html').css('visibility', 'visible').hide().fadeIn(750);
               });
            } else {
               $(document).ready( function() {
                  $('html').css('visibility', 'visible');
               });
            }
            $().ligatureTest();
         },
         inactive: function() {
            $(document).ready( function() {
               $('html').css('visibility', 'visible');
            });
            $().ligatureTest();
         }
      })
   } catch(e) {}
   
}) ();
