﻿var newXmlString = '';
var $IDarray = [];
var $quantityArray = [];
var $mealXML;
var $currentItemUpdate = $('');
var DetailsUrl1;
var DisplayTitle;
var ItemID;
var $currentCategory = 1;
var $count;
var $currentEditItem;
var $updateArray = [];
var $xmlArray = [];
var iconAppendCount = 0;
var mealItemCount = 0;
var $mealCount = 0;
var moreIngredients = true;
var $changeQuantity = false;
var updateItem = false;
var burgerBuilderInUse = false;
var deepLink = false;
var slideDown = true;
var selectedMenuItem = '';
var $moreInfoPanelOpen = false;
var strUrl = new String(document.location);
var arrUrl = splitURLVars(strUrl);
var isIE6 = false/*@cc_on || @_jscript_version < 5.7@*/;

var CONTENT = BK.local.MENU_NUTRITION;

var BK = BK || {};
BK.meal = {
	items: [],
	totalCal: 0,
	totalFat: 0,
	totalSatFat: 0,
	totalTransFat: 0,
	totalCholesterol: 0,
	totalCarbs: 0,
	totalSugar: 0,
	totalProtein: 0,
	totalSodium: 0
}

function init() {





	//COOKIES
	if ($.cookie('itemlink') != null) {
		$('#YourMeal').css("display", "block");
		$('#YourMeal .meal-totals').html('<p class="meal-total">' + CONTENT.MEAL_TOTAL + ' <em id="meal-total-info"><strong>0</strong>' + CONTENT.MEAL_CAL + '</em><a href="#" id="more-less-info"></a></p><div id="nutrition-holder"><div id="nutrition-panel"><ul class="total-nutrition1"></ul><ul class="total-nutrition2"></ul><p><a class="print-meal" href="#" id="print-meal">' + CONTENT.MEAL_PRINT + '</a></p></div></div>');
		$('.meal-totals').html($.cookie('mealtotal'));
		var linkString = $.cookie('itemlink');
		var linkArray = new Array();
		linkArray = linkString.split(',');
		var nameString = $.cookie('itemname');
		var nameArray = new Array();
		nameArray = nameString.split(',');
		var caloriesString = $.cookie('itemcalories');
		var caloriesArray = new Array();
		caloriesArray = caloriesString.split(',');
		var fatString = $.cookie('itemfat');
		var fatArray = new Array();
		fatArray = fatString.split(',');
		var satfatString = $.cookie('itemsatfat');
		var satfatArray = new Array();
		satfatArray = satfatString.split(',');
		var trabsfatString = $.cookie('itemtransfat');
		var transfatArray = new Array();
		transfatArray = trabsfatString.split(',');
		var cholesterolString = $.cookie('itemcholesterol');
		var cholesterolArray = new Array();
		cholesterolArray = cholesterolString.split(',');
		var carbsString = $.cookie('itemcarbs');
		var carbsArray = new Array();
		carbsArray = carbsString.split(',');
		var sugarString = $.cookie('itemsugar');
		var sugarArray = new Array();
		sugarArray = sugarString.split(',');
		var proteinString = $.cookie('itemprotein');
		var proteinArray = new Array();
		proteinArray = proteinString.split(',');
		var sodiumString = $.cookie('itemsodium');
		var sodiumArray = new Array();
		sodiumArray = sodiumString.split(',');
		var quantityString = $.cookie('itemquantities');
		var quantityArray = new Array();
		quantityArray = quantityString.split(',');
		var idString = $.cookie('itemids');
		var idsArray = new Array();
		idsArray = idString.split(',');

		$('#YourMeal h2').html('<a>Your Meal</a><em><strong>' + $.cookie('currentcount') + '</strong> items</em>');
		$mealCount = parseInt($('#YourMeal h2 em strong').html(), 10);
		$('#YourMeal .meal-totals').html($.cookie('currentmealtotals'));
		var cookieLength = $.cookie('cookiecount');
		for (var i = 0; i < cookieLength; i++) {
			var firstIndex = linkArray[i].lastIndexOf('/') + 1;
			var lastIndex = linkArray[i].lastIndexOf('.');
			var currentID = linkArray[i].substring(firstIndex, lastIndex);
			var currentQuantities = quantityArray[i].replace(/\;/g, ",");
			var currentIDs = idsArray[i].replace(/\;/g, ",");
			//alert("append item "+i);
			$('ul.items-in-meal').append('<li id="item' + i + '" class="' + currentID + ' meal-items"><p><a class="meal-item-name" rel="' + linkArray[i] + '" href="#">' + nameArray[i] + '</a></p><p><a class="remove-meal-item" href="#">Remove Item</a></p><p class="meal-item-nutrifact"><strong>' + caloriesArray[i] + '</strong>cal</p><ul class="meal-item-info"><li class="calories"><strong>' + caloriesArray[i] + '</strong> calories</li><li class="fat"><strong>' + fatArray[i] + '</strong>g fat</li><li class="satfat"><strong>' + satfatArray[i] + '</strong>g saturated fat</li><li class="transfat"><strong>' + transfatArray[i] + '</strong>g trans fat</li><li class="cholesterol"><strong>' + cholesterolArray[i] + '</strong>mg cholesterol</li><li class="carbs"><strong>' + carbsArray[i] + '</strong>g carbs</li><li class="sugar"><strong>' + sugarArray[i] + '</strong>g sugar</li><li class="protein"><strong>' + proteinArray[i] + '</strong>g protein</li><li class="sodium"><strong>' + sodiumArray[i] + '</strong>mg sodium</li><li class="quantities">' + currentQuantities + '</li><li class="ids">' + currentIDs + '</li></ul></li>');
		}
		BK.meal.totalCal = parseFloat($('#YourMeal .meal-totals ul.total-nutrition1 li.calories strong').html(), 10);
		BK.meal.totalFat = parseFloat($('#YourMeal .meal-totals ul.total-nutrition1 li.fat strong').html(), 10);
		BK.meal.totalSatFat = parseFloat($('#YourMeal .meal-totals ul.total-nutrition1 li.satfat strong').html(), 10);
		BK.meal.totalTransFat = parseFloat($('#YourMeal .meal-totals ul.total-nutrition1 li.transfat strong').html(), 10);
		BK.meal.totalCholesterol = parseFloat($('#YourMeal .meal-totals ul.total-nutrition1 li.cholesterol strong').html(), 10);
		BK.meal.totalCarbs = parseFloat($('#YourMeal .meal-totals ul.total-nutrition2 li.carbs strong').html(), 10);
		BK.meal.totalSugar = parseFloat($('#YourMeal .meal-totals ul.total-nutrition2 li.sugar strong').html(), 10);
		BK.meal.totalProtein = parseFloat($('#YourMeal .meal-totals ul.total-nutrition2 li.protein strong').html(), 10);
		BK.meal.totalSodium = parseFloat($('#YourMeal .meal-totals ul.total-nutrition2 li.sodium strong').html(), 10);
		if ($moreInfoPanelOpen == false) {
			if ($mealCount >= 8) {
				$('a.remove-meal-item').css("left", "186px");
				$('p.meal-item-nutrifact').css("right", "2px");
				$('#meal-items-holder').css("height", "362px");
			}
		} else {
			if ($mealCount >= 5) {
				$('a.remove-meal-item').css("left", "186px");
				$('p.meal-item-nutrifact').css("right", "2px");
				$('#meal-items-holder').css("height", "257px");
			}
		}
	}
	$('<img src="/images/menu-nutrition/bkg.a-menu-item-1row.jpg" />');
	$('<img src="/images/menu-nutrition/bkg.a-menu-item-1row-arrow.jpg" />');
	$('#list_items ul.main-menu li').remove();
	$('ul.variation-list li.filler').remove();
	$('ul.ingredient-list li.filler').remove();
	$('ul.current-nutrition1 li.filler').remove();
	$('ul.current-nutrition2 li.filler').remove();
	$('ul.total-nutrition1 li.filler').remove();
	$('ul.total-nutrition2 li.filler').remove();
	$('ul.items-in-meal li.filler').remove();
	$('ul.allergens li.filler').remove();

	$('#nutrition-panel').css("top", "-105px");
	$('#meal-items-holder').css("max-height", "362px");
	slideDown = true;
	$('#more-less-info').html('More Info');
	$('#more-less-info').css("background-position", "right 5px");
	$moreInfoPanelOpen = false;


	$('.current-item-info, #more-ingredients, #enable-javascript').css("display", "none");
	$.ajax({
		url: '/cms' + CulturePrefix + 'cms_out/menu_nutrition/categories/all.xml',
		datatype: 'xml',
		type: 'get',
		success: function(data) {

			$(data).find('MenuCategory').each(function() {

				var $mainMenu = $('#list_items ul.main-menu');
				ItemId = $(this).attr('ID');
				var $xmlItemName = $(this).children('DisplayTitle').text();
				DisplayTitle = $xmlItemName/*.replace(/®/g, '<sup>®</sup>')*/;


				DetailsUrl1 = $(this).children('DetailsUrl').text();
				$mainMenu.append('<li><a href="' + CulturePrefix + 'menu-nutrition/category' + ItemId + '/index.html" class="category' + ItemId + ' first-list">' + DisplayTitle + '</a></li>');
				addSubMenus(ItemId);
				//$currentCategory += 1;
			});

		},
		complete: function() {
			if (CategoryID != '') {
				if (MenuItemID == "") {
					$('#menu_selection ul').find('.category' + CategoryID).each(function (i) {
				        if(i==0){
				            $(this).click();
				        }
				    });
				}
				else {
				    $('#menu_selection ul').find('#menu-item' + MenuItemID).each(function (i) {
				        if(i==0){
				            $(this).click();
				        }
				    });
				}
			} else {
				$('#intro-info').css("display", "block");
			}
			if (arrUrl['banner'] == 'breakfast-value' && CategoryID == '12') {
				$('#intro-info-breakfast').css("display", "block");
			} else if (arrUrl['banner'] == 'value-menu' && CategoryID == '11') {
				$('#intro-value-menu').css("display", "block");
			}
		}
	})
}
function addSubMenus(currentCategory) {
	var DisplayTitle;
	var DetailsUrl;
	var ItemID;
	var IsHidden;
	$.ajax({
		url: DetailsUrl1,
		datatype: 'xml',
		type: 'get',
		async: false,
		success: function(data) {
		var $data = $(data);
			var $list = $('<ul class="menu-sub-menu1" id="category_' + currentCategory + '"></ul>');
			var $currentLI = $('ul.main-menu li a.category' + currentCategory);
			$(data).children().children().each(function() {
				if (this.tagName == 'MenuItem') {
					//DisplayTitle = $(this).children('DisplayTitle').text();
					//var $currentDisplayName = $(this).children('DisplayTitle').text();
					var $xmlItemName = $(this).children('DisplayTitle').text();
					DisplayTitle = $xmlItemName/*.replace(/®/g, '<sup>®</sup>')*/;

					DetailsUrl = $(this).children('DetailsUrl').text();
					ItemID = $(this).attr("ID");
					IsHidden = $(this).attr("IsHidden");

					if ($xmlItemName.length < 29) {
						var $itemLI = $('<li class="menu_item"><a rel="' + DetailsUrl + '" href="' + CulturePrefix + 'menu-nutrition/category' + currentCategory + '/menu-item' + ItemID + '/index.html" class="ingredient_item" id="menu-item' + ItemID + '">' + DisplayTitle + '</a></li>');
						if (IsHidden != "false") {
							$itemLI.hide();
						}
						$list.append($itemLI);
					} else {
						var $itemLI = $('<li class="menu_item_wide"><a rel="' + DetailsUrl + '" href="' + CulturePrefix + 'menu-nutrition/category' + currentCategory + '/menu-item' + ItemID + '/index.html" class="ingredient_item" id="menu-item' + ItemID + '">' + DisplayTitle + '</a></li>');
						if (IsHidden != "false") {
							$itemLI.hide();
						}
						$list.append($itemLI);
					}
				} else if (this.tagName == 'SubCategory') {
					var $list2 = $('<ul class="menu-sub-menu2"></ul>');
					$(this).children().each(function() {
						var $xmlItemName = $(this).children('DisplayTitle').text();
						DisplayTitle = $xmlItemName/*.replace(/®/g, '<sup>®</sup>')*/;
						DetailsUrl = $(this).children('DetailsUrl').text();
						ItemID = $(this).attr("ID");
						IsHidden = $(this).attr("IsHidden");
						if ($xmlItemName.length < 29 || ItemID == '192') {
							var $itemLI = $('<li class="menu_item"><a rel="' + DetailsUrl + '" href="' + CulturePrefix + 'menu-nutrition/category' + currentCategory + '/menu-item' + ItemID + '/index.html" class="sub_category" id="menu-item' + ItemID + '">' + DisplayTitle + '</a></li>');
							if (IsHidden != "false") {
								$itemLI.hide();
							}
							$list2.append($itemLI);
						} else {
							var $itemLI = $('<li class="menu_item_wide"><a rel="' + DetailsUrl + '" href="' + CulturePrefix + 'menu-nutrition/category' + currentCategory + '/menu-item' + ItemID + '/index.html" class="sub_category" id="menu-item' + ItemID + '">' + DisplayTitle + '</a></li>');
							if (IsHidden != "false") {
								$itemLI.hide();
							}
							$list2.append($itemLI);
						}
					});
					var $newLI = $('<li class="sub-category-name"></li>');
					var $liContents = $('<a href="#">' + $(this).attr('Title') + '</a>');
					$newLI.append($liContents).append($list2).appendTo($list);
				}
			});
			$currentLI.parent().append($list);
		}
	})
}
function addToIngredient(currentIcon) {
	var addAllergen = true;
	var $currentIngredient = currentIcon;
	if (parseInt($currentIngredient.siblings('a').children('em.quantity').html(), 10) < parseInt($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.MaxQuantity').html(), 10)) {
		var addQuantity = (parseInt($currentIngredient.siblings('a').children('em.quantity').html(), 10)) + 1;
		var ingredientCount = (parseInt($currentIngredient.siblings('a').children('em.ingredient-count').html(), 10));
		$currentIngredient.siblings('a.subtractIngredient').css("background-image", "url(/images/en/us/menu-nutrition/bkg.a-down-arrow.gif)");
		if (parseInt($currentIngredient.siblings('a').children('em.quantity').html(), 10) == (parseInt($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.MaxQuantity').html(), 10)) - 1) {
			$currentIngredient.css("background-image", "none");
		}
		track_ingredient_config(selectedMenuItem, $currentIngredient.parent().siblings('.ingredient-info').children('h4').children('strong').html(), 'Add');
		$quantityArray[ingredientCount] = addQuantity;
		if (addQuantity == 1) {
			$currentIngredient.siblings('a.icon').children('span').css({ backgroundPosition: 'left top', display: 'none', width: '14px', height: '14px', left: '25px', top: '15px' });
		} else if (addQuantity == 2) {
			$currentIngredient.siblings('a.icon').children('span').css({ backgroundPosition: '-14px top', display: 'block', width: '14px', height: '14px', left: '25px', top: '15px' });
		} else if (addQuantity == 3) {
			$currentIngredient.siblings('a.icon').children('span').css({ backgroundPosition: '-28px top', display: 'block', width: '14px', height: '14px', left: '25px', top: '15px' });
		} else if (addQuantity == 4) {
			$currentIngredient.siblings('a.icon').children('span').css({ backgroundPosition: '-42px top', display: 'block', width: '14px', height: '14px', left: '25px', top: '15px' });
		} else if (addQuantity == 5) {
			$currentIngredient.siblings('a.icon').children('span').css({ backgroundPosition: '-56px top', display: 'block', width: '14px', height: '14px', left: '25px', top: '15px' });
		} else if (addQuantity == 0) {
			$currentIngredient.siblings('a.icon').children('span').css({ backgroundPosition: '-70px top', display: 'block', width: '21px', height: '26px', left: '16px', top: '2px' });
		}
		$currentIngredient.siblings('a').children('em.quantity').html(addQuantity);
		var $currentCalories = parseFloat($('ul.current-nutrition1').children('li.calories').children('em').html(), 10);
		var $currentFat = parseFloat($('ul.current-nutrition1').children('li.fat').children('em').html(), 10);
		var $currentSatFat = parseFloat($('ul.current-nutrition1').children('li.satfat').children('em').html(), 10);
		var $currentTransFat = parseFloat($('ul.current-nutrition1').children('li.transfat').children('em').html(), 10);
		var $currentCholesterol = parseFloat($('ul.current-nutrition1').children('li.cholesterol').children('em').html(), 10);
		var $currentCarbs = parseFloat($('ul.current-nutrition2').children('li.carbs').children('em').html(), 10);
		var $currentSugar = parseFloat($('ul.current-nutrition2').children('li.sugar').children('em').html(), 10);
		var $currentProtein = parseFloat($('ul.current-nutrition2').children('li.protein').children('em').html(), 10);
		var $currentSodium = parseFloat($('ul.current-nutrition2').children('li.sodium').children('em').html(), 10);
		if (!isNaN(parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Calories').children('strong').html(), 10))) {
			$currentCalories += parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Calories').children('strong').html(), 10);
		}
		if (!isNaN(parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Fat').children('strong').html(), 10))) {
			$currentFat += parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Fat').children('strong').html(), 10);
		}
		if (!isNaN(parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.SaturatedFat').children('strong').html(), 10))) {
			$currentSatFat += parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.SaturatedFat').children('strong').html(), 10);
		}
		if (!isNaN(parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.TransFat').children('strong').html(), 10))) {
			$currentTransFat += parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.TransFat').children('strong').html(), 10);
		}
		if (!isNaN(parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Cholesterol').children('strong').html(), 10))) {
			$currentCholesterol += parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Cholesterol').children('strong').html(), 10);
		}
		if (!isNaN(parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Carbohydrates').children('strong').html(), 10))) {
			$currentCarbs += parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Carbohydrates').children('strong').html(), 10);
		}
		if (!isNaN(parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Sugar').children('strong').html(), 10))) {
			$currentSugar += parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Sugar').children('strong').html(), 10);
		}
		if (!isNaN(parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Protein').children('strong').html(), 10))) {
			$currentProtein += parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Protein').children('strong').html(), 10);
		}
		if (!isNaN(parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Sodium').children('strong').html(), 10))) {
			$currentSodium += parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Sodium').children('strong').html(), 10);
		}
		var $thisItemUL1 = $('<li class="calories"><strong>' + $currentCalories + '</strong> calories<em>' + $currentCalories + '</em></li><li class="fat"><strong>' + $currentFat + '</strong>g fat<em>' + $currentFat + '</em></li><li class="satfat"><strong>' + $currentSatFat + '</strong>g saturated fat<em>' + $currentSatFat + '</em></li><li class="transfat"><strong>' + $currentTransFat + '</strong>g trans fat<em>' + $currentTransFat + '</em></li><li class="cholesterol"><strong>' + $currentCholesterol + '</strong>mg cholesterol<em>' + $currentCholesterol + '</em></li>');
		var $thisItemUL2 = $('<li class="carbs"><strong>' + $currentCarbs + '</strong>g carbs<em>' + $currentCarbs + '</em></li><li class="sugar"><strong>' + $currentSugar + '</strong>g sugar<em>' + $currentSugar + '</em></li><li class="protein"><strong>' + $currentProtein + '</strong>g protein<em>' + $currentProtein + '</em></li><li class="sodium"><strong>' + $currentSodium + '</strong>mg sodium<em>' + $currentSodium + '</em></li>');
		$('ul.current-nutrition1').html($thisItemUL1);
		$('ul.current-nutrition2').html($thisItemUL2);
		$('#Content #menu_selection #YourMeal .meal-totals p.meal-total em strong').html(BK.meal.totalCal);
		var ingredientID = $currentIngredient.siblings("a.icon").attr('id');
		var IDarray = new Array();
		IDarray = ingredientID.split('-');
		var strXmlReplaced = '<MenuItem ID="1"><IngredientPortion><Ingredient ID="' + IDarray[2] + '"/><DefaultQuantity>' + addQuantity + '</DefaultQuantity></IngredientPortion></MenuItem>';
		var testForFlash = false;
		if ($('#flash-holder').children('object').attr('id') != "burgerbuilder") {
			testForFlash = true;
		}
		if (burgerBuilderInUse == true && testForFlash == false) {
			updateQuanity(strXmlReplaced);
		}

		roundNutritionTotals();

		$currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.AllergensUL').children('ul.AllergensUL').children('li').each(function() {
			var allergenID = $(this).attr('class');
			allergenID = allergenID.replace(/Allergen_/, "");
			if ($('#Allergen_' + allergenID).size() > 0) {
				$('#Allergen_' + allergenID).attr('rel', parseInt($('#Allergen_' + allergenID).attr('rel'), 10) + 1);
			} else {
				$('<li id="Allergen_' + allergenID + '" rel="1">' + $(this).html() + '</li>').appendTo('ul.allergens');
			}
		});

		var firstAllergenLI = $('ul.allergens li:first').html();
		firstAllergenLI = firstAllergenLI.replace(/\,/, "");
		$('ul.allergens li:first').html(firstAllergenLI);
	}
	roundNutritionTotals();

}
function subtractFromIngredient(currentIcon) {
	var $currentIngredient = currentIcon;
	if (parseInt($currentIngredient.siblings('a').children('em.quantity').html(), 10) > parseInt($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.MinQuantity').html(), 10)) {
		var subtractQuantity = (parseInt($currentIngredient.siblings('a').children('em.quantity').html(), 10)) - 1;
		var ingredientCount = (parseInt($currentIngredient.siblings('a').children('em.ingredient-count').html(), 10));
		$currentIngredient.siblings('a.addIngredient').css("background-image", "url(/images/en/us/menu-nutrition/bkg.a-up-arrow.gif)");
		$quantityArray[ingredientCount] = subtractQuantity;
		track_ingredient_config(selectedMenuItem, $currentIngredient.parent().siblings('.ingredient-info').children('h4').children('strong').html(), 'Subtract');
		if (subtractQuantity == 1) {
			$currentIngredient.siblings('a.icon').children('span').css({ backgroundPosition: 'left top', display: 'none', width: '14px', height: '14px', left: '25px', top: '15px' });
		} else if (subtractQuantity == 2) {
			$currentIngredient.siblings('a.icon').children('span').css({ backgroundPosition: '-14px top', display: 'block', width: '14px', height: '14px', left: '25px', top: '15px' });
		} else if (subtractQuantity == 3) {
			$currentIngredient.siblings('a.icon').children('span').css({ backgroundPosition: '-28px top', display: 'block', width: '14px', height: '14px', left: '25px', top: '15px' });
		} else if (subtractQuantity == 4) {
			$currentIngredient.siblings('a.icon').children('span').css({ backgroundPosition: '-42px top', display: 'block', width: '14px', height: '14px', left: '25px', top: '15px' });
		} else if (subtractQuantity == 5) {
			$currentIngredient.siblings('a.icon').children('span').css({ backgroundPosition: '-56px top', display: 'block', width: '14px', height: '14px', left: '25px', top: '15px' });
		} else if (subtractQuantity == 0) {
			$currentIngredient.siblings('a.icon').children('span').css({ backgroundPosition: '-70px top', display: 'block', width: '21px', height: '26px', left: '16px', top: '2px' });
			$currentIngredient.css("background-image", "none");
		}
		$currentIngredient.siblings('a').children('em.quantity').html(subtractQuantity);
		var $currentCalories = parseFloat($('ul.current-nutrition1').children('li.calories').children('em').html(), 10);
		var $currentFat = parseFloat($('ul.current-nutrition1').children('li.fat').children('em').html(), 10);
		var $currentSatFat = parseFloat($('ul.current-nutrition1').children('li.satfat').children('em').html(), 10);
		var $currentTransFat = parseFloat($('ul.current-nutrition1').children('li.transfat').children('em').html(), 10);
		var $currentCholesterol = parseFloat($('ul.current-nutrition1').children('li.cholesterol').children('em').html(), 10);
		var $currentCarbs = parseFloat($('ul.current-nutrition2').children('li.carbs').children('em').html(), 10);
		var $currentSugar = parseFloat($('ul.current-nutrition2').children('li.sugar').children('em').html(), 10);
		var $currentProtein = parseFloat($('ul.current-nutrition2').children('li.protein').children('em').html(), 10);
		var $currentSodium = parseFloat($('ul.current-nutrition2').children('li.sodium').children('em').html(), 10);
		if (!isNaN(parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Calories').children('strong').html(), 10))) {
			$currentCalories -= parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Calories').children('strong').html(), 10);
		}
		if (!isNaN(parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Fat').children('strong').html(), 10))) {
			$currentFat -= parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Fat').children('strong').html(), 10);
		}
		if (!isNaN(parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.SaturatedFat').children('strong').html(), 10))) {
			$currentSatFat -= parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.SaturatedFat').children('strong').html(), 10);
		}
		if (!isNaN(parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.TransFat').children('strong').html(), 10))) {
			$currentTransFat -= parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.TransFat').children('strong').html(), 10);
		}
		if (!isNaN(parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Cholesterol').children('strong').html(), 10))) {
			$currentCholesterol -= parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Cholesterol').children('strong').html(), 10);
		}
		if (!isNaN(parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Carbohydrates').children('strong').html(), 10))) {
			$currentCarbs -= parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Carbohydrates').children('strong').html(), 10);
		}
		if (!isNaN(parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Sugar').children('strong').html(), 10))) {
			$currentSugar -= parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Sugar').children('strong').html(), 10);
		}
		if (!isNaN(parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Protein').children('strong').html(), 10))) {
			$currentProtein -= parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Protein').children('strong').html(), 10);
		}
		if (!isNaN(parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Sodium').children('strong').html(), 10))) {
			$currentSodium -= parseFloat($currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.Sodium').children('strong').html(), 10);
		}
		var $thisItemUL1 = $('<li class="calories"><strong>' + $currentCalories + '</strong> calories<em>' + $currentCalories + '</em></li><li class="fat"><strong>' + $currentFat + '</strong>g fat<em>' + $currentFat + '</em></li><li class="satfat"><strong>' + $currentSatFat + '</strong>g saturated fat<em>' + $currentSatFat + '</em></li><li class="transfat"><strong>' + $currentTransFat + '</strong>g trans fat<em>' + $currentTransFat + '</em></li><li class="cholesterol"><strong>' + $currentCholesterol + '</strong>mg cholesterol<em>' + $currentCholesterol + '</em></li>');
		var $thisItemUL2 = $('<li class="carbs"><strong>' + $currentCarbs + '</strong>g carbs<em>' + $currentCarbs + '</em></li><li class="sugar"><strong>' + $currentSugar + '</strong>g sugar<em>' + $currentSugar + '</em></li><li class="protein"><strong>' + $currentProtein + '</strong>g protein<em>' + $currentProtein + '</em></li><li class="sodium"><strong>' + $currentSodium + '</strong>mg sodium<em>' + $currentSodium + '</em></li>');
		$('ul.current-nutrition1').html($thisItemUL1);
		$('ul.current-nutrition2').html($thisItemUL2);
		$('#Content #menu_selection #YourMeal .meal-totals p.meal-total em strong').html(BK.meal.totalCal);
		var ingredientID = $currentIngredient.siblings("a.icon").attr('id');
		var IDarray = new Array();
		IDarray = ingredientID.split('-');
		var strXmlReplaced = '<MenuItem ID="1"><IngredientPortion><Ingredient ID="' + IDarray[2] + '"/><DefaultQuantity>' + subtractQuantity + '</DefaultQuantity></IngredientPortion></MenuItem>';
		var testForFlash = false;
		if ($('#flash-holder').children('object').attr('id') != "burgerbuilder") {
			testForFlash = true;
		}
		if (burgerBuilderInUse == true && testForFlash == false) {
			updateQuanity(strXmlReplaced);
		}
		roundNutritionTotals();

		$currentIngredient.parent().siblings('.ingredient-info').children('ul').children('li.AllergensUL').children('ul.AllergensUL').children('li').each(function() {
			var allergenID = $(this).attr('class');
			allergenID = allergenID.replace(/Allergen_/, "");
			count = parseInt($('#Allergen_' + allergenID).attr('rel'), 10) - 1;
			if (count > 0) {
				$('#Allergen_' + allergenID).attr('rel', count);
			} else {
				$('#Allergen_' + allergenID).remove();
			}
		});

		var firstAllergenLI = $('ul.allergens li:first').html();
		firstAllergenLI = firstAllergenLI.replace(/\,/, "");
		$('ul.allergens li:first').html(firstAllergenLI);


	}
	roundNutritionTotals();
}

function removeItemFromMeal(currentitem) {
	updateItem = false;
	$('a.add-to-meal').css("background-image", "url(/images/en/us/menu-nutrition/bkg.a-add-to-meal.gif)");
	var $currentItem = currentitem;
	$currentItem.parent().parent().remove();
	BK.meal.totalCal -= parseFloat($currentItem.parent().siblings('ul.meal-item-info').children('li.calories').children('strong').html(), 10);
	BK.meal.totalFat -= parseFloat($currentItem.parent().siblings('ul.meal-item-info').children('li.fat').children('strong').html(), 10);
	BK.meal.totalSatFat -= parseFloat($currentItem.parent().siblings('ul.meal-item-info').children('li.satfat').children('strong').html(), 10);
	BK.meal.totalTransFat -= parseFloat($currentItem.parent().siblings('ul.meal-item-info').children('li.transfat').children('strong').html(), 10);
	BK.meal.totalCholesterol -= parseFloat($currentItem.parent().siblings('ul.meal-item-info').children('li.cholesterol').children('strong').html(), 10);
	BK.meal.totalCarbs -= parseFloat($currentItem.parent().siblings('ul.meal-item-info').children('li.carbs').children('strong').html(), 10);
	BK.meal.totalSugar -= parseFloat($currentItem.parent().siblings('ul.meal-item-info').children('li.sugar').children('strong').html(), 10);
	BK.meal.totalProtein -= parseFloat($currentItem.parent().siblings('ul.meal-item-info').children('li.protein').children('strong').html(), 10);
	BK.meal.totalSodium -= parseFloat($currentItem.parent().siblings('ul.meal-item-info').children('li.sodium').children('strong').html(), 10);
	var $currentNutritionList3 = $('<li class="calories"><strong>' + BK.meal.totalCal + '</strong> calories</li><li class="fat"><strong>' + BK.meal.totalFat + '</strong>g fat</li><li class="satfat"><strong>' + BK.meal.totalSatFat + '</strong>g saturated fat</li><li class="transfat"><strong>' + BK.meal.totalTransFat + '</strong>g trans fat</li><li class="cholesterol"><strong>' + BK.meal.totalCholesterol + '</strong>mg cholesterol</li>');
	var $currentNutritionList4 = $('<li class="carbs"><strong>' + BK.meal.totalCarbs + '</strong>g carbs</li><li class="sugar"><strong>' + BK.meal.totalSugar + '</strong>g sugar</li><li class="protein"><strong>' + BK.meal.totalProtein + '</strong>g protein</li><li class="sodium"><strong>' + BK.meal.totalSodium + '</strong>mg sodium</li>');
	$('#Content #menu_selection #YourMeal .meal-totals ul.total-nutrition1').html($currentNutritionList3);
	$('#Content #menu_selection #YourMeal .meal-totals ul.total-nutrition2').html($currentNutritionList4);
	$('#Content #menu_selection #YourMeal .meal-totals p.meal-total em strong').html(BK.meal.totalCal);
	$mealCount--;
	$('#Content #menu_selection #YourMeal h2 em strong').html($mealCount);
	if ($moreInfoPanelOpen == false) {
		if ($mealCount <= 7) {
			$('a.remove-meal-item').css("left", "195px");
			$('p.meal-item-nutrifact').css("right", "10px");
			$('#meal-items-holder').css("height", "100%");
		} else {
			$('a.remove-meal-item').css("left", "186px");
			$('p.meal-item-nutrifact').css("right", "2px");
			$('#meal-items-holder').css("height", "362px");
		}
	} else {
		if ($mealCount <= 5) {
			$('a.remove-meal-item').css("left", "195px");
			$('p.meal-item-nutrifact').css("right", "10px");
			$('#meal-items-holder').css("height", "100%");
		} else {
			$('a.remove-meal-item').css("left", "186px");
			$('p.meal-item-nutrifact').css("right", "2px");
			$('#meal-items-holder').css("height", "257px");
		}
	}
	//COOKIE
	var cookieCount = 0;
	var linkArray = new Array();
	var nameArray = new Array();
	var caloriesArray = new Array();
	var fatArray = new Array();
	var satfatArray = new Array();
	var transfatArray = new Array();
	var cholesterolArray = new Array();
	var carbsArray = new Array();
	var sugarArray = new Array();
	var proteinArray = new Array();
	var sodiumArray = new Array();
	var quantityArray = new Array();
	var idArray = new Array();
	$('ul.items-in-meal').children('li').each(function() {
		linkArray.push($(this).children('p:first').children('a').attr('rel'));
		nameArray.push($(this).children('p:first').children('a').html());
		caloriesArray.push($(this).children('ul.meal-item-info').children('li.calories').children('strong').html());
		fatArray.push($(this).children('ul.meal-item-info').children('li.fat').children('strong').html());
		satfatArray.push($(this).children('ul.meal-item-info').children('li.satfat').children('strong').html());
		transfatArray.push($(this).children('ul.meal-item-info').children('li.transfat').children('strong').html());
		cholesterolArray.push($(this).children('ul.meal-item-info').children('li.cholesterol').children('strong').html());
		carbsArray.push($(this).children('ul.meal-item-info').children('li.carbs').children('strong').html());
		sugarArray.push($(this).children('ul.meal-item-info').children('li.sugar').children('strong').html());
		proteinArray.push($(this).children('ul.meal-item-info').children('li.protein').children('strong').html());
		sodiumArray.push($(this).children('ul.meal-item-info').children('li.sodium').children('strong').html());
		var quantityString = $(this).children('ul.meal-item-info').children('li.quantities').html();
		quantityArray.push(quantityString.replace(/\,/g, ";"));
		var idString = $(this).children('ul.meal-item-info').children('li.ids').html();
		idArray.push(idString.replace(/\,/g, ";"));
		cookieCount++;
	});
	$.cookie('itemlink', linkArray);
	$.cookie('itemname', nameArray);
	$.cookie('itemcalories', caloriesArray);
	$.cookie('itemfat', fatArray);
	$.cookie('itemsatfat', satfatArray);
	$.cookie('itemtransfat', transfatArray);
	$.cookie('itemcholesterol', cholesterolArray);
	$.cookie('itemcarbs', carbsArray);
	$.cookie('itemsugar', sugarArray);
	$.cookie('itemprotein', proteinArray);
	$.cookie('itemsodium', sodiumArray);
	$.cookie('itemquantities', quantityArray);
	$.cookie('itemids', idArray);

	$.cookie('currentcount', $('#YourMeal h2 em strong').html());
	$.cookie('cookiecount', cookieCount);
	$.cookie('currentmealtotals', $('#YourMeal .meal-totals').html());

	$('#meal-limit-message').css("display", "none");
	$('a.add-to-meal').css("opacity", "1");
}

function addItemToMeal(currentitem) {
	if ($mealCount < 15) {
		var $currentItem = currentitem;
		if (updateItem == true) {
			var removeThisItem = "#" + $currentItemUpdate;
			BK.meal.totalCal -= parseFloat($(removeThisItem).children('ul.meal-item-info').children('li.calories').children('strong').html(), 10);
			BK.meal.totalFat -= parseFloat($(removeThisItem).children('ul.meal-item-info').children('li.fat').children('strong').html(), 10);
			BK.meal.totalSatFat -= parseFloat($(removeThisItem).children('ul.meal-item-info').children('li.satfat').children('strong').html(), 10);
			BK.meal.totalTransFat -= parseFloat($(removeThisItem).children('ul.meal-item-info').children('li.transfat').children('strong').html(), 10);
			BK.meal.totalCholesterol -= parseFloat($(removeThisItem).children('ul.meal-item-info').children('li.cholesterol').children('strong').html(), 10);
			BK.meal.totalCarbs -= parseFloat($(removeThisItem).children('ul.meal-item-info').children('li.carbs').children('strong').html(), 10);
			BK.meal.totalSugar -= parseFloat($(removeThisItem).children('ul.meal-item-info').children('li.sugar').children('strong').html(), 10);
			BK.meal.totalProtein -= parseFloat($(removeThisItem).children('ul.meal-item-info').children('li.protein').children('strong').html(), 10);
			BK.meal.totalSodium -= parseFloat($(removeThisItem).children('ul.meal-item-info').children('li.sodium').children('strong').html(), 10);
			$mealCount--;
			$('#Content #menu_selection #YourMeal h2 em strong').html($mealCount);
			$(removeThisItem).remove();
		}
		BK.meal.totalCal += parseFloat($('ul.current-nutrition1').children('li.calories').children('strong').html(), 10);
		BK.meal.totalFat += parseFloat($('ul.current-nutrition1').children('li.fat').children('strong').html(), 10);
		BK.meal.totalSatFat += parseFloat($('ul.current-nutrition1').children('li.satfat').children('strong').html(), 10);
		BK.meal.totalTransFat += parseFloat($('ul.current-nutrition1').children('li.transfat').children('strong').html(), 10);
		BK.meal.totalCholesterol += parseFloat($('ul.current-nutrition1').children('li.cholesterol').children('strong').html(), 10);
		BK.meal.totalCarbs += parseFloat($('ul.current-nutrition2').children('li.carbs').children('strong').html(), 10);
		BK.meal.totalSugar += parseFloat($('ul.current-nutrition2').children('li.sugar').children('strong').html(), 10);
		BK.meal.totalProtein += parseFloat($('ul.current-nutrition2').children('li.protein').children('strong').html(), 10);
		BK.meal.totalSodium += parseFloat($('ul.current-nutrition2').children('li.sodium').children('strong').html(), 10);

		var $currentNutritionList3 = $('<li class="calories"><strong>' + BK.meal.totalCal + '</strong> calories</li><li class="fat"><strong>' + BK.meal.totalFat + '</strong>g fat</li><li class="satfat"><strong>' + BK.meal.totalSatFat + '</strong>g saturated fat</li><li class="transfat"><strong>' + BK.meal.totalTransFat + '</strong>g trans fat</li><li class="cholesterol"><strong>' + BK.meal.totalCholesterol + '</strong>mg cholesterol</li>');
		var $currentNutritionList4 = $('<li class="carbs"><strong>' + BK.meal.totalCarbs + '</strong>g carbs</li><li class="sugar"><strong>' + BK.meal.totalSugar + '</strong>g sugar</li><li class="protein"><strong>' + BK.meal.totalProtein + '</strong>g protein</li><li class="sodium"><strong>' + BK.meal.totalSodium + '</strong>mg sodium</li>');
		$('#Content #menu_selection #YourMeal .meal-totals ul.total-nutrition1').html($currentNutritionList3);
		$('#Content #menu_selection #YourMeal .meal-totals ul.total-nutrition2').html($currentNutritionList4);
		if (updateItem == true) {
			var currentIDcount = $currentItemUpdate;
			updateItem = true;
		} else {
			var currentIDcount = 'item' + mealItemCount;
			updateItem = false;
		}
		var withSups = $('h3.current-item-headline').html();
		var withSup = withSups.replace('<sup>', '');
		//var currentHeadline = withSup.replace('</sup>', '');
		var currentHeadline = withSups;


		if (currentHeadline.length < 16) {
			var modifiedHeadline = currentHeadline/*.replace(/®/g, '<sup>®</sup>')*/;
			var $yourMealLI = $('<li id="' + currentIDcount + '" class="' + MenuItemID + ' meal-items"><p><a rel="' + $currentDisplatTitle + '" href="#" class="meal-item-name"><em>' + modifiedHeadline + '</em></a></p><p><a href="#" class="remove-meal-item">Remove Item</a></p><p class="meal-item-nutrifact"><strong>' + parseFloat($('ul.current-nutrition1').children('li.calories').children('strong').html(), 10) + '</strong>cal</p><ul class="meal-item-info"><li class="calories"><strong>' + parseFloat($('ul.current-nutrition1').children('li.calories').children('strong').html(), 10) + '</strong> calories</li><li class="fat"><strong>' + parseFloat($('ul.current-nutrition1').children('li.fat').children('strong').html(), 10) + '</strong>g fat</li><li class="satfat"><strong>' + parseFloat($('ul.current-nutrition1').children('li.satfat').children('strong').html(), 10) + '</strong>g saturated fat</li><li class="transfat"><strong>' + parseFloat($('ul.current-nutrition1').children('li.transfat').children('strong').html(), 10) + '</strong>g trans fat</li><li class="cholesterol"><strong>' + parseFloat($('ul.current-nutrition1').children('li.cholesterol').children('strong').html(), 10) + '</strong>mg cholesterol</li><li class="carbs"><strong>' + parseFloat($('ul.current-nutrition2').children('li.carbs').children('strong').html(), 10) + '</strong>g carbs</li><li class="sugar"><strong>' + parseFloat($('ul.current-nutrition2').children('li.sugar').children('strong').html(), 10) + '</strong>g sugar</li><li class="protein"><strong>' + parseFloat($('ul.current-nutrition2').children('li.protein').children('strong').html(), 10) + '</strong>g protein</li><li class="sodium"><strong>' + parseFloat($('ul.current-nutrition2').children('li.sodium').children('strong').html(), 10) + '</strong>mg sodium</li><li class="quantities">' + $quantityArray + '</li><li class="ids">' + $IDarray + '</li></ul></li>');
		} else {
			var shortenedHeadline = currentHeadline.substring(0, 16);
			var modifiedHeadline = shortenedHeadline/*.replace(®/g, '<sup>®</sup>')*/;
			var $yourMealLI = $('<li id="' + currentIDcount + '" class="' + MenuItemID + ' meal-items"><p><a title="' + currentHeadline + '" rel="' + $currentDisplatTitle + '" href="#" class="meal-item-name"><em>' + modifiedHeadline + '...</em></a></p><p><a href="#" class="remove-meal-item">Remove Item</a></p><p class="meal-item-nutrifact"><strong>' + parseFloat($('ul.current-nutrition1').children('li.calories').children('strong').html(), 10) + '</strong>cal</p><ul class="meal-item-info"><li class="calories"><strong>' + parseFloat($('ul.current-nutrition1').children('li.calories').children('strong').html(), 10) + '</strong> calories</li><li class="fat"><strong>' + parseFloat($('ul.current-nutrition1').children('li.fat').children('strong').html(), 10) + '</strong>g fat</li><li class="satfat"><strong>' + parseFloat($('ul.current-nutrition1').children('li.satfat').children('strong').html(), 10) + '</strong>g saturated fat</li><li class="transfat"><strong>' + parseFloat($('ul.current-nutrition1').children('li.transfat').children('strong').html(), 10) + '</strong>g trans fat</li><li class="cholesterol"><strong>' + parseFloat($('ul.current-nutrition1').children('li.cholesterol').children('strong').html(), 10) + '</strong>mg cholesterol</li><li class="carbs"><strong>' + parseFloat($('ul.current-nutrition2').children('li.carbs').children('strong').html(), 10) + '</strong>g carbs</li><li class="sugar"><strong>' + parseFloat($('ul.current-nutrition2').children('li.sugar').children('strong').html(), 10) + '</strong>g sugar</li><li class="protein"><strong>' + parseFloat($('ul.current-nutrition2').children('li.protein').children('strong').html(), 10) + '</strong>g protein</li><li class="sodium"><strong>' + parseFloat($('ul.current-nutrition2').children('li.sodium').children('strong').html(), 10) + '</strong>mg sodium</li><li class="quantities">' + $quantityArray + '</li><li class="ids">' + $IDarray + '</li></ul></li>');
		}


		$currentEditItem = $yourMealLI;
		$('ul.items-in-meal').append($yourMealLI);
		$('#Content #menu_selection #YourMeal .meal-totals p.meal-total em strong').html(BK.meal.totalCal);
		$mealCount++;
		$('#Content #menu_selection #YourMeal h2 em strong').html($mealCount);
		mealItemCount++;
		if ($moreInfoPanelOpen == false) {
			if ($mealCount >= 8) {
				$('a.remove-meal-item').css("left", "186px");
				$('p.meal-item-nutrifact').css("right", "2px");
				$('#meal-items-holder').css("height", "362px");
			}
		} else {
			if ($mealCount >= 6) {
				$('a.remove-meal-item').css("left", "186px");
				$('p.meal-item-nutrifact').css("right", "2px");
				$('#meal-items-holder').css("height", "257px");
			}
		}



		//COOKIE
		var cookieCount = 0;
		var linkArray = new Array();
		var nameArray = new Array();
		var caloriesArray = new Array();
		var fatArray = new Array();
		var satfatArray = new Array();
		var transfatArray = new Array();
		var cholesterolArray = new Array();
		var carbsArray = new Array();
		var sugarArray = new Array();
		var proteinArray = new Array();
		var sodiumArray = new Array();
		var quantityArray = new Array();
		var idArray = new Array();
		$('ul.items-in-meal').children('li').each(function() {
			linkArray.push($(this).children('p:first').children('a').attr('rel'));
			nameArray.push($(this).children('p:first').children('a').html());
			caloriesArray.push($(this).children('ul.meal-item-info').children('li.calories').children('strong').html());
			fatArray.push($(this).children('ul.meal-item-info').children('li.fat').children('strong').html());
			satfatArray.push($(this).children('ul.meal-item-info').children('li.satfat').children('strong').html());
			transfatArray.push($(this).children('ul.meal-item-info').children('li.transfat').children('strong').html());
			cholesterolArray.push($(this).children('ul.meal-item-info').children('li.cholesterol').children('strong').html());
			carbsArray.push($(this).children('ul.meal-item-info').children('li.carbs').children('strong').html());
			sugarArray.push($(this).children('ul.meal-item-info').children('li.sugar').children('strong').html());
			proteinArray.push($(this).children('ul.meal-item-info').children('li.protein').children('strong').html());
			sodiumArray.push($(this).children('ul.meal-item-info').children('li.sodium').children('strong').html());
			var quantityString = $(this).children('ul.meal-item-info').children('li.quantities').html();
			quantityArray.push(quantityString.replace(/\,/g, ";"));
			var idString = $(this).children('ul.meal-item-info').children('li.ids').html();
			idArray.push(idString.replace(/\,/g, ";"));
			cookieCount++;
		});
		$.cookie('itemlink', linkArray);
		$.cookie('itemname', nameArray);
		$.cookie('itemcalories', caloriesArray);
		$.cookie('itemfat', fatArray);
		$.cookie('itemsatfat', satfatArray);
		$.cookie('itemtransfat', transfatArray);
		$.cookie('itemcholesterol', cholesterolArray);
		$.cookie('itemcarbs', carbsArray);
		$.cookie('itemsugar', sugarArray);
		$.cookie('itemprotein', proteinArray);
		$.cookie('itemsodium', sodiumArray);
		$.cookie('itemquantities', quantityArray);
		$.cookie('itemids', idArray);
		$.cookie('currentcount', $('#YourMeal h2 em strong').html());
		$.cookie('cookiecount', cookieCount);
		$.cookie('currentmealtotals', $('#YourMeal .meal-totals').html());
	} else {

		var offset = $('a.add-to-meal').offset();
		$('#meal-limit-message').css("left", (offset.left - 250));
		$('#meal-limit-message').css("top", (offset.top - 70));
		$('#meal-limit-message').css("display", "block");
		$('a.add-to-meal').css("opacity", "0.2");
	}





}

function runUpdate() {
	for (var i = 0; i < $IDarray.length; i++) {
		var strXmlReplaced = '<MenuItem ID="1"><IngredientPortion><Ingredient ID="' + $IDarray[i] + '"/><DefaultQuantity>' + $quantityArray[i] + '</DefaultQuantity></IngredientPortion></MenuItem>';
		updateQuanity(strXmlReplaced);

	}
};

function runMealUpdate() {
	updateMeal($mealXML);
};

function roundNutritionTotals() {
	/* CALORIES
	< 5 cal - express as 0
	≤50 cal - express to nearest 5 cal increment
	> 50 cal - express to nearest 10 cal increment
	*/
	var caloriesFloat = parseFloat($('ul.current-nutrition1 li.calories em').html());
	var caloriesNum = parseFloat($('ul.current-nutrition1 li.calories strong').html());
	if (caloriesNum < 5) {
		caloriesNum = 0;
	}
	else if (caloriesNum <= 50) {
		caloriesNum = RoundDecimal(caloriesNum, 5);
	}
	else {
		caloriesNum = RoundDecimal(caloriesNum, 10);
	}

	/* FAT
	< .5 g - express as 0
	< 5 g - express to nearest .5g increment
	≥5 g - express to nearest 1 g increment
	*/
	var fatFloat = parseFloat($('ul.current-nutrition1 li.fat em').html());
	var fatNum = parseFloat($('ul.current-nutrition1 li.fat strong').html());
	if (fatNum < .5) {
		fatNum = 0;
	}
	else if (fatNum < 5) {
		fatNum = RoundDecimal(fatNum, .5);
	}
	else {
		fatNum = RoundDecimal(fatNum, 1);
	}

	/* SATURATED FAT
	< .5 g - express as 0
	< 5 g - express to nearest .5g increment
	≥5 g - express to nearest 1 g increment
	*/
	var satfatFloat = parseFloat($('ul.current-nutrition1 li.satfat em').html());
	var satfatNum = parseFloat($('ul.current-nutrition1 li.satfat strong').html());
	if (satfatNum < .5) {
		satfatNum = 0;
	}
	else if (satfatNum < 5) {
		satfatNum = RoundDecimal(satfatNum, .5);
	}
	else {
		satfatNum = RoundDecimal(satfatNum, 1);
	}

	/* TRANS FAT
	< .5 g - express as 0
	< 5 g - express to nearest .5g increment
	≥5 g - express to nearest 1 g increment
	*/
	var transfatFloat = parseFloat($('ul.current-nutrition1 li.transfat em').html());
	var transfatNum = parseFloat($('ul.current-nutrition1 li.transfat strong').html());
	if (transfatNum < .5) {
		transfatNum = 0;
	}
	else if (transfatNum < 5) {
		transfatNum = RoundDecimal(transfatNum, .5);
	}
	else {
		transfatNum = RoundDecimal(transfatNum, 1);
	}

	/* CHOLESTEROL
	< 2 mg - express as 0
	2 - 5 mg - express as "less than 5 mg"
	> 5 mg - express to nearest 5 mg increment
	*/
	var cholesterolFloat = parseFloat($('ul.current-nutrition1 li.cholesterol em').html());
	var cholesterolNum = parseFloat($('ul.current-nutrition1 li.cholesterol strong').html());
	if (cholesterolNum < 2) {
		cholesterolNum = 0;
	}
	else if (cholesterolNum >= 2 && cholesterolNum <= 5) {
		cholesterolNum = RoundDecimal(cholesterolNum, 1);
	}
	else {
		cholesterolNum = RoundDecimal(cholesterolNum, 5);
	}

	/* SODIUM
	< 5 mg - express as 0
	5 - 140 mg - express to nearest 5 mg increment
	> 140 mg - express to nearest 10 mg increment
	*/
	var sodiumFloat = parseFloat($('ul.current-nutrition2 li.sodium em').html());
	var sodiumNum = parseFloat($('ul.current-nutrition2 li.sodium strong').html());
	if (sodiumNum < 5) {
		sodiumNum = 0;
	}
	else if (sodiumNum >= 5 && sodiumNum.Amount <= 140) {
		sodiumNum = RoundDecimal(sodiumNum, 5);
	}
	else {
		sodiumNum = RoundDecimal(sodiumNum, 10);
	}

	/* CARBS
	< .5 g - express as 0
	< 1 g - express as "Contains less than 1 g" or "less than 1 g"
	≥1 g - express to nearest 1 g increment
	*/
	var carbsFloat = parseFloat($('ul.current-nutrition2 li.carbs em').html());
	var carbsNum = parseFloat($('ul.current-nutrition2 li.carbs strong').html());
	if (carbsNum < .5) {
		carbsNum = 0;
	}
	else if (carbsNum < 1) {
		carbsNum = RoundDecimal(carbsNum, .1);
	}
	else {
		carbsNum = RoundDecimal(carbsNum, 1);
	}

	/* SUGAR
	< .5 g - express as 0 
	< 1 g - express as "Contains less than 1 g" or "less than 1 g"
	≥1 g - express to nearest 1 g increment
	*/
	var sugarFloat = parseFloat($('ul.current-nutrition2 li.sugar em').html());
	var sugarNum = parseFloat($('ul.current-nutrition2 li.sugar strong').html());
	if (sugarNum < .5) {
		sugarNum = 0;
	}
	else if (sugarNum < 1) {
		sugarNum = RoundDecimal(sugarNum, .1);
	} else {
		sugarNum = RoundDecimal(sugarNum, 1);
	}


	/* PROTEIN
	< .5 g - express as 0 
	< 1 g - express as "Contains less than 1 g" or "less than 1 g" or to 1 g if .5 g to < 1 g
	≥1 g - express to nearest 1 g increment
	*/
	var proteinFloat = parseFloat($('ul.current-nutrition2 li.protein em').html());
	var proteinNum = parseFloat($('ul.current-nutrition2 li.protein strong').html());
	if (proteinNum < .5) {
		proteinNum = 0;
	}
	else if (proteinNum < 1) {
		proteinNum = RoundDecimal(proteinNum, .1);
	}
	else {
		proteinNum = RoundDecimal(proteinNum, 1);
	}

	var $thisItemUL1 = $('<li class="calories"><strong>' + caloriesNum + '</strong> calories<em>' + caloriesFloat + '</em></li><li class="fat"><strong>' + fatNum + '</strong>g fat<em>' + fatFloat + '</em></li><li class="satfat"><strong>' + satfatNum + '</strong>g saturated fat<em>' + satfatFloat + '</em></li><li class="transfat"><strong>' + transfatNum + '</strong>g trans fat<em>' + transfatFloat + '</em></li><li class="cholesterol"><strong>' + cholesterolNum + '</strong>mg cholesterol<em>' + cholesterolFloat + '</em></li>');
	var $thisItemUL2 = $('<li class="carbs"><strong>' + carbsNum + '</strong>g carbs<em>' + carbsFloat + '</em></li><li class="sugar"><strong>' + sugarNum + '</strong>g sugar<em>' + sugarFloat + '</em></li><li class="protein"><strong>' + proteinNum + '</strong>g protein<em>' + proteinFloat + '</em></li><li class="sodium"><strong>' + sodiumNum + '</strong>mg sodium<em>' + sodiumFloat + '</em></li>');
	$('ul.current-nutrition1').html($thisItemUL1);
	$('ul.current-nutrition2').html($thisItemUL2);
	//alert("calories: " + caloriesNum + "// fat: " + fatNum + "// sat fat: " + satfatNum + "// trans fat: " + transfatNum + "// cholesterol: " + cholesterolNum + "// sodium: " + sodiumNum + "// carbs: " + carbsNum + "// sugar: " + sugarNum + "// protein: " + proteinNum);
};

function RoundDecimal(decValue, decNearest) {
	//var decRounded = decValue % decNearest;
	//return (decRounded < (decNearest / 2)) ? decValue - decRounded : decValue + (decNearest - decRounded);
	return Math.round(decValue * (1 / decNearest)) / (1 / decNearest);
};



function menuActive(currentselection) {
	var $currentSelection = currentselection;
	$currentSelection.addClass('Active');
	$currentSelection.parent().siblings().find('a.Active').removeClass('Active');
	$('ul.sub-menu-2').remove();
	$('ul.menu-sub-menu1').css("display", "none");
	$currentSelection.siblings("ul").css("display", "block");
	$currentSelection.siblings("ul").css("overflow-y", "auto");
	$currentSelection.siblings("ul").css("overflow-x", "hidden");
	if ($currentSelection.parent().attr("class") == "sub-category-name") {
		$currentSelection.siblings("ul").css("display", "none");
		$currentSelection.parent().parent().css("display", "block");
		var ulHtml = $currentSelection.siblings("ul").html();
		var strSubCategory = $currentSelection.text().replace(/ /g, '_').replace('\'', '').replace('®', '').replace('™', '');
		var subMenu2UL = $('<ul class="sub-menu-2" id="sub_' + strSubCategory + '"></ul>');
		//var subMenu2UL = $('<ul class="sub-menu-2"></ul>');
		$(subMenu2UL).append(ulHtml);
		$(subMenu2UL).appendTo('#list_items');
	}
}

function moreIngredientsButton(morebutton) {
	var $moreButton = morebutton;
	if (moreIngredients == true) {
		track_more_expand(selectedMenuItem, 'More');
		$('#Content #menu_selection #edit_menu #ingredient-list').css("height", "236px");
		$moreButton.css("background-position", "right top");
		moreIngredients = false;

		if ($IDarray.length <= 18) {
			$('#ingredient-list').css("background-image", "url(/images/menu-nutrition/bkg.ingredient-tray-1row.png)");
		} else {
			$('#ingredient-list').css("background-image", "url(/images/menu-nutrition/bkg.ingredient-tray-2row.png)");
		}
	} else if (moreIngredients == false) {
		track_more_expand(selectedMenuItem, 'Less');
		$('#Content #menu_selection #edit_menu #ingredient-list').css("height", "67px");
		$moreButton.css("background-position", "left top");
		moreIngredients = true;
		$('#ingredient-list').css("background-image", "none");
	}
}

$(document).ready(function() {
	init();

	$('#Content #menu_selection #select_from_menu ul li a').live("click", function() {
		$('#list_items ul.main-menu li ul').css('max-height', parseInt(($('#list_items ul.main-menu').height() - 2), 10));
	});
	$('#menu_selection ul li ul li a.ingredient_item, #menu_selection ul li ul li a.sub_category, ul.sub-menu-2 li a, #variation-list li.each-variation p a').live("click", function(event) {
		/*var currentCategoryClass = $(this).parent().parent().siblings('a').attr('class');
		var splitClass = new Array();
		splitClass = currentCategoryClass.split(" ");
		var currentCategoryID = splitClass[0].replace(/category/, "");*/
		$('ul.allergens li').remove();
		iconAppendCount = 0;
		$('#Content #menu_selection #select_from_menu ul li a').removeClass('Active');
		$('ul.sub-menu-2').remove();
		$('#Content #menu_selection #edit_menu #ingredient-list').css({ height: '67px', backgroundImage: 'none', left: '276px' });
		$('#Content #menu_selection #edit_menu #more-ingredients').css("background-position", "left top");
		$('#more-ingredients').css("display", "none");
		$('ul.menu-sub-menu1').css("display", "none");
		$('p.allergensTitle').css("display", "block");
		$('#dollar-badge').empty();

		updateItem = false;
		$('#Content #menu_selection #edit_menu #ingredient-list').html('');
		$('#YourMeal, .current-item-info').css("display", "block");

		$updateArray = [];
		var $this = $(this);
		var xmlLink = $(this).attr("rel");
		var BKitems = BKitems || {};
		BKitems.meal = {
			totalCal: 0,
			totalFat: 0,
			totalSatFat: 0,
			totalTransFat: 0,
			totalCholesterol: 0,
			totalCarbs: 0,
			totalSugar: 0,
			totalProtein: 0,
			totalSodium: 0,
			currentQuantity: 1,
			minQuantity: 0,
			maxQuantity: 0
		}

		var $ingredientCount = 0;

		var BriefCaption;
		var Allergens = "";

		$.ajax({
			url: $this.attr('rel'),
			datatype: 'xml',
			type: 'get',
			success: function(data) {
				var $data = $(data);
				MenuItemID = $data.find('MenuItem').attr('ID');
				var $useBurgerBuilder = $data.find('MenuItem').attr('BurgerBuilderEnabled');
				//var $currentItemName = $data.find('DisplayTitle:first').text();

				//var $currentDisplayName = $data.find('DisplayTitle:first').text();
				var $xmlItemName = $data.find('DisplayTitle:first').text();
				selectedMenuItem = $xmlItemName;
				track_menu_item_select($xmlItemName);
				$currentItemName = $xmlItemName/*.replace(/®/g, '<sup>®</sup>')*/;


				if ($currentItemName.indexOf("...") == "19") {
					$currentItemName = $this.attr('Title');
				}
				$('#Content #menu_selection #edit_menu h3.current-item-headline').html($currentItemName);
				BriefCaption = $data.find('MenuMetaData BriefCaption:first').text();
				$('p.current-selection-desc').html(BriefCaption);
				if ($changeQuantity == false) {
					$quantityArray = [];
					$IDarray = [];
					$('a.add-to-meal').css("background-image", "url(/images/en/us/menu-nutrition/bkg.a-add-to-meal.gif)");
				}
				if ($useBurgerBuilder == "true") {
					$('#flash-holder').html('<div id="burgerbuilder"><img src="' + $data.find('MenuItemAltImagePath').text() + '" /></div>');
					var flashvars = { XMLPath: xmlLink };
					var params = { allowFullScreen: true, allowScriptAccess: "always", wmode: "transparent" };

					var attributes = { id: "burgerbuilder" };
					swfobject.embedSWF("/flash" + CulturePrefix + "burgerbuilder.swf", "burgerbuilder", "900", "400", "9.0.0", "js/expressInstall.swf", flashvars, params, attributes);
					burgerBuilderInUse = true;
				} else if ($useBurgerBuilder == "false") {
					burgerBuilderInUse = false;
					$('#flash-holder').html('<img src="' + $data.find('MenuItemAltImagePath').text() + '" />');


				}

				$('#variation-list').empty();
				var defaultMenuItemId = $data.find('MenuItemVariations').attr('DefaultMenuItemID');
				var defaultMenuItemTitle = $data.find('MenuItemVariations').attr('Title');
				$data.find('MenuItemVariations MenuItemVariation').each(function() {
					var $itemVariationsLI = $('<li class="each-variation"></li>');
					if (MenuItemID == $(this).attr('MenuItemID')) {

						$itemVariationsLI.append('<p class="menuItemVariations"><a class="active" href="' + CulturePrefix + 'menu-nutrition/category3/menu-item' + $(this).attr('MenuItemID') + '/index.html" rel="/cms' + CulturePrefix + 'cms_out/menu_nutrition/menu_items/' + $(this).attr('MenuItemID') + '.xml" title="' + defaultMenuItemTitle + '"><span>' + $(this).attr('TitleAbbreviation') + '</span></a>');
					} else {
						$itemVariationsLI.append('<p class="menuItemVariations"><a href="' + CulturePrefix + 'menu-nutrition/category3/menu-item' + $(this).attr('MenuItemID') + '/index.html" rel="/cms' + CulturePrefix + 'cms_out/menu_nutrition/menu_items/' + $(this).attr('MenuItemID') + '.xml" title="' + defaultMenuItemTitle + '"><span>' + $(this).attr('TitleAbbreviation') + '</span></a>');
					}

					$('#variation-list').append($itemVariationsLI);
				});
				if (defaultMenuItemId == '') {
					$('#variation-list').hide();
				} else {
					$('#variation-list').show();
					var ingredientListPosition = $('#ingredient-list').position();
					var ingredientListLeft = parseInt((ingredientListPosition.left + $('#variation-list').width() + 20), 10)
					$('#ingredient-list').css('left', ingredientListLeft);
				}
				$IDarray = [];

				$('#ingredient-list').empty();
				$data.find('Ingredients IngredientPortion').each(function() {

					var allergensUL = $('<ul class="AllergensUL"></ul>');
					$(this).children('Ingredient').children('Allergens').children('Allergen').each(function() {
						$('<li class="Allergen_' + $(this).attr("ID") + '>, ' + $(this).children('MenuMetaData').children('DisplayTitle').text() + '</li>"').appendTo(allergensUL);
					});
					$IDarray.push($(this).children("Ingredient").attr('ID'));

					var $itemListLI = $('<li class="each-ingredient" id="id' + $(this).children("Ingredient").attr('IconOrder') + '"></li>');
					if ($changeQuantity == false) {
						$quantityArray.push(parseInt($(this).children('DefaultQuantity').text()));
					}
					$itemListLI.append('<p class="rollover-name">' + $(this).find('Ingredient MenuMetaData DisplayTitle').text() + '</p><p class="ingredientBtns"><a class="addIngredient" href="#">Add</a><a class="icon" id="ingredient-id-' + $(this).children("Ingredient").attr('ID') + '"><span class="current-quantity"></span>' + $(this).find('Ingredient MenuMetaData DisplayTitle').text() + '<em class="quantity">' + $quantityArray[$ingredientCount] + '</em><em class="ingredient-count">' + $ingredientCount + '</em></a><a class="subtractIngredient" href="#">Subtract</a></p>');

					var $ingredientInfoDiv = $('<div class="ingredient-info"></div>');

					$ingredientInfoDiv.append('<h4><strong>' + $(this).find('Ingredient MenuMetaData DisplayTitle').text() + '</strong> (per serving)</h4>');
					var $nutritionItemList = $('<ul></ul>');
					$nutritionItemList.append('<li class="AllergensUL">' + allergensUL.parent().html() + '</li><li class="DefaultQuantity">' + $(this).find('DefaultQuantity').text() + '</li><li class="MinQuantity">' + $(this).find('MinQuantity').text() + '</li><li class="MaxQuantity">' + $(this).find('MaxQuantity').text() + '</li>');
					var $ingredientID = $(this).children('Ingredient').attr('ID');
					$updateArray.push($ingredientID);

					$(this).children('Ingredient').children('Allergens').children('Allergen').each(function() {
						var allergenID = $(this).attr('ID');
						if ($quantityArray[$ingredientCount] != 0) {
							if ($('#Allergen_' + allergenID).size() > 0) {
								$('#Allergen_' + allergenID).attr('rel', parseInt($('#Allergen_' + allergenID).attr('rel'), 10) + 1);
							} else {
								$('<li id="Allergen_' + allergenID + '" rel="1">, ' + $(this).children('MenuMetaData').children('DisplayTitle').text() + '</li>').appendTo('ul.allergens');
							}
						}
					});


					$(this).find('NutritionItems NutritionItem Name').each(function() {
						switch ($(this).text()) {
							case "Calories":
								BKitems.meal.totalCal += (parseFloat($(this).siblings('Amount').text(), 10)) * $quantityArray[$ingredientCount];
								$nutritionItemList.append('<li class="Calories"><strong>' + $(this).siblings('Amount').text() + '</strong> calories</li>');
								break;
							case "Fat":
								BKitems.meal.totalFat += (parseFloat($(this).siblings('Amount').text(), 10)) * $quantityArray[$ingredientCount];
								$nutritionItemList.append('<li class="Fat"><strong>' + $(this).siblings('Amount').text() + '</strong>g fat</li>');
								break;
							case "Saturated Fat":
								BKitems.meal.totalSatFat += (parseFloat($(this).siblings('Amount').text(), 10)) * $quantityArray[$ingredientCount];
								$nutritionItemList.append('<li class="SaturatedFat"><strong>' + $(this).siblings('Amount').text() + '</strong>g saturated fat</li>');
								break;
							case "Trans Fat":
								BKitems.meal.totalTransFat += (parseFloat($(this).siblings('Amount').text(), 10)) * $quantityArray[$ingredientCount];
								$nutritionItemList.append('<li class="TransFat"><strong>' + $(this).siblings('Amount').text() + '</strong>g trans fat</li>');
								break;
							case "Cholesterol":
								BKitems.meal.totalCholesterol += (parseFloat($(this).siblings('Amount').text(), 10)) * $quantityArray[$ingredientCount];
								$nutritionItemList.append('<li class="Cholesterol"><strong>' + $(this).siblings('Amount').text() + '</strong>mg cholesterol</li>');
								break;
							case "Carbohydrates":
								BKitems.meal.totalCarbs += (parseFloat($(this).siblings('Amount').text(), 10)) * $quantityArray[$ingredientCount];
								$nutritionItemList.append('<li class="Carbohydrates"><strong>' + $(this).siblings('Amount').text() + '</strong>g carbs</li>');
								break;
							case "Sugar":
								BKitems.meal.totalSugar += (parseFloat($(this).siblings('Amount').text(), 10)) * $quantityArray[$ingredientCount];
								$nutritionItemList.append('<li class="Sugar"><strong>' + $(this).siblings('Amount').text() + '</strong>g sugar</li>');
								break;
							case "Protein":
								BKitems.meal.totalProtein += (parseFloat($(this).siblings('Amount').text(), 10)) * $quantityArray[$ingredientCount];
								$nutritionItemList.append('<li class="Protein"><strong>' + $(this).siblings('Amount').text() + '</strong>g protein</li>');
								break;
							case "Sodium":
								BKitems.meal.totalSodium += (parseFloat($(this).siblings('Amount').text(), 10)) * $quantityArray[$ingredientCount];
								$nutritionItemList.append('<li class="Sodium"><strong>' + $(this).siblings('Amount').text() + '</strong>mg sodium</li>');
								break;
						}
					});
					$ingredientCount += 1;
					var $currentNutritionList1 = $('<li class="calories"><strong>' + BKitems.meal.totalCal + '</strong> calories<em>' + BKitems.meal.totalCal + '</em></li><li class="fat"><strong>' + BKitems.meal.totalFat + '</strong>g fat<em>' + BKitems.meal.totalFat + '</em></li><li class="satfat"><strong>' + BKitems.meal.totalSatFat + '</strong>g saturated fat<em>' + BKitems.meal.totalSatFat + '</em></li><li class="transfat"><strong>' + BKitems.meal.totalTransFat + '</strong>g trans fat<em>' + BKitems.meal.totalTransFat + '</em></li><li class="cholesterol"><strong>' + BKitems.meal.totalCholesterol + '</strong>mg cholesterol<em>' + BKitems.meal.totalCholesterol + '</em></li>');
					var $currentNutritionList2 = $('<li class="carbs"><strong>' + BKitems.meal.totalCarbs + '</strong>g carbs<em>' + BKitems.meal.totalCarbs + '</em></li><li class="sugar"><strong>' + BKitems.meal.totalSugar + '</strong>g sugar<em>' + BKitems.meal.totalSugar + '</em></li><li class="protein"><strong>' + BKitems.meal.totalProtein + '</strong>g protein<em>' + BKitems.meal.totalProtein + '</em></li><li class="sodium"><strong>' + BKitems.meal.totalSodium + '</strong>mg sodium<em>' + BKitems.meal.totalSodium + '</em></li>');
					$('#Content #menu_selection #edit_menu .current-item-nutrition ul.current-nutrition1').html($currentNutritionList1);
					$('#Content #menu_selection #edit_menu .current-item-nutrition ul.current-nutrition2').html($currentNutritionList2);
					$ingredientInfoDiv.append($nutritionItemList);
					$itemListLI.append($ingredientInfoDiv);
					var currentID = $(this).children("Ingredient").attr('ID');

					if (MenuItemID != 2004 && MenuItemID != 2005 && MenuItemID != 2006 && MenuItemID != 2007 && MenuItemID != 2008 && MenuItemID != 2009 && MenuItemID != 2010) {
						if ((currentID != 85) && (currentID != 25) && (currentID != 17) && (currentID != 29) && (currentID != 120) && (currentID != 111) && (currentID != 134) && (currentID != 135) && currentID != 14 && currentID != 140 && currentID != 50 && currentID != 30 && currentID != 36 && currentID != 127 && currentID != 6 && currentID != 129 && currentID != 141 && currentID != 19 && currentID != 119 && currentID != 131) {
							if ($(this).find('DefaultQuantity').text() != 0) {
								$('#Content #menu_selection #edit_menu #ingredient-list').prepend($itemListLI);
								iconAppendCount++;
							} else {
								$('#Content #menu_selection #edit_menu #ingredient-list').append($itemListLI);
								iconAppendCount++;
							}
						}
					}
					if (MenuItemID == 30 || MenuItemID == 120 || MenuItemID == 149) {
						$('#ingredient-id-118, #ingredient-id-26, #ingredient-id-74, #ingredient-id-116').parent().parent().remove();
					}
					if (MenuItemID == 103) {
						if ($("li.each-ingredient").length == 12) {
							$('#ingredient-id-20:first, #ingredient-id-10:first, #ingredient-id-124:first, #ingredient-id-61:first, #ingredient-id-90:first, #ingredient-id-112:first').parent().parent().remove();
							$('#ingredient-list').css("left", "398px");
						}
					}
					if (MenuItemID == 7 || MenuItemID == 8) {
						if ($("li.each-ingredient").length > 50) {
							$('#ingredient-id-98:first, #ingredient-id-1002:first, #ingredient-id-41:first, #ingredient-id-67:first, #ingredient-id-81:first, #ingredient-id-76:first, #ingredient-id-74:first, #ingredient-id-118:first, #ingredient-id-86:first, #ingredient-id-3:first, #ingredient-id-1000:first, #ingredient-id-1003:first, #ingredient-id-1001:first, #ingredient-id-7:first, #ingredient-id-137:first, #ingredient-id-11:first, #ingredient-id-136:first, #ingredient-id-2000:first, #ingredient-id-18:first, #ingredient-id-26:first, #ingredient-id-116:first, #ingredient-id-133:first, #ingredient-id-12:first, #ingredient-id-52:first, #ingredient-id-138:first, #ingredient-id-126:first, #ingredient-id-115:first').parent().parent().remove();
							//$('#ingredient-list').css("left", "398px");
						}
					}

				});
				var iconCount = 0;
				$('.icon').each(function() {
					if ($(this).children('em.quantity').html() == 1) {
						$(this).children('span').css({ backgroundPosition: 'left top', display: 'none', width: '14px', height: '14px', left: '25px', top: '15px' });
					} else if ($(this).children('em.quantity').html() == 2) {
						$(this).children('span').css({ backgroundPosition: '-14px top', display: 'block', width: '14px', height: '14px', left: '25px', top: '15px' });
					} else if ($(this).children('em.quantity').html() == 3) {
						$(this).children('span').css({ backgroundPosition: '-28px top', display: 'block', width: '14px', height: '14px', left: '25px', top: '15px' });
					} else if ($(this).children('em.quantity').html() == 4) {
						$(this).children('span').css({ backgroundPosition: '-42px top', display: 'block', width: '14px', height: '14px', left: '25px', top: '15px' });
					} else if ($(this).children('em.quantity').html() == 5) {
						$(this).children('span').css({ backgroundPosition: '-56px top', display: 'block', width: '14px', height: '14px', left: '25px', top: '15px' });
					} else if ($(this).children('em.quantity').html() == 0) {
						$(this).children('span').css({ backgroundPosition: '-70px top', display: 'block', width: '21px', height: '26px', left: '16px', top: '2px' });
					}
					if ($(this).children('em.quantity').html() == $(this).parent().siblings('.ingredient-info').children('ul').children('li.MaxQuantity').html()) {
						$(this).siblings('a.addIngredient').css("background-image", "none");
					} else if ($(this).children('em.quantity').html() == 0) {
						$(this).siblings('a.subtractIngredient').css("background-image", "none");
					}
					iconCount++;
				});
				for (var i = 0; i < (iconCount + 1); i++) {
					$('.each-ingredient').each(function() {
						var currentID = parseInt($(this).attr("id").replace(/id/, ""));
						if (currentID == i) {
							$(this).appendTo('#ingredient-list');
						}
					});
				}
				if (iconAppendCount == 1) {
					$('#Content #menu_selection #edit_menu #ingredient-list li').css("display", "none");
					$('#Content #menu_selection #edit_menu #more-ingredients').css("display", "none");
				} else if (iconAppendCount <= 9 || $('#flash-holder').children('img').attr('src') == '/cms/en/us/cms_out/digital_assets/graphics/menu_nutrition/menu_items/meal_builder/CrownTenders4Piece_380x700.png') {
					$('#Content #menu_selection #edit_menu #more-ingredients').css("display", "none");
				} else {
					$('#Content #menu_selection #edit_menu #ingredient-list li').css("display", "block");
					$('#Content #menu_selection #edit_menu #more-ingredients').css("display", "block");
				}

				$currentDisplatTitle = xmlLink;
				if ($changeQuantity == true) {
					if ($useBurgerBuilder == "true") {
						setTimeout("runUpdate()", 5000);
					}
					$('a.add-to-meal').css("background-image", "url(/images/en/us/menu-nutrition/bkg.a-update-meal.gif)");
					$changeQuantity = false;
				}
				$('#Content #menu_selection #edit_menu #ingredient-list li.each-ingredient:eq(8)').css("margin-right", "40px");
				roundNutritionTotals();
				if ($mealCount == 15) {
					var offset = $('a.add-to-meal').offset();
					$('#meal-limit-message').css("left", (offset.left - 250));
					$('#meal-limit-message').css("top", (offset.top - 70));
					$('#meal-limit-message').css("display", "block");
					$('a.add-to-meal').css("opacity", "0.2");
				}

				var $currentNutritionList3 = $('<li class="calories"><strong>0</strong> calories</li><li class="fat"><strong>0</strong>g fat</li><li class="satfat"><strong>0</strong>g saturated fat</li><li class="transfat"><strong>0</strong>g trans fat</li><li class="cholesterol"><strong>0</strong>mg cholesterol</li>');
				var $currentNutritionList4 = $('<li class="carbs"><strong>0</strong>g carbs</li><li class="sugar"><strong>0</strong>g sugar</li><li class="protein"><strong>0</strong>g protein</li><li class="sodium"><strong>0</strong>mg sodium</li>');
				$('#Content #menu_selection #YourMeal .meal-totals ul.total-nutrition1').html($currentNutritionList3);
				$('#Content #menu_selection #YourMeal .meal-totals ul.total-nutrition2').html($currentNutritionList4);
				var firstAllergenLI = $('ul.allergens li:first').html();
				if (firstAllergenLI != null) {
					firstAllergenLI = firstAllergenLI.replace(/\,/, "");
					$('ul.allergens li:first').html(firstAllergenLI);
				}
			},
			complete: function() {
				/* BEGIN: Value Meal $1 Badge Remove After Promotion */
				$('#SectionFooter').css('top', '635px');
				if (MenuItemID == 179 || MenuItemID == 184 || MenuItemID == 41 || MenuItemID == 151 || MenuItemID == 154 || MenuItemID == 157 || MenuItemID == 131 || MenuItemID == 219 || MenuItemID == 169 || MenuItemID == 183 || MenuItemID == 52 || MenuItemID == 48 || MenuItemID == 56 || MenuItemID == 60) {
					if ($('#dollar-badge img').length == 0) {
						$('#dollar-badge').append('<img src=\"/images' + CulturePrefix + 'menu-nutrition/one_dollar.png" alt=\"\$1" />');
					}
					// This if statement may need to stay after promotion
					if (MenuItemID == 131) {
						$('#SectionFooter').css('top', '655px');
					}
				}
				else if (MenuItemID == 210) {
					if ($('#dollar-badge img').length == 0) {
						$('#dollar-badge').append('<img src=\"/images' + CulturePrefix + 'menu-nutrition/one_dollar_39_cents.png" alt=\"\$1.39" />');
						$('#dollar-badge').css('left', '632px');
						$('#dollar-badge').css('top', '294px');
					}
				}
				else if (MenuItemID == 68) {
					if ($('#dollar-badge img').length == 0) {
						$('#dollar-badge').append('<img src=\"/images' + CulturePrefix + 'menu-nutrition/one_dollar_19_cents.png" alt=\"\$1.19" />');
						$('#dollar-badge').css('left', '522px');
						$('#dollar-badge').css('top', '298px');
					}
				} else if (MenuItemID == 5 || MenuItemID == 10 || MenuItemID == 103 || MenuItemID == 192 || MenuItemID == 2004 || MenuItemID == 20 || MenuItemID == 165 || MenuItemID == 24 || MenuItemID == 30 || MenuItemID == 31 || MenuItemID == 180) {
					if ($('#dollar-badge img').length == 0) {
						$('#dollar-badge').append('<img src=\"/images' + CulturePrefix + 'menu-nutrition/one_dollar.png" alt=\"\$1" />');
					}
				}
				/* END: Value Meal $1 Badge Remove After Promotion */
			}


		});


		var ingredientCount = 0;
		return false;
	});
	$('.addIngredient').live('click', function() {
		$('#intro-info-breakfast, #intro-value-menu').css("display", "none");
		addToIngredient($(this));
		return false;
	});

	$('.subtractIngredient').live('click', function() {
		$('#intro-info-breakfast, #intro-value-menu').css("display", "none");
		subtractFromIngredient($(this));
		return false;
	});

	$('a.remove-meal-item').live('click', function() {
		removeItemFromMeal($(this));
		return false;
	});

	$('a.meal-item-name').live('click', function() {
		$('#intro-info').css("display", "none");
		$('#intro-info-breakfast, #intro-value-menu').css("display", "none");
		$currentItemUpdate = $(this).parent().parent().attr("id");
		$changeQuantity = true;
		var $ingredientQuantities = $(this).parent().siblings('ul.meal-item-info').children('li.quantities').html();
		var $ingredientIDs = $(this).parent().siblings('ul.meal-item-info').children('li.ids').html();
		var $currentLink = $(this).attr('rel');
		$quantityArray = $ingredientQuantities.split(',');
		$IDarray = $ingredientIDs.split(',');
		$xmlArray = [];
		$xmlString = '';
		for (var i = 0; i < $quantityArray.length; i++) {
			var strXmlReplaced = '<IngredientPortion><Ingredient ID="' + $IDarray[i] + '"/><DefaultQuantity>' + $quantityArray[i] + '</DefaultQuantity></IngredientPortion>';
			$xmlArray.push(strXmlReplaced);
		}
		$xmlString = '<MenuItem ID="1">' + $xmlArray + '</MenuItem>';
		newXmlString = $xmlString.replace(/\,/g, '');
		$("#menu_selection #select_from_menu ul li ul li a[rel='" + $currentLink + "']").trigger("click");
		updateItem = true;
		return false;
	});

	$('a.add-to-meal').click(function() {
		track_add_to_meal(selectedMenuItem);
		addItemToMeal($(this));
		return false;
	});
	var hoverTimeout;
	$('#list_items').hover(function() {
		clearTimeout(hoverTimeout);
	}, function() {
		hoverTimeout = setTimeout(function() {
			$('ul.sub-menu-2').remove();
			$('#Content #menu_selection #select_from_menu h2').css("background-position", "left bottom");
			$('#Content #menu_selection #select_from_menu h2').css("width", "202px");
			$('#Content #menu_selection #select_from_menu #list_items').css("width", "202px");
			$('ul.menu-sub-menu1').css("display", "none");
			$('#Content #menu_selection #select_from_menu ul li a').removeClass('Active');
		}, 1000);
	});

	$('#select_from_menu').mouseover(function() {
		$('#intro-info, #intro-info-breakfast, #intro-value-menu').css("display", "none");
	});

	$('#Content #menu_selection #select_from_menu ul.main-menu li a').live("click", function() {
		menuActive($(this));
		return false;
	});

	$('#meal-limit-message .close').click(function() {
		$(this).parent().css("display", "none");
	});


	/*---------------------ADD MEAL BUILDER--------------*/
	/*$('#Content #menu_selection #YourMeal h2 a').click(function() {
	$('#flash-holder').html('');
	$('#flash-holder').html('<div id="mealbuilder">flash 9 required</div>');
	var mealXML;
	var menuItemXML;
	var ingredientPortionArray = [];
	var menuItemArray = [];
	var count = 0;
	$('ul.items-in-meal li.meal-items').each(function() {
	var currentItem = $(this).attr('class');
	var currentItemID = currentItem.replace(/ meal-items/, '');
	var $eachMenuItem = $('<MenuItem ID="' + currentItemID + '"></MenuItem>');
	var $idString = $(this).children('ul.meal-item-info').children('li.ids').html();
	var $quantityString = $(this).children('ul.meal-item-info').children('li.quantities').html();
	var $itemIDarray = [];
	var $itemQuantityArray = [];
	$itemIDarray = $idString.split(',');
	$itemQuantityArray = $quantityString.split(',');
	for (var i = 0; i < $itemIDarray.length; i++) {
	var $ingredientPortionLI = '<IngredientPortion><Ingredient ID="' + $itemIDarray[i] + '"/><DefaultQuantity>' + $itemQuantityArray[i] + '</DefaultQuantity></IngredientPortion>';
	ingredientPortionArray.push($ingredientPortionLI);
	}
	menuItemXML = '<MenuItem ID="' + currentItemID + '">' + ingredientPortionArray + '</MenuItem>';
	menuItemArray.push(menuItemXML);
	count++;
	});
	var xmlPath = '/cms' + CulturePrefix + 'cms_out/menu_nutrition/menu_items/';
	mealXML = '<Meal>' + menuItemArray + '</Meal>';
	$mealXML = mealXML.replace(/\,/g, '');
	var flashvars = { XMLPath: xmlPath, targetPath: "" };
	var params = { allowFullScreen: true, allowScriptAccess: "always", wmode: "transparent" };
	var attributes = { id: "mealbuilder" };
	swfobject.embedSWF("/flash" + CulturePrefix + "mealbuilder.swf", "mealbuilder", "500", "400", "9.0.0", "js/expressInstall.swf", flashvars, params, attributes);
	setTimeout("runMealUpdate()", 2000);
	return false;
	});*/
	$('#more-ingredients').click(function() {
		moreIngredientsButton($(this));
		return false;
	});

	$('#more-less-info').click(function() {
		if (slideDown == true) {
			$("#nutrition-panel").animate({ top: "0px" }, 500);
			$("#meal-items-holder").animate({ maxHeight: "257px" }, 500);
			slideDown = false;
			$(this).html('Less Info');
			$(this).css("background-position", "right -5px");
			$moreInfoPanelOpen = true;

			if ($mealCount <= 5) {
				$('a.remove-meal-item').css("left", "195px");
				$('p.meal-item-nutrifact').css("right", "10px");
				if (isIE6 == true) {
					$("#meal-items-holder").css("height", "100%");
				}
			} else {
				$('a.remove-meal-item').css("left", "186px");
				$('p.meal-item-nutrifact').css("right", "2px");
				if (isIE6 == true) {
					$("#meal-items-holder").animate({ height: "257px" }, 500);
				}
			}

		} else {
			$("#nutrition-panel").animate({ top: "-105px" }, 500);
			$("#meal-items-holder").animate({ maxHeight: "362px" }, 500);
			slideDown = true;
			$(this).html('More Info');
			$(this).css("background-position", "right 5px");
			$moreInfoPanelOpen = false;
			if ($mealCount <= 7) {
				$('a.remove-meal-item').css("left", "195px");
				$('p.meal-item-nutrifact').css("right", "10px");
				if (isIE6 == true) {
					$("#meal-items-holder").css("height", "100%");
				}
			} else {
				$('a.remove-meal-item').css("left", "186px");
				$('p.meal-item-nutrifact').css("right", "2px");
				if (isIE6 == true) {
					$("#meal-items-holder").animate({ height: "362px" }, 500);
				}
			}
		}
		return false;
	});
	$('.each-ingredient').live("mouseover", function() {
		$(this).children('p.ingredientBtns').children('a.icon').css("background-position", "left bottom");
		$(this).children('p.ingredientBtns').children('a.icon').children(".current-quantity").css("opacity", "0.2");
	});
	$('.each-ingredient').live("mouseout", function() {
		$(this).children('p.ingredientBtns').children('a.icon').css("background-position", "left top");
		$(this).children('p.ingredientBtns').children('a.icon').children(".current-quantity").css("opacity", "1");
	});

	$('#print-meal').click(function() {
		track_print_meal();
		window.print();
	});

	if ($.browser.msie && $.browser.version < 7) {
		var intContentHeight = parseInt(($('#Content').height() + 140), 10);
		$('#MenuTab').css({ 'height': intContentHeight });
		$('#GlobalHeader').css({ 'height': intContentHeight });
	}

});




