/*!
 * jQuery equalizeBottoms - v1.5 - 3/23/2010
 * http://benalman.com/projects/jquery-equalizebottoms-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */

// Script: jQuery equalizeBottoms
//
// *Version: 1.5, Date: 3/23/2010*
// 
// Project Home - http://benalman.com/projects/jquery-equalizebottoms-plugin/
// GitHub       - http://github.com/cowboy/jquery-equalizebottoms/
// Source       - http://github.com/cowboy/jquery-equalizebottoms/raw/master/jquery.ba-equalizebottoms.js
// (Minified)   - http://github.com/cowboy/jquery-equalizebottoms/raw/master/jquery.ba-equalizebottoms.min.js (0.5kb)
// 
// About: License
// 
// Copyright (c) 2010 "Cowboy" Ben Alman,
// Dual licensed under the MIT and GPL licenses.
// http://benalman.com/about/license/
// 
// About: Examples
// 
// This working example, complete with fully commented code, illustrates a few
// ways in which this plugin can be used.
// 
// Equalize Bottoms - http://benalman.com/code/projects/jquery-equalizebottoms/examples/equalizebottoms/
// 
// About: Support and Testing
// 
// Information about what version or versions of jQuery this plugin has been
// tested with and what browsers it has been tested in.
// 
// jQuery Versions - 1.3.2, 1.4.2
// Browsers Tested - Internet Explorer 6-8, Firefox 2-3.6, Safari 3-4, Chrome, Opera 9.6-10.1.
// 
// About: Release History
// 
// 1.5 - (3/23/2010) Changed .height measurement to .outerHeight to take
//       padding and border into consideration.
// 1.4 - (11/7/2009) Removed polling functionality. If you need polling, use
//       in combination with jQuery doTimeout.
// 1.3 - (4/4/2009) Initial release

(function($) {
  '$:nomunge'; // Used by YUI compressor.
  
  // Method: jQuery.fn.equalizeBottoms
  // 
  // Equalize the bottoms of all selected elements.
  // 
  // Usage:
  // 
  // > jQuery('selector').equalizeBottoms( [ bottom ] );
  // 
  // Arguments:
  // 
  //  bottom - (Number) An optional bottom y position to force selected element
  //    bottoms to. If omitted, bottom is computed automatically by measuring
  //    height of all selected elements and choosing the bottom-most bottom. You
  //    will probably never, ever use this.
  // 
  // Returns:
  // 
  //  (jQuery) The initial jQuery collection of elements.
  
  $.fn.equalizeBottoms = function( bottom ) {
    
    if ( isNaN( bottom ) ) {
      bottom = 0;
      
      // Reset height first, then get the bottom-most bottom.
      this.each(function(){
        var that = $(this).css({ height: 'auto' });
        bottom = Math.max( bottom, that.offset().top + that.outerHeight() );
      });
    }
    
    // Update all bottoms, taking padding and border height into consideration.
    return this.each(function(){
      var that = $(this);
      that.height( bottom - that.offset().top - that.outerHeight() + that.height() );
    });
    
  };
  
})(jQuery);

/*  The Equal Bottom Font Resizer
*   modification added by One to One Interactive
*   June 2010
*   Equal bottoms and font resizing, all in one go!
*/

$(function(){
  
  // This one function performs multiple equalizeBottoms calls.
  function equalize(){
    
    // For each box, equalize bottoms of the last div in each column.
    $('.equal-heights-box').each(function(){
	  $(this).find('.equal-heights-column > :last-child').addClass('equal-heights');
	  $(this).find('.equal-heights > :last-child').equalizeBottoms();
   
   });
	
	// homepage 3 columns
	$('.equal-heights-home').each(function(){
	  $(this).find('.module-wrapper > :last-child').equalizeBottoms();
    });
	
	// sitemap columns
	$('#footer-sitemap').each(function(){
	  $(this).find('.sitemap-col > :first-child').equalizeBottoms();
    });
	
    // Equalize bottoms of boxes.
    $('.equal-heights-box').equalizeBottoms();
	$('.equal-heights-home').equalizeBottoms();
	$('#footer-sitemap').equalizeBottoms();
  };
  
  // Bind a custom 'equalize' event to document, then trigger it immediately.
  $(document).bind( 'equalize', equalize ).trigger( 'equalize' );
  
  // Now, let's resize that font
  $('a.resize').click(function(){
    var ourText = $('#main-content-left .module-container');
	var currFontSize = ourText.css('fontSize');
	var currLineHeight = ourText.css('lineHeight');
	var finalNum = parseFloat (currFontSize, 12);
	var finalHeight = parseFloat (currLineHeight, 18);
	var stringSize = currFontSize.slice(-2);
	var stringHeight = currLineHeight.slice(-2);
	if(this.id == 'large') {
		finalNum = 16;
		finalHeight = 24;
		// in case we want to dynamically scale
		// finalNum *=1.2;
		// finalHeight *=1.2;
		//if(finalNum >= 20.74){finalNum = 20.74;}
		//if(finalHeight >31.1){finalHeight = 31.1;}
	}
	if(this.id == 'xlarge') {
		finalNum = 20;
		finalHeight = 30;
	}
	else if (this.id == 'normal') {
		finalNum = 12;
		finalHeight = 18;
	}
	ourText.css('fontSize', finalNum + stringSize);
	ourText.css('lineHeight', finalHeight + stringHeight);
    
    // Trigger equalizeBottom (the event will bubble).
    $(this).trigger( 'equalize' );
    
    // Prevent default click action.
    return false;
  });
  
});

// Initialize search as you type
$(document).ready(function(){
	searchAsYouType.initialize(document.getElementById('search_field'), false);
	$('#search_field').focus(function(){
		$(this).val('');
	});	
	
	$('#internationalRadio').click(function(){
		var action = '/international/search/search.aspx';
		$('#search_s').attr('action',action);
	});
	
	$('#gmeRadio').click(function(){
		var action = '/Graduate-Medical-Education/search/search.aspx';
		$('#search_s').attr('action',action);
	});		
	
	$('#phsRadio').click(function(){
		var action = '/search/search.aspx';
		$('#search_s').attr('action',action);
	});
});
