$(document).ready(function() {
		
	$.ajaxSetup ({ cache: false });
	
	//	load() functions			
	$.address.change(function(event) {
		
		var url = event.pathNames[0];
		var loadURL = "i/" + url + ".php";
		
		$(".loader").fadeIn('fast');

		if ($.address.pathNames().length > 1) {
			$("#menu li#aboutBtn").css('color', '#097fdb');
		} else if ($.address.pathNames().length == 1) {
			$("#menu li#aboutBtn").css('color', '#ffffff');
		}
		
		$('#menu li').each(function() {
			if ($('a',this).attr('href') == url) {
				$('a',this).css('color', '#097fdb');
			} else {
				$('a',this).css('color', '#ffffff');
			}
		});
		
		var pages = $.address.pathNames().length;
		
		switch(pages) {
			case 0:
			$("#content").fadeOut(200, function() {
				$("#content").load("i/home.php", function() {
					$(".loader").fadeOut('fast');
					$(this).fadeIn();
				});
			});
			break;
			
			case 1:
			$("#content").fadeOut(200, function() {
				$("#content").load(loadURL, function() {
					$(".loader").fadeOut('fast');
					$(this).fadeIn();
				});
			});
			break;
			
			case 2:
			$("#content").fadeOut(200, function() {
				$("#content").load(loadURL, function() {
					$(".loader").fadeOut('fast');
					$('.subpage').each(function() {
						if($(this).attr('id') == event.pathNames[1]) {
							$(this).show();
						}
					});
					$(this).fadeIn();
				});
			});
			break;
		
		}
		
		$(".page-sideMenu ul li").each(function() {
			if ($(this).attr('class') == event.pathNames[1]) {
				$(this).css('background', '#111').focus();
			} else {
				$(this).css('background', '#000');
			}
		});
    });    
	
	$('#menu li span, #footer-menu li a, #socialBtns a').fadeTo(0, 0.5);
	$('#menu li.navitem-give').css('background', '#111111');
	$('#menu li').hover(function() {
			$('span', this).stop(true,true).fadeTo(100, 1);
			$(this).stop(true,true).css('background', '#222222');
		}, function() {
			$('span', this).stop(true,true).fadeTo(300, 0.5);
			$(this).stop(true,true).css('background', '#000000');
	});
	
	$('#footer-menu li a, #socialBtns a').hover(function() {
			$(this).stop(true,true).fadeTo(300, 1);
		}, function() {
			$(this).stop(true,true).fadeTo(300, 0.5);
	});
	
	$('.aboutColumn dd:has(a)').hover(function() {
			$(this).stop(true,true).css('color', '#ffffff');
			$(this).stop(true,true).css('background', '#0084ff');
		}, function() {
			$(this).stop(true,true).css('color', '#555555');
			$(this).stop(true,true).css('background', 'none');
	});
	
	$('span','.aboutColumn dd:not(:has(a))').after('<span style="font-size: 10px; color: #333"> (Coming Soon)</span>');
	
	$('#goLive').hover(function() {
			$(this).stop(true,true).css('background', '#ffffff');
			$(this).stop(true,true).css('color', '#000000');
		}, function() {
			$(this).stop(true,true).css('background', '#0084ff');
			$(this).stop(true,true).css('color', '#ffffff');
	});
	
	var timeouts = {};
	$('#aboutBtn, #aboutMenu').hover(function() {
			var menu = $(this).attr('rel');
			if (timeouts[menu]) clearTimeout(timeouts[menu]);
			timeouts[menu] = setTimeout(function() { $('#aboutMenu').stop(true,true).fadeIn('fast').show(); }, 200);
		}, function() {
			var menu = $(this).attr('rel');
			if (timeouts[menu]) clearTimeout(timeouts[menu]);
			timeouts[menu] = setTimeout(function() { $('#aboutMenu').stop(true,true).fadeOut('fast') }, 500);
	});
	
	var options = { 
		success: function() { 
			$('#quickForm').fadeOut("normal", function() {
				$('#quickForm').html("<div id='cForm2' class='roundShadow' style='overflow: hidden; padding: 100px; background: url(/images/darkBG.jpg); margin-top: 25px'><div style='font-size: 14px'><h2 style='color: #fff; font-size: 40px; margin: 0; padding: 0'>Thank You!</h2><br/><span style='color: #888; font-size: 18px'>Your message has been successfully sent to this ministry's leader. Thank you for your interest in our ministry and for serving here at Mosaic! The ministry leader will contact you as soon as possible.</span></div><div class='clear'></div></div>");
				$('#quickForm').fadeIn('normal', function() {
					$.get("/i/minicontactForm.php",{},function(response){
						$('#quickForm').delay(5000).fadeOut("normal", function() {
							$('#quickForm').html(response);
							$('#quickForm').fadeIn('normal');
						});
					});
				});
			});
		} 
	};
	
	$('.submitInvolved').livequery('click',function(){
		$('#contactForm').validate({
			submitHandler: function(form) {
				$('.submit').hide();
				$('#formLoading').stop().fadeTo(500,1);
				$(form).ajaxSubmit(options);
			}
		});
	});

});
