jQuery(document).ready(function($){

	//Email Obfuscation
	$(".replaceAt").replaceWith("@");
  	$(".obfuscate").each(function () {
  		$(this).attr("href", "mailto:"+$(this).text());
  	});

	//Form Default Values
	$(".replacedefault input[type=text], .replacedefault textarea").bind('focus', function(){
		var currentValue = $(this).attr("value");
		var defaultValue = $(this).attr("defaultValue");
		if (currentValue == defaultValue) $(this).attr({ value: ""});
	});
	$(".replacedefault input[type=text], .replacedefault textarea").bind('blur', function(){
		var currentValue = $(this).attr("value");
		var defaultValue = $(this).attr("defaultValue");
		if (currentValue == '') $(this).attr({ value: defaultValue});
	});

	
	$("a#closewindow").click(function () {
		$(".footerpopup-pane").hide();
		$("#footerwrap ul li a").removeClass("selected");
		$("#footerpopup").fadeOut();
		return false;
	});
	
	// SLIDESHOW
	$("#homeslideshow_container").innerfade({
		animationtype: 'fade',
		speed: 'normal',
		timeout: '5000',
		type: 'sequence',
		containerheight: 'auto'
	}); 
	
	
	// BoxSlideshow
	$("#boxslideshow_container").innerfade({
		animationtype: 'fade',
		speed: 'slow',
		timeout: '8000',
		type: 'sequence',
		containerheight: 'auto'
	}); 
	
	
	
	//NEWS TICKERS
	$("marquee").marquee();

	
	// FOOTER POPUPS
	$("#footerNav-contact").click(function() {
		$(".footerpopup").hide();
		$("#popup-contactus").fadeIn();
		return false;
	});

	$(".footerpopupclose").click(function() {
		$(".footerpopup").fadeOut();
		return false;
	});

	$("#newslettersignup").submit(function(e) {
		e.preventDefault();
		$.post("/wp-content/themes/moody_1.0/formsubmit2.php", { type: "addsubscriber", name: $("#NameSignup").val(), email: $("#EmailSignup").val() } );
		$("#newslettersignup").html("<h4>Thank You</h4><p>The 5 Love Languages&trade; newsletter will be delivered to your inbox weekly. If for any reason you are not satisfied, you may unsubscribe at any time.</p><p>Thank you for your interest.</p>");
		return false;

	});
	$("#contactusform").submit(function(e) {
		e.preventDefault();
		TheForm = document.contactusform;
		if(!TheForm.name.value) { alert ("Please enter your name."); TheForm.name.focus(); return false; }
		if(!TheForm.email.value || !isValidEmailAddress(TheForm.email.value)) { alert ("Please enter a valid email address."); TheForm.email.focus(); return false; }
		if(!TheForm.comment.value) { alert ("Please enter your message."); TheForm.comment.focus(); return false; }
		$.post("/wp-content/themes/moody_1.0/formsubmit2.php", { type: "contactus", name: TheForm.name.value, email: TheForm.email.value, state: TheForm.state.value, comment: TheForm.comment.value } );
		$("#popup-contactus").hide();
		alert('Thank you. Your message has been sent.\n\nYour comments are very important to us.');
		parent.document.contactusform.reset();
		return false;

	});


	// POPUP WINDOWS
	 $('#overlayWelcome').jqm({ajax: '/wp-content/themes/moody_1.0/overlays/radio_gary.php', trigger: 'a#welcomeVideo', overlay: '75'});
	 $('#overlay1').jqm({ajax: '/wp-content/themes/moody_1.0/overlays/radio_gary.php', trigger: 'a#radio_gary', overlay: '75'});
	 $('#overlay2').jqm({ajax: '/wp-content/themes/moody_1.0/overlays/radio_fabry.php', trigger: 'a#radio_fabry', overlay: '75'});
	 $('#overlay3').jqm({ajax: '/wp-content/themes/moody_1.0/overlays/events_conferencevideo.php', trigger: 'a.startconferencevideo', overlay: '75'});
	 $('#overlay_podcast').jqm({ajax: '/wp-content/themes/moody_1.0/overlays/radio_podcast.php', trigger: 'a.showPodcastOverlay', overlay: '75'});
	 $('#overlay_minute_podcast').jqm({ajax: '/wp-content/themes/moody_1.0/overlays/radio_minute_podcast.php', trigger: 'a.showMinutePodcastOverlay', overlay: '75'});
	 $('#overlay_newslettersignup').jqm({trigger: 'a#NewsletterSignupLink', overlay: '75'});

	
});

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

function stopDefAction(evt) {
	evt.preventDefault();
}

function checkForm(TheForm){
	if(!TheForm.name.value) {
		alert ("Please enter your name.");
		TheForm.name.focus();
		return false;
	}
	if(!TheForm.email.value || !isValidEmailAddress(TheForm.email.value)) {
		alert ("Please enter a valid email address.");
		TheForm.email.focus();
		return false;
	}
	if(!TheForm.comment.value) {
		alert ("Please enter your message.");
		TheForm.comment.focus();
		return false;
	}
	return true;
}