/**
 * @author Ross
 */
    	$(document).ready(function(){
			var options = {path: '/', expires: 10};//Cookie options
			var validId = false;
			
			//Get finish id
			$.fn.getTableId = function(str){
				return table_id = str.replace(/finish-/, '');
			}
			
			//Select the first finish option and the appropriate table
			$.fn.reset = function() {
				//$('a', '.finish li').first().addClass('current');
				table_id = $(this).getTableId($('a', '.finish li').attr('id'));
				$('#finish-' + table_id).addClass('current');
				$('#category-' + table_id).css('display', 'table');
				$('#description-' + table_id).css('display', 'block');
			};
			
			//-------------------------------------------------------------------------------------
			
			//Hide all the tables and descriptions as default
			$('table').each(function(index){
				$(this).css('display', 'none');
			});
			$("div[id^='description-']").css('display', 'none');
			
			//If the user select a new product, delete the cookie which should envoke a reset
			$('.product li').click(function(){
				$.cookie('table_id', null, {path: '/'}); //Delete cookie
			});
			var table_id = $.cookie('table_id'); //assign cookie value
			var tmp = table_id;
			//Goes through each of the current id's, if the table_id doesn't match then reset
			$('a', '.finish li').each(function(index){
				current_table_id = $(this).getTableId($(this).attr('id'));
				if(tmp == current_table_id){
					validId = true;
				}
			});
			
			if(validId == false){
				$(this).reset();
			}
			//Check if cookie is null.  If null reset
			if(table_id !== null){
				$('#finish-' + table_id).addClass('current');
				$('#category-' + table_id).css('display', 'table');
				$('#description-' + table_id).css('display', 'block');
			}else{
				$(this).reset();
			}
			
			//On finish click, store cat_id in cookie and get the appropriate table
			$('a', '.finish li').click(function(){
				$('a', '.finish li').removeClass('current');
				$(this).addClass('current');
				table_id = $(this).getTableId($(this).attr('id'));
				$.cookie('table_id', table_id, options);
				$('table').each(function(index){
					$(this).css('display', 'none');
				});
				$("div[id^='description-']").css('display', 'none');
				$('#category-'+table_id).effect("slide", {direction: "left"}, "slow");
				$('#description-'+table_id).effect("slide", {direction: "left"}, "slow");
			});
			return false;
		});