$(document).ready( function(){
	/* mailing list stuff */
	var origSubscribeText = $('#effusion_mailing_list_input').val();
	$('#effusion_mailing_list_input').focus(function(){
		if ($(this).val() == origSubscribeText) this.value='';
	});
	
	$('#effusion_mailing_list_input').keyup(function(event){
		if (event.keyCode == 13){
			var inputBox = this;
			var emailToSubscribe = $(this).val();
			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);
			if (pattern.test(emailToSubscribe)){
				$(this).val('Sending Request...');					
				$(this).removeClass('error');
				$(this).removeClass('success');
				$(this).addClass('sending');
				$.ajax({
					type: "POST",
					url: "subscribe.php",
					data: 'email='+emailToSubscribe,
					cache: false,
					success: function(msg){
						if (msg == 'ok'){
							$(inputBox).removeClass('sending');
							$(inputBox).addClass('success');
							$(inputBox).val('Thanks for subscribing!')
						} else {
							$(inputBox).removeClass('sending');
							$(inputBox).addClass('error');
							$(inputBox).val('ERROR: Please try again')
						}
					},
					error: function(){
						$(inputBox).addClass('error');
					}
				});

			} else {
				$(this).addClass('error');
			}
		}
	});
	
	/* header images stuff */
	var headerGalInterval = setInterval("$('#effusion_topimage_holder').click()", 8000);
	$('#effusion_topimage_holder').click(function(){
		var pics = $(this).children();
		pics.show();
		pics.eq(0).fadeOut(1000, function(){
			$('#effusion_topimage_holder').prepend($('#effusion_topimage_holder > img:last'));
		});
		clearInterval(headerGalInterval);
		headerGalInterval = setInterval("$('#effusion_topimage_holder').click()", 8000);
	});
	
	/* members page stuff */
	if ($('.effusion_member_profile').size()>0){
		$('.effusion_member_profile ul').each(function(){
			var ul = this;
			var showlink = $('<a class="effusion_member_show_link" href="javascript:function(){return false;}()">Read More</a>');
			showlink.click(function(){
				if ($(this).text()=='Read Less') var hide = true;
				$('.effusion_member_show_link').text('Read More');
				$('.effusion_member_profile ul').slideUp();
				if (!hide){
					$(this).text("Read Less");
					$(ul).slideDown();
				}
			});
			$(this).hide();
			$(this).before(showlink);
			$(this).after($('<div style="clear:left;"></div>'));
		});
	}
							
});