
/* set defaults */
var currentLI = null;
var currentSub = null;
var currentSubLi = null;
var currentSubImg = null;

jQuery(document).ready(function(){	
	$("#nutrition").hide();	
	$(".main-arrow").hide();
	$(".sub-arrow").hide();
});

function showSubMenu(itemname){

	//hide the current submenu if set
	if(currentSub != null){
		$("#" + currentSub).hide("fast");				
		//clear the active current sub li if set
		if(currentSubLi != null){			
			currentSubLi.removeClass('active-arrow');
			currentSubImg.hide();
		}
	}

	//turn off the nutrition table if on
	$("#nutrition").fadeOut("fast");

	//first turn off the current li	
	if(currentLI){
		currentLI.removeClass("active-arrow");
		$("#" + currentSub + "-arrow").hide();
	}	
	//set the current submenu being displayed
	currentSub = itemname;

	currentLI = $("#main-" + itemname).parent();	
	currentLI.addClass("active-arrow");
	$("#" + itemname + "-arrow").show();
	
	//show the submenu
	$("#" + itemname).show("fast");

}

function getNutrition(item_id){

	if(currentSubLi != null){
		//remove the current active LI
		currentSubLi.removeClass('active-arrow');
		currentSubImg.hide();
	}
	
	currentSubImg = $("#" + item_id + "-arrow");
	currentSubLi = currentSubImg.parent();	
	currentSubLi.addClass('active-arrow');
	currentSubImg.show();
	
	$("#nutrition").fadeOut("fast");
	$.get("/items/view", {id:item_id}, showNutrition, "html");	
	
}

function showNutrition(result){	
	$("#nutrition").html(result);
	$("#nutrition").fadeIn("fast");	
}
