var rec;

// class that handles the ajax loading for the recipes page
var Recipes = function() {
	
	// update the category list of links to have them make ajax calls for the recipe lists
	this.updateCatList = function() {
		$('#cats').children('li').each(function() {
			var a = $(this).children('a');
			a.attr('data', a.attr('href'));
			a.bind('click', function() {
				rec.loadRecipeList($(this).attr('data'));
				return false;
			});
		});
	};
	
	// load the recipe list for the specific category
	this.loadRecipeList = function(uri) {
		// update selected list item
		$('#cats').children('li').each(function() {
			var a = $(this).children('a');
			if (a.attr('data') == uri)
				$(this).addClass('selected');
			else
				$(this).removeClass('selected');
		});
		$('#col_r_recipes').attr('innerHTML', '<div class="loading">Loading...</div>');
		$('#col_r_recipes').load(uri, null, this.updateRecipeList);
	};
	
	// update the recipe list of links to have them make ajax calls for the recipe
	this.updateRecipeList = function() {
		$('#recipelist').children('li').each(function() {
			var a = $(this).children('a');
			a.attr('data', a.attr('href'));
			a.bind('click', function() {
				rec.loadRecipe($(this).attr('data'));
				return false;
			});
		});
	};
	
	// load the recipe content for the specific recipe
	this.loadRecipe = function(uri) {
		// update selected list item
		$('#recipelist').children('li').each(function() {
			var a = $(this).children('a');
			if (a.attr('data') == uri)
				$(this).addClass('selected');
			else
				$(this).removeClass('selected');
		});
		$('#col_c_recipes').attr('innerHTML', '<div class="loading">Loading...</div>');
		$('#col_c_recipes').load(uri);
	};
	
	this.loadSingle = function(uri){
		uri = "http://www.seductionmeals.com/2010/10/the-ultimate-lobster-corn-chow.html.recipes.html"
		//uri = "http://www.seductionmeals.com/2008/01/chargrilled-oysters-with-roque.html.recipes.html"
		$('#col_c_recipes').attr('innerHTML', '<div class="loading">Loading...</div>');
		$('#col_c_recipes').load(uri);
	};
};

// ondomready function
$(function() {
	rec = new Recipes();
	rec.updateCatList();
	rec.updateRecipeList();
	rec.loadSingle();
});

