$(document).ready(function(){ 

    var open = 'welcome';
    var popen = '';
    var id = '';
    $("#"+open+'_content').slideToggle(1);
	$(".main_menu").click(function() {
		swap_content((this).id)
    });

	$(".more").click(function() {
		swap_content((this).id);
    });

	$(".portfolio").click(function() {
		swap_portfolio_content((this).id);
    });

	$(".who_we_are").click(function() {
		swap_who_we_are_content((this).id);
    });


	$("#menu img").hover(
		function() {
			this.src = this.src.replace("_off","_on");
		},
		function() {
			this.src = this.src.replace("_on","_off");
		}
	);


	$("#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: '/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 swap_content(id) {
		if (open != id) {
			var niceTitle = id;
			niceTitle = niceTitle.replace(/[0-9]/g," ");
			$("#"+open+'_content').fadeOut(600, function() {
			    $("#title").fadeOut(300, function() {
				    $("#title").html(niceTitle.replace(/_/g," "));
				    $("#title").fadeIn(300, function() {
					    $("#"+id+'_content').fadeIn(600);
						open = id;
				    });
				});
			});
		}
    }

    function swap_portfolio_content(id) {
		var niceTitle = 'portfolio  ';
		if (open != id) {
			if (niceTitle != $("#title").html()) {
				$("#"+open+'_content').fadeOut(600, function() {
				    $("#title").fadeOut(300, function() {
					    $("#title").html(niceTitle.replace(/_/g," "));
					    $("#title").fadeIn(300, function() {
						    $("#"+id+'_content').fadeIn(600);
							open = id;
					    });
					});
				});
			} else {
				$("#"+open+'_content').fadeOut(600);
			    $("#"+id+'_content').fadeIn(600);
				open = id;
			}
		}
    }

    function swap_who_we_are_content(id) {
		if (open != id) {
			$("#"+open+'_content').fadeOut(600, function() {
			    $("#"+id+'_content').fadeIn(600);
				open = id;
		    });
		}
    }

});
