$(document).ready(function(){
	$('#content-background').wtRotator({
		width: 960,
		height: 446,
		button_width: 20,
		button_height: 20,
		auto_start: true,
		block_size: 50,
		delay: 4000,
		mouseover_pause: true,
		cpanel_mouseover: true,
		text_mouseover: true
	});
	$('.tweet-feed').jTweetsAnywhere({
		username: 'PierreLandscape',
		count: 4,
		showFollowButton: true,
		showTweetFeed: {
			expandHovercards: true,
			showUserScreenNames: true,
			paging: { mode: 'prev-next' }
		}
	});
	$('#ea').val('you@somewhere.com').addClass('default-input')
	.focus(function() {
		if ($(this).val() == 'you@somewhere.com') $(this).val('').removeClass();
	})
	.blur(function(){
		if (!$(this).val().length) {
			$(this).val('you@somewhere.com').addClass('default-input');
			if ($(this).hasClass('input-error')) $(this).removeClass('input-error')
			if ($('#system-message').css('display') == 'block') $('#system-message').hide('slow');
		}
	});
	$('#ccoptin').submit(function() {
		if ($('#ea').val() == 'you@somewhere.com') {
			return false;
		} else {
			if (validateNewsletterEmail()) {
				$('#system-message').fadeOut('slow');
				if ($('#ea').hasClass('input-error')) $('#ea').removeClass('input-error');
				return true;
			} else {
				$('#system-message').show('slow');
				return false;
			}	
		}
	});
	function validateNewsletterEmail() {
		var email = $('#ea');
		var emailValue = email.val();
		var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
		if(filter.test(emailValue)) {
			email.removeClass('input-error');
			return true;
		} else {
			email.addClass('input-error');
			return false;
		}
	}
});
