$(document).ready(function() {
	emailMangle();
	
	// Logo animation
	$('#logo').wait().animate({
		top: 0
	}, 'fast', function() {
		$('#logo').css({'top':'0'});
	});
	if (!$.browser.msie || $.browser.version > 7) {
		$('#logo').effect('bounce', {
			times:5,
			distance:25
		}, 500);
	}
	
	// Form submission behavior	
	$('#signup').submit(function(){
		var formStatus = 'pass';
		var emailInput = $('#email').val();
		
		$("#email").css({'background':'transparent'});
		
		if (emailInput.indexOf('@') < 0) {
			$("#email").css({'background':'pink'});
			formStatus = 'fail';
		}
		
		if (formStatus=='pass') {
			$("#signup").css({'display':'none'});
			$("#thankYouWrap").css({'display':'block'});
			return true;
		}
		else {
			return false;
		}
	});
	// External links
	$('a[rel=external]').click(function(){
		window.open(this.href);
		return false;
	});
	
});

/*
*********
Functions
*********
*/

// Pause before starting logo animation
$.fn.wait = function(time, type) {
    time = time || 1000;
    type = type || "fx";
    return this.queue(type, function() {
        var self = this;
        setTimeout(function() {
            $(self).dequeue();
        }, time);
    });
};

function emailMangle() {
	var mangleCode = 'c3po'; //Set this variable to whatever you will replace the email domain name with
	var trueDomain = 'theshantyannes' //Set this variable to the real domain name in the email
	var aLinks = document.getElementsByTagName('a');
	var aHREF;
	var aTextNode;
	for (i=0; i < aLinks.length; i++) {
		aHREF = aLinks[i].getAttribute('href');
		aTextNode = aLinks[i].innerHTML;
		
		if (aHREF!=null && aHREF.indexOf(mangleCode)!=-1) {
			var newHREF = aHREF.replace(mangleCode,trueDomain);
			aLinks[i].setAttribute('href',newHREF)
		}
		
		if (aTextNode.indexOf(mangleCode)!=-1) {
			var aTextNode = aTextNode.replace(mangleCode,trueDomain);
			aLinks[i].innerHTML= aTextNode;
		}
	}
}
