$(document).ready( function () {

	//change the background color of main nav on hover
	$('.navItem').hover(function() {
		if($(this).attr('id') != 'mainNavCurrent') {
			$(this).addClass('mainNavTempCurrent');
			if($(this).attr('id') != 'mainNavFirst' && $(this).attr('id') != 'mainNavFirstPrior' && $(this).attr('id') != 'mainNavPrior') {
				var tempWidthThis = $(this).width() + 1;
				$(this).css('width',tempWidthThis + 'px');
				$(this).prev().addClass('mainNavTempPrior');
				var tempWidthPrior = $(this).prev().width() - 1;
				$(this).prev().css('width',tempWidthPrior + 'px');
			}
			else if($(this).attr('id') == 'mainNavPrior') {
				//var tempWidthThis = $(this).width() + 1;
				//$(this).css('width',tempWidthThis + 'px');
				$(this).css('padding-left','1px');
				$(this).prev().addClass('mainNavTempPrior');
				var tempWidthPrior = $(this).prev().width() - 1;
				$(this).prev().css('width',tempWidthPrior + 'px');
			}
			else if($(this).attr('id') == 'mainNavFirst') {
				var tempWidthThis = $(this).width() - 1;
				$(this).css('width',tempWidthThis + 'px');
				$(this).css('padding-right','1px');
			}
		}
	},function() {
		if($(this).attr('id') != 'mainNavCurrent') {
			$(this).removeClass('mainNavTempCurrent');
			if($(this).attr('id') != 'mainNavFirst' && $(this).attr('id') != 'mainNavFirstPrior' && $(this).attr('id') != 'mainNavPrior') {
				var tempWidthThis = $(this).width() - 1;
				$(this).css('width',tempWidthThis + 'px');
				$(this).prev().removeClass('mainNavTempPrior');
				var tempWidthPrior = $(this).prev().width() + 1;
				$(this).prev().css('width',tempWidthPrior + 'px');
			}
			else if($(this).attr('id') == 'mainNavPrior') {
				//var tempWidthThis = $(this).width() - 1;
				//$(this).css('width',tempWidthThis + 'px');
				$(this).css('padding-left','0px');
				$(this).prev().removeClass('mainNavTempPrior');
				var tempWidthPrior = $(this).prev().width() + 1;
				$(this).prev().css('width',tempWidthPrior + 'px');
			}
			else if($(this).attr('id') == 'mainNavFirst') {
				var tempWidthThis = $(this).width() + 1;
				$(this).css('width',tempWidthThis + 'px');
				$(this).css('padding-right','0px');
			}
		}
	});
  
	$("#searchButton").click( function () {
		var currentInput = $("#searchInput").val();
		if(currentInput == "") {
			alert("Please type in the text you would like to search the site for.");
			$("#searchInput").focus();
			return false;
		}
	});
	
	//fix embeded objects so they don't shine through
	$('object').append('<param name="wmode" value="opaque"></param>');
  
	//hide the fsf inputs (fight spam fields)
	$('.bomberCMSform-fsf').hide();
	
	//show custom form success popup
	if($('#custom_form_success').length ){
		alert("Thank you!\n\nYour information was submitted successfully");
	}
	if($('#custom_form_fail').length ){
		alert("There was a problem with the information you submitted\n\nPlease check it and try again");
	}
	//handle validation of custom forms
	$('.customFormSubmit').click( function () {
		var status;
		$(this).closest('.customForm').find('.require').each(function() {
			if($(this).attr('type') == 'checkbox' && $(this).attr('checked') == false) {
				status = false;
				$(this).prev().addClass('customFormFail');
				
				$(this).focus();
				alert("You must agree to the terms.\n\nPlease complete the form and try again");
				return false;
			}
			else if($(this).val() == "") {
				status = false;
				$(this).prev().addClass('customFormFail');
				$(this).focus();
				alert("A required field was left blank.\n\nPlease complete the form and try again");
				return false; 
			}
			else {
				status = true;
				$(this).prev().removeClass('customFormFail');
				return true;
			}
		});
		return status;
	});

});
