// Input Hints plugin by Remy Sharp
// http://plugins.jquery.com/project/hint

jQuery.fn.hint = function () {
  return this.each(function (){
    // get jQuery version of 'this'
    var t = jQuery(this);
    // get it once since it won't change
    var title = t.attr('title');
    // only apply logic if the element has the attribute
    if (title) {
      // on blur, set value to title attr if text is blank
      t.blur(function (){
        if (t.val() == '') {
          t.val(title);
          t.addClass('blur');
        }
      });
      // on focus, set value to blank if current value
      // matches title attr
      t.focus(function (){
        if (t.val() == title) {
          t.val('');
          t.removeClass('blur');
        }
      });

      // clear the pre-defined text when form is submitted
      t.parents('form:first()').submit(function(){
          if (t.val() == title) {
              t.val('');
              t.removeClass('blur');
          }
      });

      // now change all inputs to title
      t.blur();
    }
  });
}

// Common functions used on pages
$(document).ready(function(){

// Google search box hint "Enter search keywords".
// Uses jQuery Input Hints plug-in (code is above)
// jQuery below says: use the hint function on
//   an input box with a type of 'text' AND an id of 'q'.
    $('input:text[id="q"]').hint();
    $('input:text[id="searchcontacts"]').hint();

// Table striping
    $('table:not([class="noborder"]):not([class="calendar"]):not([summary="Contact Details"]) tr:not([th])').removeClass('even');

    $('table:not([class="noborder"]):not([class="calendar"]):not([summary="Contact Details"]) tbody tr:nth-child(odd)').addClass('even');

 });

// Equalize News, Events and Announcements columns on home pages
/**
 *
 * Copyright (c) 2007 Tom Deater (http://www.tomdeater.com)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */

(function($) {
	/**
	 * equalizes the heights of all elements in a jQuery collection
	 * thanks to John Resig for optimizing this!
	 * usage: $("#col1, #col2, #col3").equalizeCols();
	 */

	$.fn.equalizeCols = function(){
		var height = 0,
			reset = $.browser.msie ? "1%" : "auto";

		return this
			.css("height", reset)
			.each(function() {
				height = Math.max(height, this.offsetHeight);
			})
			.css("height", height)
			.each(function() {
				var h = this.offsetHeight;
				if (h > height) {
					$(this).css("height", height - (h - height));
				};
			});

	};

})(jQuery);

$(document).ready(function() {
	$("#news-list, #events-list, #announce-list").equalizeCols();
});
