// Adds some support for some new HTML 5 features to older browsers. Depends on Modernizr and JQuery 1.4.2 or later.
(function($) {
	try {
		$(document).ready(function() {
			if (Modernizr !== undefined) {
				// Add support for placeholder text if the browser doesn't support it.
				if (!Modernizr.input.placeholder) {
					$('input[placeholder], textarea[placeholder]').each(function(i, e) {
						if ($(this).hasClass('noPlaceholder')) return;
						var def = $(this).attr('placeholder'), ip = this;
						$(this).data('def', def).val((($(this).val() != '') ? $(this).val() : def)).bind('focus',function() { ($(this).val() == $(this).data('def')) ? $(this).val('').css('color', '#000') : false; }).bind('blur',function() { ($(this).val() == '') ? $(this).val(def).css('color', '#999999') : false; }).bind('change', function() { ($(this).val() != $(this).data('def')) ? $(this).css('color', '#000') : false; });
						($(this).val() == $(this).data('def')) ? $(this).css('color', '#999999') : $(this).css('color', '#000');
						$(this).closest('form').submit(function() {
							if ($(ip).val() == def) $(ip).val('');
						});
					});
				}
				// Add support for the new autofocus attribute.
				if (!Modernizr.input.autofocus) {
					$('input[autofocus], select[autofocus], textarea[autofocus]').focus();
				}
				//Add some IE crutches.
				if ($.browser.msie) {
					$('ul li:first-child').addClass('first-child');
					$('ul li:last-child').addClass('last-child');
					// Crutch for IE to support images in labels
					$('label > img').each(function(i, e) {
						if ($(e).parent().attr('for')) {
							var forid = '#' + $(e).parent().attr('for');
							var forel = $(forid);
							$($(e).parent()).click(function(){
								switch (forel.attr('type')) {
									case "radio":
										forel.attr("checked", "checked");
									break;
									case "checkbox":
										if (forel.attr("checked") == "checked") {
											forel.attr("checked", "");
										} else {
											forel.attr("checked", "checked");
										}
									break;
									case "text": case "password": case "textarea":
										forel.focus();
									break;
								}
								forel.trigger("click");
							});
						}
					});
				}
			}
			
		});
	} catch(ex) {
		
	}
})(jQuery);
