jQuery(function( $ ){
	//Scrolling content
	$('#content_pane').attr({scrollTop:0,scrollLeft:0});
	
	$('#mainnav .first A').addClass('active');
	
	$.localScroll.hash({
		target: '#content_pane', //could be a selector or a jQuery object too.
		axis:'xy',//the default is 'y'
		queue:true,
		duration:1500
	});
	
	var $last = $([]);//save the last link
	

	$('#mainnav').localScroll({
		target: '#content_pane', //could be a selector or a jQuery object too.
		axis:'xy', //the default is 'y'
		queue:true,
		duration:2000,
		hash:true,
		onBefore:function( e, anchor, $target ){//'this' is the clicked link
			$('#mainnav A').removeClass('active');
			$('#home img, #home UL').hide('fast');
			/*
			switch($(this).attr("href")){
				case "#home":
					image = "/img/mccartt_bkgd_sm_1.jpg";
					break;
				case "#news":
					image = "/img/mccartt_bkgd_sm_2.jpg";
					break;
				case "#events":
					image = "/img/mccartt_bkgd_sm_3.jpg";
					break;
				case "#media":
					image = "/img/mccartt_bkgd_sm_4.jpg";
					break;
				case "#contact":
					image = "/img/mccartt_bkgd_sm_5.jpg";
					break;
			}
			$('IMG.body_image').attr('src',image);
			*/
			if(($(this).attr("href")=="#home")&&(!ishome)){
				$('#link_1').animate({
					marginTop:'330px'
				},600,'',function(){
					$('#link_1').html(homehtml);
				});
				$('#link_1').animate({
					marginTop:'0px'
				},600);
			}
			$(this).addClass('active');
			$last.removeClass('scrolling');
			$last = $(this).addClass('scrolling');
			if( this.blur )
				this.blur();//remove the awful outline
		},
		onAfter:function( anchor ){
			$last.removeClass('scrolling');
		}
	});

	var homehtml = $('#link_1').html();
	var ishome = true;

	//Home page buttons
	$('#home_menu a').click(function(){
		href = $(this).attr("href");
		
		switch(href.substring(0,1)){
			case "h":
 				window.open	(href);
				break;
			default:
				$('#link_1').animate({
					marginTop:'330px'
				},600,'',function(){
					$('#link_1').html($(href).html());
				});
				$('#link_1').animate({
					marginTop:'0px'
				},600);
				ishome = false;
				break;
		}

		return false;
	});
	
/* 	BANNER FORM */
	$('#add_contact_form INPUT').focus(function(){
		if(($(this).val()=="Email")||($(this).val()=="First")||($(this).val()=="Last")||($(this).val()=="Zip")){
			$(this).val('');
		}
		$('#add_contact_form INPUT').css({
			"background":"url(../img/mccartt_buttons.png) no-repeat left top",
			"color":"#b2d4eb"
		});
		$(this).css({
			"background":"url(../img/mccartt_buttons.png) no-repeat left bottom",
			"color":"#002b5c"
		});
	});
	var form_options = {
		beforeSubmit: function(){
			fail = false;
			if($('#ContactFirstName').val() == ""){fail = true;}
			if($('#ContactLastName').val() == ""){fail = true;}
			if($('#ContactZip').val() == ""){fail = true;}
			if($('#ContactEmail').val() == ""){fail = true;}
			if(fail){
				alert('Please fill out all the fields.');
				return false;
			}
		},
		success: function(){
			alert('Thanks for submitting your information!');
			$('#add_contact_form').hide();
		}
	};
	$('#add_contact_form').ajaxForm(form_options);
	$('#add_contact_form a.submit').click(function() {
		$(this).parents("form").submit();
		return false;
	});
});