$(document).ready(function(){ 
	$('input').focus(function(){
		(this).value='';
	})

	$('#menu a').addClass('inactive');
	var open = 'home';
	$('#'+open+'_content').slideDown('fast');
	$('a#'+open).removeClass('inactive');
	$('a#'+open).addClass('active');
	
	$('#menu a').click(function(){
		if ((this).id != open) {
			var id = (this).id;
			$('#'+open+'_content').slideUp(500,function(){
				$('#'+id+'_content').slideDown(500);
				$('a#'+open).removeClass('active');
				$('a#'+open).addClass('inactive');
				$('a#'+id).removeClass('inactive');
				$('a#'+id).addClass('active');
				open=id;
			});
		}
	})

	$('.store_link').click(function(){
		if (open != 'store') {
			$('#'+open+'_content').slideUp(500,function(){
				$('#store_content').slideDown(500);
				$('a#'+open).removeClass('active');
				$('a#'+open).addClass('inactive');
				$('a#store').removeClass('inactive');
				$('a#store').addClass('active');
				open='store';
			});
		}
	})

	$('.contact_link').click(function(){
		if (open != 'contact') {
			$('#'+open+'_content').slideUp(500,function(){
				$('#contact_content').slideDown(500);
				open='contact';
			});
		}
	})

	$('.more').click(function(){
	    $('#more_'+(this).id).slideDown('fast');
	    $('.more_line').slideUp('fast');
	})

	$("#newsletter_form #add").click(function() {
		var subject = $('input[name=email_address]');
		if (subject.val().length == 0 || subject.val() == 'email address') {
			alert('Please enter your email address.');
	        return false;
		}
		var data = $("#newsletter_form").serialize();
		$.ajax({
			type: "POST",
			url: 'functions/add_to_mailing_list.php',
	        dataType: "text",
	        data: data,
			error: function(){ alert('Sorry, an error occurred.  Please try again.'); },
			success: function(a) {
				$('#newsletter_message').html(a);
			}
		});
		return false;
    });


	$("#press_form #submit").click(function() {
		press_form_submit();
    });
	$("#press_form").submit(function() {
		press_form_submit();
        return false;
    });

	$("#contact_form input").focus(function(){
		var a = '';
		$(this).val(a);
    });
	$("#contact_form textarea").focus(function(){
		var a = '';
		$(this).val(a);
    });
	$("#contact_form #submit_button").click(function() {
		var email = $('input[id=email_address]');
		if (email.val().length == 0 || email.val() == 'your email address') {
			alert('Please enter your email address.');
	        return false;
		}
		var subject = $('input[id=subject]');
		if (subject.val().length == 0 || subject.val() == 'subject') {
			alert('Please enter a subject for your email.');
	        return false;
		}
		var data = $("#contact_form").serialize();
		$.ajax({
			type: "POST",
			url: 'functions/contact_send.php',
	        dataType: "text",
	        data: data,
			error: function(){ alert('Sorry, an error occurred.  Please try again.'); },
			success: function(a) {
				$('#contact_form').html(a);
			}
		});
		return false;
    });


	function press_form_submit() {
		var secret_word = $('input[id=secret_word]');
		if (secret_word.val().length == 0) {
			alert('You must enter the secret word.');
	        return false;
		}

		var data = $("#press_form").serialize();
		$.ajax({
			type: "POST",
			url: 'functions/secret_press.php',
	        dataType: "text",
	        data: data,
			error: function(){ alert('Sorry, an error occurred.  Please try again.'); },
			success: function(a) {
				if (a.match('Error')) {
					$('#press_form').prepend('<div class="error">'+a+'</div>');
					return false;
				}
				if (a == 0) {
					alert('The password you entered was incorrect.  Please try again.');
				} else {
					$.cookie('tws_ok', 'ok', {path: '/',domain:'.thewintersounds.com'});
					$('#press_content').html(a);
				}
				return false;
			}
		});
	    return false;
	}
	

});
