


	/* when document is ready */

	$(document).ready(function() {


		// Find categories content ont he page
		if ($(".fr").size() > 0) {
			var $lang = 'fr';
		} else {
			var $lang = 'en';
		}


		//check for oyster menu
		if ($("#oyster-recipe-menu").size() == 1) {


			$("#oyster-recipe-menu").html('');
  			$.ajax({
				type: "GET",
				url: "/index.php/recipes/show",
				data:  {lang: $lang},
				dataType: "json",
				success: function (data) {
					$(data).each(function () {
						$("#oyster-recipe-menu").append('<li id='+this.id+'>'+this.title+'</li>');
					});
				},
				failure: function () {
					$("#oyster-recipe-menu").append('<li id="none">No Recipes!r</li>');
				}
			});

  		$.ajax({
			type: "GET",
			url: "/index.php/recipes/recipedefault",
			data:  {lang: $lang},
			dataType: "json",
			success: function (data) {
				/* load in the content of recipes/X.html where X is the id of the 
				list item clicked and load it into item with ID "ajax-content" */
				$("#ajax-content").html('');
				if (data.title == null) { data.title = 'No Title!' }
				if (data.instructions == null) { data.instructions = 'No Instructions!' }
				if (data.image != null) { data.image = '<img src="/uploads/'+data.image+'" alt="'+data.title+'" align="right" style="padding: 10px;" />' } else { data.image = ''; }
				var multiline_string = '<div id="recipe">'+data.image+'<h2>'+data.title+'</h2><p>'+data.instructions+'</p></div>';
				multiline_string = multiline_string.replace(/(\r\n|[\r\n])/g, "<br />");
				$("#ajax-content").html(multiline_string);
			},
			failure: function () {
				alert('fail default!');
			}
		});


		/* when clicking any list item from the 
		"oyster-recipe-menu" unordered list */

			$("#oyster-recipe-menu li").livequery(function(){ 
				$(this).click(function () {

	  				$.ajax({
						type: "GET",
						url: "/index.php/recipes/single",
						data:  {id: this.id},
						dataType: "json",
						success: function (data) {
							/* load in the content of recipes/X.html where X is the id of the 
							list item clicked and load it into item with ID "ajax-content" */
							$("#ajax-content").html('');
							if (data.title == null) { data.instructions = 'No Title!' }
							if (data.instructions == null) { data.instructions = 'No Instructions!' }
							if (data.image != null) { data.image = '<img src="/uploads/'+data.image+'" alt="'+data.title+'" align="right" style="padding: 10px;" />' } else { data.image = ''; }
							var multiline_string = '<div id="recipe">'+data.image+'<h2>'+data.title+'</h2><p>'+data.instructions+'</p></div>';
							multiline_string = multiline_string.replace(/(\r\n|[\r\n])/g, "<br />");
							$("#ajax-content").html(multiline_string);
						},
						failure: function () {
							alert('fail!');
						}
					});

				});

			});


		}



		//check for oyster menu
		if ($("#news-list").size() == 1) {

			$("#news-list").html('');

		}

  		$.ajax({
			type: "GET",
			url: "/index.php/news/items",
			data:  {lang: $lang},
			dataType: "json",
			success: function (data) {
				$(data).each(function () {
					$("#news-list").append('<li><strong><em>'+this.title+'</em></strong> &ndash; '+this.source+'</li>');
				});
			},
			failure: function () {
				$("#news-list").append('<li id="none">No news!</li>');
			}
		});


	});