$(document).ready( function() { 

	// set up the rollover nav
	var subs = $('div.subs');
	$('#nav a.toplevel').each(function(e) {
		$(this).attr('id', e);
		$(this).mouseover(function(event) {
			var position = $(this).position();
			$('#nav a.toplevel').removeClass('selected');
			$('div.subs').css('display', 'none');
			$(this).addClass('selected');
			var nav_id = $(this).attr('id');
			if (subs[nav_id]) {
				var sub_id = $(subs[nav_id]).attr('id');
				if (sub_id) {
					$('#' + sub_id).css('left', position.left);
					$('#' + sub_id).css('display', 'inline');					
				}
			}
		});
	});
	
	// when they move outside the parent nav.. hide everything
	$("div.content, div.search, h1").mouseover(function(event) {
		$('#nav a.toplevel').removeClass('selected');
		$('div.subs').css('display', 'none');
	});
	
	// set the side filler (right side drop shadow) to the right height
	var container_height = $('div.container').height();
	$('div.side-filler').css('height', container_height-35 + 'px');
	$('div.side-filler').css('display', 'inline');
	
	// swap the submit buttons for fake submit buttons
	var submit_buttons = $('form input.submit-button');
	var fake_submit_buttons = $('form .submit-button-fake');
	submit_buttons.each(function(f) {
		if (fake_submit_buttons[f]) {
			$(this).css('display', 'none');
			$(fake_submit_buttons[f]).css('display', 'inline');
			$(fake_submit_buttons[f]).click(function(event) {
				$(this).parent().get(0).submit();
			});
			$(fake_submit_buttons[f]).mouseover(function(event) {
				$(this).css('background', '#F00');
			});
			$(fake_submit_buttons[f]).mouseout(function(event) {
				$(this).css('background', '#000');
			});
		}
	});
		
});


// Generic functions

function clearField(f, default_text) {
	if (f && f.value == default_text) { f.value = ''; }
}


