// Put all of this in a closure
(function($){

// Small plugin to remove the default value from a form input
// and replace it if no input was made
$.fn.clearonfocus = function() {
	$(this)
		.bind('focus', function() {
			if (this.defaultValue && this.defaultValue != this.value) return;
			this.defaultValue = this.value;
			this.value = '';
		})
		.bind('blur', function() {
			if ( this.value.match(/^\s*$/) )
				this.value = this.defaultValue;
		});
};

// Do what you will within this block since the document is now ready
$(function() { 
	
	// Start the sIFR headline replacement
	if (typeof sIFR == "function") {
		sIFR.replaceElement(named({
			sSelector:"#col2>h2",
			sFlashSrc:"http://www.salvationarmyusa.org/WebManager/themes/20/flash/trajanpro.swf",
			sColor:"#050505",
			sLinkColor:"#B60A0E",
			sBgColor:"#E1DDD2",
			sWmode:"transparent"
		}));
		sIFR();
	}
	
	// Add main content area shadows
	$('<div id="shadow_top" />').prependTo('#body');
	$('<div id="shadow_bottom" />').prependTo('#col3');
	
	// Setup Locations form
	var $locator_form = $('#locator_form'),
		$locator_form_label = $locator_form.find('label');
	$('#q_zip')
		.val( $locator_form_label.text() )
		.clearonfocus();
	
	// Setup newsletter form
	var $newsletter_form = $('div.newsletter_signup');
	$('input:eq(0)', $newsletter_form)
		.val( $('label:eq(0)', $newsletter_form).text() )
		.clearonfocus();
	$('input:eq(1)', $newsletter_form)
		.val( $('label:eq(1)', $newsletter_form).text() )
		.clearonfocus();
		
	// Setup nav hovers
	var $subNavLis = $('#nav ul li:has(ul)').addClass('hasChild'), $firstLevelLis = $('#nav > ul > li');
	$('> a', $subNavLis).addClass('arrow');
	var navTimeout;
	var hideSecondLevel = function() {
		$firstLevelLis.removeClass('hover');
		if ( $.browser.msie && $.browser.version.match(/6/) && $(this).is(':has(ul)') ) $('#body select').css('visibility', 'visible');
	};
	$firstLevelLis
		.hover(function() {
			clearTimeout(navTimeout);
			if ( $firstLevelLis.is('.hover') ) hideSecondLevel();
			$(this).addClass('hover');
			if ( $.browser.msie && $.browser.version.match(/6/) && $(this).is(':has(ul)') ) $('#body select').css('visibility', 'hidden');
		}, function() {
			navTimeout = setTimeout(hideSecondLevel, 750);
		});
	$('#nav ul li ul li')
		.hover(function() {
			$(this).css('zIndex', 10);
			if ( !$(this).is('.hasChild') ) return;
			$(this).addClass('hover');
			if ($.browser.msie) $('> ul', this).show();
		}, function() {
			$(this).css('zIndex', 1);
			if ( !$(this).is('.hasChild') ) return;
			$(this).removeClass('hover');
			if ($.browser.msie) $('> ul', this).hide();
		});
	
});

})(jQuery); // Pass in jQuery so we can safely use the $ alias for jQuery within this block