$(document).ready( function() {
  /**
   * Crappy browser fallback behaviors
   */
  // placeholder text for form inputs
  if( !Modernizr.input.placeholder ) {
    $('input[type=text][placeholder]').placeholder();
  }
  
  /**
   * UNIVERSAL LINK MANAGEMENT
   */
  
  // disabled links
  $('a[href=#]').addClass( 'disabled' );
	$('a.disabled').click( function() {
		return false;
	});
  
  // standards-compliant new window
	$('a[rel="external"]').attr( 'target', '_blank' );
  
  // visual cue for document downloads
	$('a.document[href$=".pdf"]').addClass( 'document pdf' );
	$('a.document[href$=".doc"]').addClass( 'document msword' );
  
  $( '.dialog' ).colorbox({
    onComplete: function() {
      $.fn.colorbox.resize();
    }
  });
});

/**
 * Emulates the HTML5 placeholder input attribute
 */
$.fn.placeholder = function() {
  return this.each( function() {
    var $this = $(this);
    
    var clear = function() {
      if( $this.val() === $this.attr( 'title' ) ) {
        $this
          .removeClass( 'placeholder' )
          .val( '' );
      }
      return true;
    };

    var placeholder = function() {
      if( $this.val() === '' ) {
        $this
          .addClass( 'placeholder' )
          .val( $this.attr('placeholder') );
      }
    };
    $this
      .focus( clear )
      .blur( placeholder )
      .closest('form').submit( clear );
    
    placeholder();
  });
};

