$(function()
{
	// Use javascript to get around XHTML's 
	// removal of target=_blank
	$('a[rel=outgoing]')
		.after('<img class="outgoing" src="/images/icons/outgoing.png" />')
		.attr('target','_blank');
		
	// Quick Ajax support
	$('.ajax').each(function() {
		$(this).bind('submit', function() {
			
			// Cache this
			var $this = $(this);
			
			// Load the data
			$this.load($this.attr('action'),$this.serialize()); 

			// Prevent the form from submitting
			return false;
		});
	});
	
	// Nursing Homes Search Box
	$('.nursing-homes-search').each(function(){
		
		var $this = $(this);
		var $options = $this.children('div:not(.options)');
		
		// See if any options are selected by default to be shown
		if ($this.children('.selected').length > 0) {
			var remove_child = '.selected';
		} else {
			var remove_child = ':first';
		}
		
		// Hide the non-selected options
		$options.not(remove_child).hide();
		
		// Set up Event Handlers
		$this
			.find(':radio')
			.click(function() {
				
				// Hide all siblings
				$(this)
					.parent('div')
					.siblings('div')
					.hide();
					
				// Show selected
				$(this)
					.parent('div')
					.siblings('.'+$(this).val())
					.show();
			});		
	});
	
	// Input defaults
	$.getScript('/javascripts/plugins/jquery.default-input.js', function(){
		$('input:text,textarea').defaults();
	});
	
	// Tabs
	$('#tabs').semantictabs({
		panel: 'tab',
		head: 'h3',
		active: ':first'
	});
	
	// Google maps doesn't load properly because it's hidden
	// by the tabs. Reload it when the tab is actuall clicked
	$('#tabs li:last').click(function() {
		// Google maps
		if (typeof load_google_maps == 'function') {
			load_google_maps();
		}
	});

});
