function mailingListSubmit()
{
	strEmail = document.getElementById('strEmail').value;
	xmlRequest('mailing-list-submit.php?e=' + strEmail, 'mailing-list-loader', 'mailingListResponse(oXMLHttp.responseText)');
}

function mailingListResponse(response)
{
	if (response == "success")
	{
		$("#mailing-list-thanks").fadeIn(1000);
	}
	else
	{
		document.getElementById('mailing-list-loader').src = 'images/ajax-error.gif';
	}
}

function xmlRequest(source, loader, completed_cmds)
{
	// Set the loader image
	if (loader != "")
	{
		oldsrc = document.getElementById(loader).src;
		document.getElementById(loader).src = 'images/ajax.gif';
	}
	
	var oXMLHttp = null;

 	if (window.XMLHttpRequest) 
    	oXMLHttp = new XMLHttpRequest();
 	else 
  		if (window.ActiveXObject)
    		oXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
   		if (oXMLHttp != null) {
			oXMLHttp.onreadystatechange = function ()
	  		{
  			if (oXMLHttp.readyState == 4) {
			 	if (oXMLHttp.status == 200) {
					if (loader != "") document.getElementById(loader).src = oldsrc;
					eval(completed_cmds);
			  	}
		  	}
 		}
	}
	oXMLHttp.open("GET", source, true);
	oXMLHttp.send(null);
}

function ajaxifyLinks(selector)
{
	$(selector).each(function() {
		$(this).click(function() {
			var getpage = $(this).attr("rel");
			$(this).parent().parent().find("a.on").removeClass("on");
			$(this).addClass("on")
			$.get(getpage, function(data) {
				ajaxShowPage(getpage, data);
			});
		});
		if ($(this).attr("href").indexOf("?") == -1)
			$(this).attr("rel",$(this).attr("href").substring(1) + ".php");
		else
			$(this).attr("rel",$(this).attr("href").substring(1).replace("?",".php?"));
		//$(this).attr("href","javascript:void(0);");
	});
}

function ajaxShowPage(getpage, data)
{
	// When page has been fetched...
	lastpage = page;
	page = getpage.substring(0,getpage.indexOf("."));
	
	// Replace div contents, fade it in
	$("#container-ajax").html(data + '<p align="right" style="margin: 5px 10px 5px 10px; clear: left"><a href="http://www.paulpritchard.ca" target="_blank"><img src="images/paul-pritchard.gif" border="0" alt="Designed by Paul Pritchard" /></a></p>');
	$("#container-ajax").fadeIn();
	
	// Span the black background to new div contents
	//if ($("#body").height() < $(document).height()-128-60-46-100)
	//	$("#body").css("height",$(document).height()-128-60-46-100+"px");

	ajaxifyLinks('#container-ajax a.ajax');

	// Thickboxify
	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox

	// Update title
	document.title = "It's Guava Belly! | " + page.substr(0,1).toUpperCase() + page.substr(1);
	
	// Page-specific animations
	if (page == "home")
	{
		$("#album-sale").hover(
			function () {
				$(this).animate({ top: "-2px" },100)
				.animate({ top: "2px" },200)
				.animate({ top: "0px" },100);
			}
		);
		$('#slideshow').cycle({
			timeout: 5000
		});
	} 
	else 
	{
		$("#sidebar").hide();
		if (page == "links")
			sidebar = true;
		if (page != lastpage)
			$("#head-"+page).animate({ marginTop: "1px", height: "122px"},700, "easeOutQuad", function() { if (sidebar) $("#sidebar").fadeIn(2000); });
		else
			$("#head-"+page).css({ marginTop: "1px", height: "122px" });
	}
}