$(document).ready(function()
{
	// paths to open/closed images
	var openImg = "/media/img/structure/open-sign.png";
	var closedImg = "/media/img/structure/closed-sign.png";
	
	var openAlt = 'Yay, we\'re open!';
	var closedAlt = 'Sorry, we\'re closed!';
	
	var container = '#OpenClosed'; // the element that contains the open/closed image
	
	// lets check the open status
	$.ajax({
		url: '/php/ajax/status.check.php',
		success: function(status)
		{
			var el = $(container);
			if(status == 1)
				el.html('<img width="272" height="77" alt="'+openAlt+'" src="'+openImg+'">');
			else
				el.html('<img width="272" height="77" alt="'+closedAlt+'" src="'+closedImg+'">');
				
		}
	});
	
	// get opening times content
	// first check we need it for this page
	if($('#openingHours').length > 0)
	{
		$.ajax({
			url: '/php/ajax/get.opening.hours.php',
			success: function(html)
			{
				var obj = jQuery.parseJSON(html);

				$('#openingHours h1').html(obj.title.replace('\\',''));
				$('#openingHours p').html(obj.text);
			}
		});
	}
	
	
	// get the latest menu
	// first check we need it for this page
	if($('#menu').length > 0)
	{
		$.ajax({
			url: '/php/ajax/get.menu.php',
			success: function(html)
			{
				$('#menu').html(html);
			}
		});
	}
	
	
	// get press & awards
	// first check we need it for this page
	if($('#press-awards').length > 0)
	{
		$.ajax({
			url: '/php/ajax/get.awards.php',
			success: function(html)
			{
				$('#press-awards').html(html);
			}
		});
	}
	
	$(function() {
		$('#email_error').hide();
		$(".button").click(function() {
		// validate and process form here
		
		var email = $("input#email").val();
		if (email == "" || email == "Enter your email address") {
			$("label#email_error").show();
			$("input#email").focus();
			return false;
		}
		
		var email = $('#email').attr('value');
		
		$.ajax({
			type:	"POST",
			url:	"php/MailingList.php",
			data:	"email="+ email,
			success: function() {
				$('#form').html("<div id='message'></div>");
				$('#message').html("<h2 class='reenie'>Thankyou!</h2>")
				.append("<p>You are now on our mailing list, we'll be in touch soon with juicy blas news!</p>")
				.hide()
				.fadeIn(1500, function() {
					$('#message');
				});
			}
		});
		return false;
		
		});
	});
});
