(function($){
  if ($.browser.safari) {
    var onReady = $.fn.ready;
    $.fn.ready = function( obj ) {
      if (document.readyState !== 'complete') {
        setTimeout(function() {
          $.fn.ready( obj );
        }, 50);
      } else onReady( obj );
    }
  }
})(jQuery);


(function($){
  $.es = {

    setEqualHeight: function(columns) {
      var tallestcolumn = 0;
      columns.each(function() {
        currentHeight = parseInt($.css(this,'height'));
        if(currentHeight > tallestcolumn) {
          tallestcolumn = currentHeight;
        }
      });
      columns.css('height', tallestcolumn + 30);
    },

    // Default settings for fancybox.
    buildBox: function(opts) {
      return $.extend({
        'orig': undefined,
        'href': undefined,
        'onStart': undefined,
        'onClosed': undefined,
        'onComplete': undefined,
        'onCleanup': undefined,
        'type': 'iframe',
        'scrolling': 'no',
        'speedIn':300,
        'speedOut':200,
        'transitionIn':'elastic',
        'transitionOut':'elastic',
        'easingIn':'easeOutBack',
        'easingOut':'easeInBack',
        'autoDimensions': false,
        'width': 865,
        'height': 490
      }, opts);
    }

  };

  $(function() {
    //Swap OL numbers for images.
    $('ol > li').each(function() {
      var self = $(this);
      var parent = self.parent('ol');
      var color = '';
      if (parent.hasClass('color_2')) {
        color = '2';
      }

      self.css({
        'background':'url("/_img/ol_'+ color + (parent.find('> li').index(this) + 1) +'.png") no-repeat 0 0',
        'padding-left':'45px'
      }).addClass('li_num');
    });

    //Clear default value on click
    $('form input[type="text"][value!=""]').each(function() {
      var val = this.value;
      var self = $(this);
      self
        .bind('focus click', function() {
          if (self.val() == val) self.val('');
        })
        .bind('blur', function() {
          if(self.val().trim() == '') self.val(val);
        });
    });

    $('#print_page').click(function() { window.print(); });
  });

})(jQuery);
