$(function(){
	if ($.browser.msie) {
		$('label.image').click(function() {
			// This enables images as labels in IE6/7
			// Any label with the class 'image' will call a click function
			// on the corresponding input [ie, with a matching id]:							
			var id = $(this).attr('for');
			$('#'+id).click();
			// NOTE: we should really use change() and not click(), but IE doesn't support it
		});
	}
});

$(function() {
	// This allows us to vertically align elements either middle or bottom within their parent
	// by applying the style 'vertical_align_middle' or 'vertical_align_bottom'
	// It will often be necessary to wrap elements in a div.wrapper [see core.css]
	$.fn.vAlign = function(align) {
		return this.each(function(i){
			var ah = $(this).height();
			var ph = $(this).parent().height();
			var mh = (ph - ah) / 2;
			var bh = (ph - ah);
			if (align == 'middle') {
				$(this).css('margin-top', mh);
			}
			else if (align == 'bottom') {
				$(this).css('margin-top', bh);
			}
		});
	}			
	$('.vertical_align_middle').vAlign('middle');
	$('.vertical_align_bottom').vAlign('bottom');	
	
	// This enables default values for fields, using the 'title' attribute to store the default: 
	
	$('input[title]').focus(function() {
		var default_value = $(this).attr('title');
		var current_value = $(this).val();
		if (current_value == default_value) {
			$(this).val('');
		}
	});
	$('input[title]').blur(function() {
		var default_value = $(this).attr('title');
		var current_value = $(this).val();
		if (!current_value) {
			$(this).val(default_value);
		}
	});
			
});
