function MultiDimensionalArray(iRows,iCols)
{
var i;
var j;
   var a = new Array(iRows);
   for (i=0; i < iRows; i++)
   {
       a[i] = new Array(iCols);
       for (j=0; j < iCols; j++)
       {
           a[i][j] = "";
       }
   }
   return(a);
}

function sortByTime(a, b) {
    var x = a[2];
    var y = b[2];
	if(x === '' || y === ''){
		return (1);
	}
	else{
   		return (x-y);
	}
}
function updateHTML(elmId, value) {
 //         document.getElementById(elmId).innerHTML = value;
}

function setytplayerState(newState) {
  updateHTML("playerstate", newState);
}

function onYouTubePlayerReady(playerId) {
  ytplayer = document.getElementById("myytplayer");
  setInterval(updateytplayerInfo, 250);
  updateytplayerInfo();
  ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
  ytplayer.addEventListener("onError", "onPlayerError");
}

function onytplayerStateChange(newState) {
  setytplayerState(newState);
}

function onPlayerError(errorCode) {
  alert("An error occured: " + errorCode);
}

function updateytplayerInfo() {
  updateHTML("bytesloaded", getBytesLoaded());
  updateHTML("bytestotal", getBytesTotal());
  updateHTML("videoduration", getDuration());
  updateHTML("videotime", getCurrentTime());
  updateHTML("startbytes", getStartBytes());
  updateHTML("volume", getVolume());
}

// functions for the api calls
function loadNewVideo(id, startSeconds) {
  if (ytplayer) {
	ytplayer.loadVideoById(id, parseInt(startSeconds,10));
  }
}

function cueNewVideo(id, startSeconds) {
  if (ytplayer) {
	ytplayer.cueVideoById(id, startSeconds);
  }
}

function play() {
  if (ytplayer) {
	ytplayer.playVideo();
  }
}

function pause() {
  if (ytplayer) {
	ytplayer.pauseVideo();
  }
}

function stop() {
  if (ytplayer) {
	ytplayer.stopVideo();
  }
}

function getPlayerState() {
  if (ytplayer) {
	return ytplayer.getPlayerState();
  }
}

function seekTo(seconds) {
  if (ytplayer) {
	ytplayer.seekTo(seconds, true);
  }
}

function getBytesLoaded() {
  if (ytplayer) {
	return ytplayer.getVideoBytesLoaded();
  }
}

function getBytesTotal() {
  if (ytplayer) {
	return ytplayer.getVideoBytesTotal();
  }
}

function getCurrentTime() {
  if (ytplayer) {
	return ytplayer.getCurrentTime();
  }
}

function getDuration() {
  if (ytplayer) {
	return ytplayer.getDuration();
  }
}

function getStartBytes() {
  if (ytplayer) {
	return ytplayer.getVideoStartBytes();
  }
}

function mute() {
  if (ytplayer) {
	ytplayer.mute();
  }
}

function unMute() {
  if (ytplayer) {
	ytplayer.unMute();
  }
}

function getEmbedCode() {
  alert(ytplayer.getVideoEmbedCode());
}

function getVideoUrl() {
  alert(ytplayer.getVideoUrl());
}

function setVolume(newVolume) {
  if (ytplayer) {
	ytplayer.setVolume(newVolume);
  }
}

function getVolume() {
  if (ytplayer) {
	return ytplayer.getVolume();
  }
}

function clearVideo() {
  if (ytplayer) {
	ytplayer.clearVideo();
  }
}
function playSound(_sound){
	if(_sound == 'alert'){
		$('#alert_audio').setFile("../sounds/Alarm.mp3");
		$("#alert_audio").play();
	}
	else if(_sound == 'cheer'){
		$('#alert_audio').setFile("../sounds/Boxing Bell.mp3");
		$("#alert_audio").play();
	}
}

function UserEdit(_firstTime,_terms) { 
	_string = "useredit.php?";
	if(_firstTime){
		_string += "first&height=190&width=350&modal=true";
	}
	else{
		_string += "&height=190&width=350&modal=true";
	}
	tb_show("User Information",_string,null);
	
}

function ReportThis(_type,_itemID){
	$('#reportThis').html('reporting...');
	_dataString = "status=reportThis&type=" + _type + "&itemID=" + _itemID;
	$.ajax({type: "POST",
		url: "process.php",
		data: _dataString,
		dataType: "xml",
		success: function(xml){
			$.growl("dinneratmyplace","item has been reported");
			$('#reportThis').html('reported.');
		}
	});
}


function checkForEmptyFields(formData, jqForm, options) { 
	var form = jqForm[0]; 
	var checkCount = $(":checkbox").fieldValue();
	if(checkCount.length ==0 ){
			tb_show("Waiter","#TB_inline?height=100&width=350&inlineId=enterRecipes");
			return false;
	}
	else if(checkCount.length ==1){
		if($('#recEngine:checked').val() !== null) {
			tb_show("Waiter","#TB_inline?height=100&width=350&inlineId=enterRecipes");
			return false;
		}
	}
    else if (!form.servings.value) { 
        tb_show("Maitre D","#TB_inline?height=100&width=350&inlineId=enterServings"); 
        return false; 
    }
	
	/*if (!form.ingName0.value) {
		alert('Please enter at least one ingredient');
		return false;
	}
	if (!form.stepText0.value) {
		alert('Please enter at least one step');
		return false;
	}*/
	tb_show("Thinking","thinking.html?modal=true",null);
}


function processRecipeChoices(responseXML) { 
	var $index = 0;	
	if($("validation", responseXML).text() == "success") {
		tb_remove();
		var $location = "cooking.php?servings=" + $("servings", responseXML).text();
		$("recipe", responseXML).each(function(){
			$location += "&recipeID" + $index + "=" + $("recipeID", this).text();
			$index++;
		});
		window.location.href=($location);
	}
	else{
		var $location = "cooking.php?servings=" + $("servings", responseXML).text();
		$("recipe", responseXML).each(function(){
			$location += "&recipeID" + $index + "=" + $("recipeID", this).text();
			$index++;
		});
		window.location.href=($location);
		
		//var $error = "error.php?recipe1ErrorID=" + $("recipe1ErrorID", responseXML).text() + "&recipe2ErrorID="+ $("recipe2ErrorID", responseXML).text() + "&errorNum=" + $("errorNum", responseXML).text() + "&modal=true";
		/*
		$location = "error.php?servings=" + $("servings", responseXML).text();
		$("recipe", responseXML).each(function(){
			$location += "&recipeID" + $index + "=" + $("recipeID", this).text();
			$index++;
		});
		$index = 0;
		$("errorInfo", responseXML).each(function(){
			if($("errorNum", this).text() == "0"){
				$location += "&errorInfo_" + $index + "=true&errorNum_" + $index + "=0&recipe1ErrorID_" + $index + "=" + $("recipe1ErrorID", responseXML).text() + "&recipe2ErrorID_" + $index + "="+ $("recipe2ErrorID", responseXML).text();
			}else if ($("errorNum", this).text() == "1"){
				$location += "&errorInfo_" + $index + "=true&errorNum_" + $index + "=1&ovenCount_" + $index + "=" + $("ovenCount", responseXML).text();
			}else if ($("errorNum", this).text() == "2"){
				$location += "&errorInfo_" + $index + "=true&errorNum_" + $index + "=2&rangeCount_" + $index + "=" + $("rangeCount", responseXML).text();
			}else if ($("errorNum", this).text() == "4"){
				$location += "&errorInfo_" + $index + "=true&errorNum_" + $index + "=4&userSkill=" + $index + "=" + $("userSkill", responseXML).text() + "&menuSkill=" + $index + "=" + $("menuSkill", responseXML).text();
			}else{
				$location += "&errorInfo_" + $index + "=true&errorNum_" + $index + "=3";
			}
			$index++;
		});		
		/*
		$("recipe", responseXML).each(function(){
			$error += "&recipeID" + $index + "=" + $("recipeID", this).text();
			$index++;
		});
		$location += "&servings=" + $("servings", responseXML).text();
		$location += "&modal=true";
		//tb_remove();
		tb_show("There seems to be an issue...",$location,null);
		*/
	}
}

function urlencode(str) {
return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}

function recipeSelection(_recipes){
	$.ajax({type: "POST",
		url: "process.php",
		data: "status=recipeNames" ,
		dataType: "xml",
		success: function(xml){
			$("#loadingAll").hide("slow");
			var _index = 0;
				$("RecipeHeader", xml).each(function(){
					_tempArray = new Array(0);
					_tempArray.push($("RecipeID", this).text());
					_tempArray.push($("RecipeName", this).text());
					_tempArray.push($("RecipeType", this).text());
					_tempArray.push($("RecipeTime", this).text());
					_tempArray.push($("RecipeDesc", this).text());
					_recipes.push(_tempArray);
					/*
					_recipes[_index][0] = $("RecipeID", this).text();
					_recipes[_index][1] = $("RecipeName", this).text();
					_recipes[_index][2] = $("RecipeType", this).text();
					_recipes[_index][3] = $("RecipeTime", this).text();
					_recipes[_index][4] = $("RecipeDesc", this).text();					
					_index++;
					*/
			});
			//_index =0;
			while(_index < _recipes.length){
				var $tempHtml = "<div class='checks' id='" + _recipes[_index][0] +
					"'> <INPUT TYPE=CHECKBOX recType='"+_recipes[_index][2] +
					"' full='"+ _recipes[_index][1] +
					"' id='"+ _recipes[_index][0] +
					"' itemTime= '"+ _recipes[_index][3] +
					 "' NAME=\"recipeID_" + _recipes[_index][0] + "\">";
				$tempHtml += " " + _recipes[_index][1] + " - " +
							 _recipes[_index][3] + " minutes";
				if(_recipes[_index][4] != ''){
					$tempHtml += " - "+ _recipes[_index][4];
				}
				$tempHtml += " <a title='see recipe details' class='recipeDetailLink' target='_blank' href=search.php?status=detail&detailType=recipe&detailName="+ _recipes[_index][0] + ">?</a></div>";
				if (_recipes[_index][2] == "main"){
					$('#mainDishes').append($tempHtml);
				}
				else if (_recipes[_index][2] == "side"){
					$('#sideDishes').append($tempHtml);
				}
				else if (_recipes[_index][2] == "app"){
					$('#appDishes').append($tempHtml);
				}
				_index++;
			}
		}
	});
}
function recEngine(_recipeIds){
	var _dataString = "status=recEngine" ;
	for (_i=0;_i<(_recipeIds.length);_i++){
			_dataString += "&recipeID" + _i + "=" + _recipeIds[_i][0];
			_dataString += "&recipeType" + _i + "=" + _recipeIds[_i][1];
	}
		
	$.ajax({type: "POST",
		url: "process.php",
		data: _dataString ,
		dataType: "xml",
		success: function(xml){
			$("suggestion", xml).each(function(){
				$.growl("dinneratmyplace", $("text", this).text());				
			});
			$("goodID", xml).each(function(){
				_div = "#" + $("id", this).text();
				$(_div).addClass("goodSuggest");
				$(_div).removeClass("badSuggest");
			});
			$("badID", xml).each(function(){
				_div = "#" + $("id", this).text();
				$(_div).addClass("badSuggest");
				$(_div).removeClass("goodSuggest");
			});
		}
	});
}
function recipeSelectionUser($user,_recipesUser){
	$.ajax({type: "POST",
		url: "process.php",
		data: "status=recipeNamesUser&user=" + $user ,
		dataType: "xml",
		success: function(xml){
			if( $("count", xml).text() === 0 ){
				$("#dishesBreakdownUser").html("<h3> No recipes entered yet! you can <a href=\"addRecipes.php\"> Submit them here </a></h3>");
			}
			else {
				var _index = 0;
				$("RecipeHeader", xml).each(function(){
					_tempArray = new Array(0);
					_tempArray.push($("RecipeID", this).text());
					_tempArray.push($("RecipeName", this).text());
					_tempArray.push($("RecipeType", this).text());
					_tempArray.push($("RecipeTime", this).text());
					_tempArray.push($("RecipeDesc", this).text());
					_tempArray.push($("imageFound", this).text());
					_tempArray.push($("imageUrl", this).text());
					_recipesUser.push(_tempArray);
				});
				$mainVisible = false;
				$sidesVisible = false;
				$appsVisible = false;
				while(_index < _recipesUser.length){
					var $tempHtml = "<div class='checks' id='" + _recipesUser[_index][0] +
					"'> <INPUT TYPE=CHECKBOX recType='"+_recipesUser[_index][2] +
					"' full='"+ _recipesUser[_index][1] +
					"' id='"+ _recipesUser[_index][0] +
					"' itemTime= '"+ _recipesUser[_index][3] +
					 "' NAME=\"recipeID_" + _recipesUser[_index][0] + "\">";
					$tempHtml += " " + _recipesUser[_index][1] + " - " +
								 _recipesUser[_index][3] + " minutes";
					if(_recipesUser[_index][4] != ''){
						$tempHtml += " - "+ _recipesUser[_index][4];
					}
					if(_recipesUser[_index][5] == 'true'){
						$tempHtml += " <a title='see recipe details' target='_blank' class='recipeDetailLink' id='" +_recipesUser[_index][6] +"' href='search.php?status=detail&detailType=recipe&detailName="+ _recipesUser[_index][0] + "'>?</a></div>";
					}
					else{
						$tempHtml += " <a title='see recipe details' target='_blank' class='recipeDetailLink' id='none' href='search.php?status=detail&detailType=recipe&detailName="+ _recipesUser[_index][0] + "'>?</a></div>";
					}
					if (_recipesUser[_index][2] == "main"){
						$('#mainDishesUser').append($tempHtml);
					}
					else if (_recipesUser[_index][2] == "side"){
						$('#sideDishesUser').append($tempHtml);
					}
					else if (_recipesUser[_index][2] == "app"){
						$('#appDishesUser').append($tempHtml);
					}
					_index++;
				}
				($mainVisible === false) ? $('#mainDishesHeaderUser').hide() : $('#mainDishesHeaderUser').show(); 
				($sidesVisible === false) ? $('#sideDishesHeaderUser').hide() : $('#sideDishesHeaderUser').show(); 
				($appsVisible === false) ? $('#appDishesHeaderUser').hide() : $('#appDishesHeaderUser').show(); 
			}
			$("#loadingUser").hide("slow", function(){
				$("#dishesBreakdownUser").show("slow");
			});
		}
	});
}
function getWineSuggestion($recipes,_servings){
	$(".wineLinks").html("thinking...");
	_dataString = "status=wineSuggestion&servings=" + _servings;
	
	for (_i=0;_i<$recipes.length;_i++){
		if ($recipes[_i][0] !== ""){
			_dataString += "&recipeID" + _i + "=" +$recipes[_i][0];
		}
	}
	
	$.ajax({type: "POST",
		url: "process.php",
		data: _dataString,
		dataType: "xml",
		success: function(xml){
			$(".wineLinks").html("Get a Wine Suggestion");
			$("suggestion", xml).each(function(){
				$.growl("Sommelier", $("text", this).text());				
			});
		}
	});
}
function GetVotes(_type,_itemID){
	_dataString = "status=getvotes&type=" + _type + "&itemID=" + _itemID;
	$.ajax({type: "POST",
		url: "process.php",
		data: _dataString,
		dataType: "xml",
		success: function(xml){
			if($("upVotes", xml).text() != '0' || $("downVotes", xml).text() != '0'){ 
				_imageLink = "<img src='http://chart.apis.google.com/chart?cht=p3&chd=t:" +
				 $("upVotes", xml).text() +
				 "," +
				 $("downVotes", xml).text() +
				"&chs=270x100&chl=Up (" +
				 $("upVotes", xml).text() +
				")|Down (" +
				 $("downVotes", xml).text() +
				")&chf=bg,s,ebead1&chco=9caac4,465a75' />";
				$('#voteCharts').html(_imageLink);
				if ($("hasVoted", xml).text() != 'false'){
					if($("hasVoted", xml).text() == "up"){
					$('#voteUp').fadeTo("fast", 1);
					}else {
					$('#voteDown').fadeTo("fast", 1);
					}
				}
			}else{
				$('#voteCharts').html("no votes yet!<br />");
			}
			$('#voteLoading').hide('slow', function(){
					$('#voting').show('slow');
			});
		}
	});
}
function Vote(_type,_itemID,_direction){
	$('#voting').hide('fast', function(){
		$('#voteLoading').show('fast');
	});
	_dataString = "status=vote&type=" + _type + "&itemID=" + _itemID + "&direction=" + _direction;
	$.ajax({type: "POST",
		url: "process.php",
		data: _dataString,
		dataType: "xml",
		success: function(xml){
			$.growl("dinneratmyplace",$("status", xml).text());
			GetVotes(_type,_itemID);
		}
	});
}
function GetFavorites(_type,_itemID){
	_dataString = "status=getfavorites&type=" + _type + "&itemID=" + _itemID;
	$.ajax({type: "POST",
		url: "process.php",
		data: _dataString,
		dataType: "xml",
		success: function(xml){
			if($("timesFavorited", xml).text() != '0'){ 
				_text = "This has been favorited " + $("timesFavorited", xml).text() + " time(s)";
				$('#favoriteCount').html(_text);
				if ($("isFavorited", xml).text()){
					$('.star').fadeTo("fast", 1);
				}
			}else{
				$('#favoriteCount').html("no one has favorited this yet!");
			}
			$('#voteLoading').hide('slow', function(){
					$('#voting').show('slow');
			});
		}
	});
}
function Favorite(_type,_itemID){
	$('#voting').hide('fast', function(){
		$('#voteLoading').show('fast');
	});
	_dataString = "status=favorite&type=" + _type + "&itemID=" + _itemID;
	$.ajax({type: "POST",
		url: "process.php",
		data: _dataString,
		dataType: "xml",
		success: function(xml){
			$.growl("dinneratmyplace",$("status", xml).text());
			GetFavorites(_type,_itemID);
		}
	});
}

function GetUserVote(_type,_itemID){
	_dataString = "status=getuservote&type=" + _type + "&itemID=" + _itemID;
	$.ajax({type: "POST",
		url: "process.php",
		data: _dataString,
		dataType: "xml",
		success: function(xml){
			$.growl("dinneratmyplace",$("status", xml).text());
		}
	});
}
function GetMenuStats(_recipeIDs,isArray){
	$('#recipeStats').slideUp("fast");
	if(_recipeIDs.length != 0){
		_dataString = "status=getmenustats";
		if(isArray){
			for (_i=0;_i<(_recipeIDs.length);_i++){
				_dataString += "&recipeID" + _i + "=" + _recipeIDs[_i][0];
				_dataString += "&recipeType" + _i + "=" + _recipeIDs[_i][1];
			}
		}
		else{
			_dataString += "&recipeID0=" + _recipeIDs;
		}
		/*
		$.ajax({type: "POST",
			url: "process.php",
			data: _dataString,
			dataType: "xml",
			success: function(xml){
				_imageLink = "";
				_imageLink += "<br /><h2>Menu Stats</h2><br />";
				if($("protein", xml).text() != 0 || $("starch", xml).text() != 0 || $("salt", xml).text() != 0 || $("spicy", xml).text() != 0){
					_imageLink += "<img src='http://chart.apis.google.com/chart?cht=p3&chd=t:"+
					 $("protein", xml).text()+
					 ","+
					 $("starch", xml).text()+
					 ","+
					 $("salt", xml).text()+
					 ","+
					 $("spicy", xml).text()+
					"&chs=270x100&chl="+
					 "Protein ("+
					 $("protein", xml).text()+
					")|Starch ("+
					 $("starch", xml).text()+
					")|Salt ("+
					 $("salt", xml).text()+
					")|Spice ("+
					 $("spicy", xml).text()+
					")&chf=bg,s,ebead1&chco=9caac4,465a75' />";
				}else{
					_imageLink += "<h3>No Item Matches Found</h3><br />";
				}
				if($("skill", xml).text() != 0){
					 _imageLink += "<br /><br /><h2>Menu Skill Ranking: "+ $("skill", xml).text() + "</h2>";
					$('#recipeStats').html(_imageLink);
					$('#recipeStats').slideDown("fast");
				}   
			}
		});
		*/
	}
}
function getNutritionValues($ingredients,_servings){
	$(".nutritionLinks").html("thinking...");
	$('#contentFillNutrition').html("<img src='images/ajax-loader.gif' alt='Loading'/>");
	_dataString = "status=nutritionValues";
	_dataString += "&servings=" + _servings;
	

		/*
	$ingredients[_index][0] = $("recipeID", this).text();
	$ingredients[_index][1] = $("name", this).text();
	$ingredients[_index][2] = $("amount", this).text();
	$ingredients[_index][3] = $("amounttype", this).text();
	$ingredients[_index][4] = $("realName", this).text();
	$ingredients[_index][5] = $("servings", this).text();
		*/
					
	for (_i=0;_i<$ingredients.length;_i++){
		if ($ingredients[_i][0] !== ""){
			_dataString += "&ingredients" + _i + "=" +$ingredients[_i][4];
			_dataString += "&ingredientsType" + _i + "=" +$ingredients[_i][3];
			_dataString += "&ingredientsAmt" + _i + "=" +$ingredients[_i][2];
			_dataString += "&ingredientsRecID" + _i + "=" + $ingredients[_i][0];
			_dataString += "&ingredientsServings" + _i + "=" + $ingredients[_i][5];
		}
	}
	
	$.ajax({type: "POST",
		url: "process.php",
		data: _dataString,
		dataType: "xml",
		success: function(xml){
			$(".nutritionLinks").html("Get a nutritional value estimation.");
			_nutritionHtml = "<b> Full Menu </b><br />";
			$("nutritionalValues", xml).each(function(){
				_nutritionHtml +="calories = " + $("calories", this).text() + " <br />" +
						"calories from fat = " + $("caloriesFromFat", this).text() + "<br />" +
						"total fat = " + $("totalFat", this).text() + " g<br />" +
						"saturated fat = " + $("satFat", this).text() + " g<br />" +
						"trans fat = " + $("transFat", this).text() + " g<br />" +
						"cholesterol = " + $("cholesterol", this).text() + " mg<br />" +
						"sodium = " + $("sodium", this).text() + " mg<br />" +
						"potassium = " + $("potassium", this).text() + " mg<br />" +
						"total carbs = " + $("totalCarbs", this).text() + " g<br />" +
						"fiber = " + $("fiber", this).text() + " g<br />" +
						"sugars = " + $("sugars", this).text() + " g<br />" +
						"protein = " + $("protein", this).text() + " g<br />" +
						"<br />";
										
			});
			$("nutritionalValuesPerServing", xml).each(function(){
				_nutritionHtml += "<b> Per Serving </b><br />";	
				_nutritionHtml +="calories = " + $("calories", this).text() + 
						" ("+ Math.round((($("calories", this).text()/2000)*100),0) +"%) <br />" +
						"calories from fat = " + $("caloriesFromFat", this).text() + 
						"<br />" +
						"total fat = " + $("totalFat", this).text() + 
						" g ("+ Math.round((($("totalFat", this).text()/65)*100),0) +"%) <br />" +
						"saturated fat = " + $("satFat", this).text() + 
						" g ("+ Math.round((($("satFat", this).text()/20)*100),0) +"%) <br />" +
						"trans fat = " + $("transFat", this).text() + 
						" g<br />" +
						"cholesterol = " + $("cholesterol", this).text() + 
						" mg ("+ Math.round((($("cholesterol", this).text()/300)*100),0) +"%) <br />" +
						"sodium = " + $("sodium", this).text() + 
						" mg ("+ Math.round((($("sodium", this).text()/2400)*100),0) +"%) <br />" +
						"potassium = " + $("potassium", this).text() + 
						" mg ("+ Math.round((($("potassium", this).text()/3500)*100),0) +"%) <br />" +
						"total carbs = " + $("totalCarbs", this).text() +
						" g ("+ Math.round((($("totalCarbs", this).text()/300)*100),0) +"%) <br />" +
						"fiber = " + $("fiber", this).text() + 
						" g ("+ Math.round((($("fiber", this).text()/25)*100),0) +"%) <br />" +
						"sugars = " + $("sugars", this).text() + 
						" g<br />" +
						"protein = " + $("protein", this).text() + 
						" g ("+ Math.round((($("protein", this).text()/50)*100),0) +"%) <br />" +
						"<br />";
						
				_nutritionHtml2 ="<table class='nutFacts'><tr>"+
					"<td colspan='2' class='td head'>Nutrition Facts</td></tr><tr>"+
					"<td colspan='2' class='td fullspan'>Serving Size</td></tr><tr>"+
					"<td colspan='2' class='td fullspan'>Servings Per Container " + $("servings", xml).text() +"</td></tr><tr>"+
					"<td colspan='2' class='td black5'></td></tr><tr>"+
					"<td colspan='2' class='td full'><b>Amount per serving</b></td></tr><tr>"+
					"<td colspan='2' class='td black1'></td></tr><tr>"+
					"<td class='td left'><b>Calories</b> "+$("calories", this).text()+ " ("+ Math.round((($("calories", this).text()/2000)*100),0) +"%)" +"</td>"+
					"<td class='td right'>Cals from Fat " + $("caloriesFromFat", this).text() + "</td></tr><tr>"+
					"<td colspan='2' class='td black3'></td></tr><tr>"+
					"<td class='td left'>&nbsp;</td>"+
					"<td class='td right'><b>% Daily Value*</b></td></tr><tr>"+
					"<td colspan='2' class='td black1'></td></tr><tr>"+
					"<td class='td left'><b>Total Fat</b> " + $("totalFat", this).text() + " g</td>"+
					"<td class='td right'>"+ Math.round((($("totalFat", this).text() / 65)*100),0) +"%</td></tr><tr>"+
					"<td colspan='2' class='td black1'></td></tr><tr>"+
					"<td class='td left'>&nbsp;&nbsp;&nbsp;Sat. Fat " + $("satFat", this).text() + " g</td>"+
					"<td class='td right'>"+ Math.round((($("satFat", this).text() / 20)*100),0) +"%</td></tr><tr>"+
					"<td colspan='2' class='td black1'></td></tr><tr>"+
					"<td class='td left'>&nbsp;&nbsp;&nbsp;Trans Fat " + $("transFat", this).text() + " g</td>"+
					"<td class='td right'>&nbsp;</td></tr><tr>"+
					"<td colspan='2' class='td black1'></td></tr><tr>"+
					"<td class='td left'><b>Cholesterol</b> " + $("cholesterol", this).text() + " mg</td>"+
					"<td class='td right'>"+ Math.round((($("cholesterol", this).text()/300)*100),0) +"%</td></tr><tr>"+
					"<td colspan='2' class='td black1'></td></tr><tr>"+
					"<td class='td left'><b>Sodium</b> " + $("sodium", this).text() + " mg</td>"+
					"<td class='td right'>"+ Math.round((($("sodium", this).text()/2400)*100),0) +"%</td></tr><tr>"+
					"<td colspan='2' class='td black1'></td></tr><tr>"+
					"<td class='td left'><b>Total Carbs</b> " + $("totalCarbs", this).text() +" g </td>"+
					"<td class='td right'>"+ Math.round((($("totalCarbs", this).text()/300)*100),0) +"%</td></tr><tr>"+
					"<td colspan='2' class='td black1'></td></tr><tr>"+
					"<td class='td left'>&nbsp;&nbsp;&nbsp;Fiber " + $("fiber", this).text() + " g</td>"+
					"<td class='td right'>"+ Math.round((($("fiber", this).text()/25)*100),0) +"%</td></tr><tr>"+
					"<td colspan='2' class='td black1'></td></tr><tr>"+
					"<td class='td left'>&nbsp;&nbsp;&nbsp;Sugars " + $("sugars", this).text() + " g</td>"+
					"<td class='td right'></td></tr><tr>"+
					"<td colspan='2' class='td black1'></td></tr><tr>"+
					"<td class='td left'><b>Protein</b> " + $("protein", this).text() + " g</td>"+
					"<td class='td right'>"+ Math.round((($("protein", this).text()/50)*100),0) +"%</td></tr><tr>"+
					"<td colspan='2' class='td black5'></td></tr><tr>"+
					"<td class='td left'>Vitamin A</b></td>"+
					"<td class='td right'>Vitamin C</td></tr><tr>"+
					"<td colspan='2' class='td black1'></td></tr><tr>"+
					"<td class='td left'>Calcium</b></td>"+
					"<td class='td right'>Iron</td></tr><tr>"+
					"<td colspan='2' class='td black1'></td></tr><tr>"+
					"<td colspan='2' class='td full'>* Percent Daily Values are based on a 2,000 calorie diet.</td></tr><tr>"+
					"<td colspan='2' class='td black1'></td></tr></table>";
			});
			_nutritionHtml += "* note these values may not be accurate just yet but we're working on it.";
			_nutritionHtml2 += "* note these values may not be accurate just yet but we're working on it.";
			$.growl("Nutritionist",_nutritionHtml);
			$('#contentFillNutrition').hide().html(_nutritionHtml2).slideDown();
		}
	});
}
function RecipeInfoUser($user,_recipesUser){
	$.ajax({type: "POST",
		url: "process.php",
		data: "status=recipeNamesUser&user=" + $user ,
		dataType: "xml",
		success: function(xml){
			if( parseInt($("count", xml).text(),10) === 0 ){
				$("#dishesBreakdownUser").html("<h3> No recipes entered yet! you can <a href=\"addRecipes.php\"> Submit them here </a></h3>");
			}
			else {
				var _index = 0;
				$("RecipeHeader", xml).each(function(){
					_tempArray = new Array(0);
					_tempArray.push($("RecipeID", this).text());
					_tempArray.push($("RecipeName", this).text());
					_tempArray.push($("RecipeType", this).text());
					_tempArray.push($("RecipeTime", this).text());
					_tempArray.push($("RecipeDesc", this).text());
					_recipesUser.push(_tempArray);
				});
				$mainVisible = false;
				$sidesVisible = false;
				$appsVisible = false;
				while(_index < _recipesUser.length){
					if (_recipesUser[_index][2] == "main"){
						$mainVisible = true;
						var $tempHtml = "<a href=search.php?status=detail&detailType=recipe&detailName=" + _recipesUser[_index][0] + ">";
						$tempHtml += _recipesUser[_index][1] + " - " + _recipesUser[_index][3] + " minutes - " + _recipesUser[_index][4] + "</a><br />";
						$('#mainDishesUser').append($tempHtml);
					}
					else if (_recipesUser[_index][2] == "side"){
						$sidesVisible = true;
						$tempHtml = "<a href=search.php?status=detail&detailType=recipe&detailName=" + _recipesUser[_index][0] + ">";
						$tempHtml += _recipesUser[_index][1] + " - " + _recipesUser[_index][3] + " minutes - " + _recipesUser[_index][4] + "</a><br />";
						$('#sideDishesUser').append($tempHtml);
					}
					else if (_recipesUser[_index][2] == "app"){
						$appsVisible = true;
						$tempHtml = "<a href=search.php?status=detail&detailType=recipe&detailName=" + _recipesUser[_index][0] + ">";
						$tempHtml += _recipesUser[_index][1] + " - " + _recipesUser[_index][3] + " minutes - " + _recipesUser[_index][4] + "</a><br />";
						$('#appDishesUser').append($tempHtml);
					}
					_index++;
				}
				($mainVisible === false) ? $('#mainDishesHeaderUser').hide() : $('#mainDishesHeaderUser').show(); 
				($sidesVisible === false) ? $('#sideDishesHeaderUser').hide() : $('#sideDishesHeaderUser').show(); 
				($appsVisible === false) ? $('#appDishesHeaderUser').hide() : $('#appDishesHeaderUser').show(); 
			}
			$(".loading").hide("slow",function(){
				$("#dishesBreakdownUser").show("slow");				   
			});
		}
	});
}
function RecipeManager(_user,_recipesUser,_lowerLimit){
	$('#backArrow').hide();
	$('#forwardArrow').hide();
	$("#recipeManager").hide('fast',function(){
		$(".loading").show('fast',function(){
		});	
	});
	$.ajax({type: "POST",
		url: "process.php",
		data: "status=recipeMgr&user=" + _user + "&lowerLimit=" +_lowerLimit,
		dataType: "xml",
		success: function(xml){
			if($("count", xml).text() == '0' ){
				$("#recipeManager").html("<h3> No recipes entered yet! you can <a href=\"addRecipes.php\"> Submit them here </a></h3>");
				$(".loading").hide('fast',function(){
					$("#recipeManager").show('fast');
				});
			}
			else {
				_html = '';
				$("RecipeHeader", xml).each(function(){
					_ingredients = '';
					_steps = '';
					$("ingredients", this).each(function(){
						_ingredients += $("amount", this).text() + " " +
							$("amounttype", this).text() + " " +
							$("name", this).text() + "<br />"
					});
					$("step", this).each(function(){
						_steps += $("stepText", this).text() + "  ";
					});
				
			
					_html += "<div class='recipeGroup ui-widget ui-widget-content ui-helper-clearfix ui-corner-all' id='"+$("RecipeID", this).text() +"' >"+
						"<div class='recipeHeader' ><h2>&nbsp;" + $("RecipeName", this).text() + "</h2></div>"+
						"		<div class='recipeDetails' style='display:none'>";
					if($("imageFound", this).text() == 'true'){
						_html += "			<div class='recipeImageWrapper1' style='float:right' height='250px' width='250px'> <div class='recipeImageWrapper' style='position:relative' ><div class='recipeImageUploadifyWrapper' style='position:absolute; top:0; right:0;z-index:5'><div class='recipeImageUploadify' id='"+$("RecipeID", this).text() +"_uploadify' ></div></div><div class='recipeImage' style='position:absolute; top:0; right:0;z-index:2' ><img src='http://dinneratmyplace.com/uploads/" + $("imageUrl", this).text() + "' height='250px' width='250px' class='recipeImagePlaceholder' style='z-index:2'/></div>";
					}
					else{
						_html += "			<div class='recipeImageWrapper1' style='float:right' height='250px' width='250px'><div class='recipeImageWrapper'  style='position:relative' ><div class='recipeImageUploadifyWrapper' style='position:absolute; top:0; right:0;z-index:5'><div class='recipeImageUploadify' id='"+$("RecipeID", this).text() +"_uploadify'></div></div><div class='recipeImage' style='position:absolute; top:0; right:0;z-index:2' ><img src='images2/noImage.png' alt='no' title='no' height='250px' width='250px' class='recipeImagePlaceholder' style='z-index:2' /></div>";
					}
					_html += "			</div></div>";
					if($("private", this).text() == '0'){
						_html += "			<div class='privateOrPublic editable'><img src='images2/public.png' alt='no' title='no' /></div><br />";
					}else{
						_html += "			<div class='privateOrPublic editable'><img src='images2/private.png' alt='yes' title='yes' /></div><br />";
					}
					if($("RecipeType", this).text() == 'main'){
						_html += "<div class='recipeCourse editable' title='main'>Main Dish</div><br />";
					}
					else if($("RecipeType", this).text() == 'side'){
						_html += "<div class='recipeCourse editable' title='side'>Side Dish</div><br />";
					}else {
						_html += "<div class='recipeCourse editable' title='app'>Appetizer</div><br />";
					}
							
					_html +="<span class='recipeTime'>" +  $("RecipeTime", this).text()  + "</span> minutes<br />" +
						$("RecipeDesc", this).text() + "<br />"+
						"			servings: <div class='servings editable'>"+ $("RecipeServings", this).text() +"</div><br />";
					if(_ingredients != ''){
						_html += "			<div class='recipeIngredients editable'>" + _ingredients + "</div>";
					}else{
						_html += "			<div class='recipeIngredients editable'>Add Some!</div>";
					}
					if(_steps != ''){
						_html += "			<br /><div class='recipeSteps editable'>" + _steps + "</div>";
					}else{
						_html += "			<br /><div class='recipeSteps editable'>Add Some!</div>";
					}
					_html += "			<br />"+
						 "		</div>"+
						 "</div>";
				});
			}
			$("#recipeManager").html(_html);
			/*
			$('.recipeImagePlaceholder').each(function(){
				$(this).uploadify({
					'uploader'       : 'js/uploadify.swf',
					'script'         : 'include/uploadify.php',
					'cancelImg'      : 'images2/cancel.png',
					'buttonImg'	: 'images2/noImage.png',
					'folder'         : 'uploads',
					'auto'           : true,
					'multi'          : false,
					'sizeLimit'		 : 20000,
					'fileDesc'		 :'*.jpg;*.gif;*.png',
					'fileExt'		 :'*.jpg;*.gif;*.png',
					'width'	: 250,
					'height' : 250,
					'onComplete'  : function (evt, queueID, fileObj, response) {
					   $('#image').val(response);
					}
				});
			});
			*/
			$(".loading").hide('fast',function(){
				$("#recipeManager").show('fast',function(){				   
					if(_lowerLimit != 0){
						$('#backArrow').show();
					}
					if(parseInt($("count", xml).text(),10) > (_lowerLimit + 10)){ //need to check for upper limit on recipes
						$('#forwardArrow').show();
					}
				});
			});
		}
	});
}
function GetUserFavorites($user){
	$.ajax({type: "POST",
		url: "process.php",
		data: "status=getuserfavorite&user=" + $user ,
		dataType: "xml",
		success: function(xml){
			$("favoriteRecipes", xml).each(function(){
				if( parseInt($("count", this).text(),10) === 0 ){
					$("#favorites").append("<h3> No favorited recipes yet!</h3>");
				}
				else {
					$("#favorites").append("<h3>Recipes:</h3>");
					$("recipe", this).each(function(){
						
						$("#favorites").append("<a href=search.php?status=detail&detailType=recipe&detailName=" +  $("id", this).text() + ">"+ $("name", this).text() +"</a><br />");
					});
					$("#favorites").append("<br />");
				}
			});
			$("favoriteMenus", xml).each(function(){
				if( parseInt($("count", this).text(),10) === 0 ){
					$("#favorites").append("<h3> No favorited menus yet!</h3>");
				}
				else {
					$("#favorites").append("<h3>Menus:</h3>");
					$("menu", this).each(function(){
						$("#favorites").append("<a href=search.php?status=detail&detailType=menu&detailName=" +  $("id", this).text() + ">"+ $("date", this).text() +"</a><br />");
					});
					$("#favorites").append("<br />");
				}
			});
			$("#loadingUserFavorites").hide("slow",function(){
				$("#favorites").show("slow");				   
			});
		}
	});
}
function UserHistory($user){
	$.ajax({type: "POST",
		url: "process.php",
		data: "status=UserHistory&user=" + $user ,
		dataType: "xml",
		success: function(xml){
			if( parseInt($("count", xml).text(),10) === 0 ){
				$("#userHistory").html("<h3> No menus prepared yet!</h3>");
			}
			else {
				var $menus = new MultiDimensionalArray($("count", xml).text(),20);
				var $index = 0;
				var _subIndex = 2;
				$("menu", xml).each(function(){
						_subIndex = 2;
						$menus[$index][0] = $("menuID", this).text();
						$menus[$index][1] = $("menuDate", this).text();
						$("recipes", this).each(function(){
							$menus[$index][_subIndex] = $("recipeID", this).text();
							$menus[$index][_subIndex+1] = $("recipeName", this).text();					
							_subIndex+=2;
						});
						$index++;
				});
				$index =0;
				_subIndex = 2;
				while($index < $menus.length){
					_subIndex = 2;
					var $tempHtml = "<h3>" + $menus[$index][1] +
						" <a href=search.php?status=detail&detailType=menu&detailName=" + $menus[$index][0] + ">See menu details</a>" + "</h3>";
					while($menus[$index][_subIndex] !== ""){
						$tempHtml += "<br />" + "<a href=search.php?status=detail&detailType=recipe&detailName=" + $menus[$index][_subIndex] + ">" + $menus[$index][_subIndex+1] + "</a>";
						_subIndex +=2;
					}
					$tempHtml += "<br /><br />";
					$index++;
					$("#historyDetail").append($tempHtml);
				}
			}
			$("#loadingUserHistory").hide("slow",function(){
			$("#userHistory").show("slow");				   
			});
		}
	});
}
function UserMilestone(_user){
	$.ajax({type: "POST",
		url: "process.php",
		data: "status=UserMilestones&user=" + _user ,
		dataType: "xml",
		success: function(xml){
			if( parseInt($("count", xml).text(),10) === 0 ){
				$("#userMilestones").html("<h3> No Milestones acheived yet!</h3>");
			}
			else {
				var _milestones = new MultiDimensionalArray($("count", xml).text(),3);
				var _index =0;
				$("milestone", xml).each(function(){
					_milestones[_index][0] = $("color", this).text();
					_milestones[_index][1] = $("name", this).text();
					_milestones[_index][2] = $("url", this).text();
					_index++;
				});
				var $tempHtml = "";
				for(_i=0;_i<_milestones.length;_i++){
					_color = "";
					switch(_milestones[_i][0]){
						case '0':
						_color = "Platnum";
						break;
						case '1':
						_color = "Gold";
						break;
						case '2':
						_color = "Silver";
						break;
						case '3':
						_color = "Bronze";
						break;
					}
					$tempHtml += "<img src='http://dinneratmyplace.com/images2/milestones/"+ _milestones[_i][2] +"' alt='"+ _color + " - " +_milestones[_i][1] + "' title='" +_milestones[_i][1] + "'/>&nbsp;";
				}
				$tempHtml += "<br /><br />";
				$("#userMilestones").append($tempHtml);
			}
			$("#loadingUserMilestones").hide("slow",function(){
				$("#userMilestones").show("slow");				   
			});
		}
	});
}
function UserXP(_user){
	$.ajax({type: "POST",
		url: "process.php",
		data: "status=UserXP&user=" + _user ,
		dataType: "xml",
		success: function(xml){
			_skill = parseInt($("skill", xml).text(),10);
			_skillprogress = _skill % 100;
			_skillLevel = Math.floor(_skill / 100);
			_skillLevelNext = _skillLevel+1;
			$("#loadingUserXP").hide("slow",function(){
				$("#lastXPLevel").text(_skillLevel + " ");
				$("#nextXPLevel").text(" " + _skillLevelNext);
				$("#userXPProgress").progressbar('option', 'value', _skillprogress);
				$("#userXP").show("slow");
			});
		}
	});
}

//left off here, adding recType to class.

function searchForRecipeSelection(_search){
	$('#loadingAll').slideDown("fast");
	$('#noRecipesFound').slideUp("fast");
	$('#dishesBreakdown').slideUp("fast");
	$('#mainDishes').empty();
	$('#sideDishes').empty();
	$('#appDishes').empty();
	
	$.ajax({type: "POST",
		url: "process.php",
		data: "status=recipeSelectionSearch&search=" + _filter ,
		dataType: "xml",
		success: function(xml){
			if( $("count", xml).text() == 0 ){
				$('#loadingAll').slideUp("fast",function(){										 
					$('#noRecipesFound').slideDown("fast");
				});
			}
			else
			{
				_recipes = new Array(0);
				$("RecipeHeader", xml).each(function(){
					_tempArray = new Array(0);
					_tempArray.push($("RecipeID", this).text());
					_tempArray.push($("RecipeName", this).text());
					_tempArray.push($("RecipeType", this).text());
					_tempArray.push($("RecipeTime", this).text());
					_tempArray.push($("RecipeDesc", this).text());
					_tempArray.push($("RecipeImage", this).text());
					_recipes.push(_tempArray);
				});
				var _index = 0;
				while(_index < _recipes.length){
					var $tempHtml = "<div class='checks' id='" + _recipes[_index][0] +
						"'> <INPUT TYPE=CHECKBOX recType='"+_recipes[_index][2] +
						"' class='"+ _recipes[_index][0] + " mainBar " + _recipes[_index][2] + 
						"' full='"+ _recipes[_index][1] +
						"' id='"+ _recipes[_index][0] +
						"' itemTime= '"+ _recipes[_index][3] +
						 "' NAME=\"recipeID_" + _recipes[_index][0] + "\">";
					$tempHtml += " " + _recipes[_index][1] + " - " +
								 _recipes[_index][3] + " minutes";
					if(_recipes[_index][4] != ''){
						$tempHtml += " - "+ _recipes[_index][4];
					}
					$tempHtml += " <a title='see recipe details' target='_blank' class='recipeDetailLink' id='" +_recipes[_index][5] +"' href='search.php?status=detail&detailType=recipe&detailName="+ _recipes[_index][0] + "'>?</a></div>";
					if (_recipes[_index][2] == "main"){
						$('#mainDishes').append($tempHtml);
					}
					else if (_recipes[_index][2] == "side"){
						$('#sideDishes').append($tempHtml);
					}
					else if (_recipes[_index][2] == "app"){
						$('#appDishes').append($tempHtml);
					}
					_index++;
				}
				$('#loadingAll').slideUp("fast",function(){	
					$('#dishesBreakdown').slideDown("fast");
				});
			}
		}
	});
}

function StartANewTimer(_time,_timers){
	$.growl("Kitchen Timer", "Starting Timer for " + _time + " minutes");
	var d = new Date();
	var _timeStart = d.getTime();
	if ( !$("#header_" + _timeStart).length > 0 ) {
		$("#Timers").prepend("<div id=header_" + _timeStart+ "><p>" + _time + " minutes: </p></div><div id=" + _timeStart + " class='timer'></div><br />"); 
	}
	$("#" +_timeStart).progressbar({value: 0});
	$("#" +_timeStart).children().addClass("progressGoing");
	 	_timers[_timeStart] = setInterval(function() {
		var d = new Date();																					 
		var _curTime = d.getTime();	
		var _timeEnd = _timeStart + (_time * 60000);
		if (_timeEnd  >= _curTime){
			var _percent = Math.round((((_curTime-_timeStart)/(_time*60000))*100),0);
			var _remaining = _timeEnd - _curTime;
			if(_remaining >= 60000){
				_remaining = Math.ceil(_remaining / 60000,0);
				_remaining += " min(s) left";
			}else{
				_remaining = Math.ceil((_remaining % 60000) / 1000,0);
				_remaining += " sec(s) left";
			}
			$("#" + "header_" + _timeStart).text( _time + " minutes, " +  _percent+ "%, " + _remaining);
			$("#" +_timeStart).progressbar('option', 'value', _percent);
		}
		else
		{
			clearInterval(_timers[_timeStart]);
			$("#" +_timeStart).children().removeClass("progressGoing");
			$("#" + "header_" + _timeStart).text( _time + " minutes: Done!");
			$.growl("Kitchen Timer", "Timer for " + _time + " minutes Done!");
			$("#" +_timeStart).progressbar('option', 'value', 100);
			playSound('alert');
		}
	},1000);
}
function NextStep(_currentStep,_isStarted,_welcome,_servings,_timers){
	//Start any currently displayed timer notifications.
	if($('#CurrentStepTextDivTimers').text() !== ""){
		_timersInStep = $('#CurrentStepTextDivTimers').text();
		var regExpression = new RegExp("(\\d{1}) \\(to (\\d{1})\\) minutes","gi");
		if(_timersInStep.match(regExpression) != null){
			var testForComplexTimers = _timersInStep.replace(regExpression, "$1");
			StartANewTimer(testForComplexTimers,_timers);
		}
		regExpression = new RegExp("(\\d{1}) minutes","gi");
		if(_timersInStep.match(regExpression) != null){
			var testForComplexTimers = _timersInStep.replace(regExpression, "$1");
			StartANewTimer(testForComplexTimers,_timers);
		}
	}
	_menuComp = false;
	_currentStep = parseInt(_currentStep,10);
	_futureStep = _currentStep + 1;
	if(_currentStep == -1){
		if(_welcome){
			setTimeout(loadNewVideo, 2000,'jX-9zxWNhdE',0);
		}
	}
	if($('#step_' + _futureStep).length >0){
		_oldStep = _currentStep;
		if(_oldStep != '-1'){
			$('#step_' + _oldStep).css({"text-decoration": "line-through" });
			_oldGroup = $('#step_' + _currentStep).parent().parent().attr('id'); 
			_oldGroup = _oldGroup.split("_");
			_oldGroup = (+(_oldGroup[1]));
		} else {
			_oldGroup = 0;
		}
		_currentStep++;
		
		$('#step_' + _currentStep).css({"text-decoration": "underline" });
		_newGroup = $('#step_' + _currentStep).parent().parent().attr('id');
		_newGroup = _newGroup.split("_");
		_newGroup = (+(_newGroup[1]));
		if(_oldGroup === 0 && _newGroup == 1 && !_isStarted){
			tb_remove();
		}
		//var _curGroup = $("#steps").accordion('option', 'active');
		if(_oldGroup != _newGroup){
			$("#steps").accordion('activate', _newGroup);
		}
		if(_oldStep != '-1'){
			if(_oldGroup === 0 && _newGroup == 1 && !_isStarted){
				setTimeout(ThickboxJump,100);
			}else{
				$('#CurrentStepTextDivText').text($('#step_' + _currentStep).text());
				$('#CurrentStepTextDivRecipe').text($('#recipeName_' + _currentStep).text());
				_stepTime =  $('#time_' + _newGroup +"_header").text();
				$('#CurrentStepTextTime').text("Current Step ( "+ _stepTime + " ):");
				_ingHtml = $('#step_' + _currentStep + " a"); 
				
				if(_ingHtml){
					_ingFound = false;
					_timeFound = false;
					_instructFound = false;
					for(_i=0;_i<_ingHtml.length;_i++){
						if($(_ingHtml[_i]).attr("className") == "ingAmount"){
							if(!_ingFound){
								$('#CurrentStepTextDivIngsHeader').text("Ingredients Involved:");
								$('#CurrentStepTextDivIngs').html($(_ingHtml[_i]).attr("title") + "<br />");
								_ingFound = true;
							}
							else{
								$('#CurrentStepTextDivIngs').append($(_ingHtml[_i]).attr("title") + "<br />");
							}
						}
						else if($(_ingHtml[_i]).attr("className") == "timers"){
							if(!_timeFound){
								$('#CurrentStepTextDivTimerHeader').text("Timers Involved:");
								$('#CurrentStepTextDivTimers').html($(_ingHtml[_i]).text() + "<br />");
								_timeFound = true;
							}
							else{
								$('#CurrentStepTextDivTimers').append($(_ingHtml[_i]).text() + "<br />");
							}
						}
						else if($(_ingHtml[_i]).attr("className") == "instructVideo"){
							if(!_instructFound){
								setTimeout(loadNewVideo, 1000, $(_ingHtml[_i]).attr('title'), 0);
								_instructFound = true;
							}
						}
					}
					if(!_ingFound){
						$('#CurrentStepTextDivIngsHeader').text('');
						$('#CurrentStepTextDivIngs').text('');
					}
					if(!_timeFound){
						$('#CurrentStepTextDivTimerHeader').text('');
						$('#CurrentStepTextDivTimers').text('');
					}
					if(!_instructFound){
						if(getPlayerState() == 1){
							stop();
						}
					}
				}
				else{
					$('#CurrentStepTextDivIngsHeader').text('');
					$('#CurrentStepTextDivIngs').text('');
					$('#CurrentStepTextDivTimerHeader').text('');
					$('#CurrentStepTextDivTimers').text('');
				}
				tb_show("Sous Chef","#TB_inline?height=300&width=500&inlineId=CurrentStepTextDiv");
			}
		}
	}
	else{  //completed menu (future step does not exist
		_menuComp = true;
	}
	if($('#step_' + (_futureStep+1)).length  == 0 ){
		_menuComp = true;
	}
	if(!_menuComp){
		_data = "status=menuProgress&currentStep=" +_currentStep + "&prepComp=" + _isStarted + "&menuComp=" + _menuComp + "&servings=" + _servings;
		$.ajax({type: "POST",
			url: "process.php",
			data: _data ,
			dataType: "xml",
			success: function(xml){
				$("milestoneReached", xml).each(function(){
					var colorName = '';
					switch($("color", this).text()){
						case 0:
							colorName = "Platnum";
						break;
						case 1:
							colorName = "Gold";
						break;
						case 2:
							colorName = "Silver";
						break;
						case 3:
							colorName = "Bronze";
						break;
					}
					$.growl(colorName + " Milestone Reached!","<img src='http://dinneratmyplace.com/images2/milestones/" +$("url", this).text() + "' /><br />" + $("name", this).text());
					playSound('cheer');
				}); 
			}
		});
	}
	return(_currentStep);
}
function ThickboxJump(){
	tb_show("Start Cooking?","#TB_inline?height=145&width=350&inlineId=Start2");
}
function ThickboxJump2(_steps){
	_StepNumForJump = $('#group_1_content').children('.stepText').attr("id");
	_StepNumForJump = _StepNumForJump.substring(5,_StepNumForJump.length);
	_StepNumForJump -= 1;
	NextStep(_StepNumForJump,true);
}
function PreviousStep(_currentStep,_isStarted){
	_currentStep = parseInt(_currentStep,10);
	var _futureStep = _currentStep - 1;
	if($('#step_' + _futureStep).length >0){
		var _oldStep = _currentStep;
		if(_oldStep != '-1'){
			$('#step_' + _oldStep).css({"text-decoration": "line-through" });
			var _oldGroup = $('#step_' + _currentStep).parent().parent().attr('id'); 
			_oldGroup = _oldGroup.split("_");
			_oldGroup = (+(_oldGroup[1]));
		} else {
			_oldGroup = 0;
		}
		_currentStep--;
		
		$('#step_' + _currentStep).css({"text-decoration": "underline" });
		var _newGroup = $('#step_' + _currentStep).parent().parent().attr('id');
		_newGroup = _newGroup.split("_");
		_newGroup = (+(_newGroup[1]));
		$("#steps").accordion("activate", _newGroup);
		if(_oldStep != '-1'){
				$('#CurrentStepTextDivText').text($('#step_' + _currentStep).text());
				$('#CurrentStepTextDivRecipe').text($('#recipeName_' + _currentStep).text());
				_stepTime =  $('#time_' + _newGroup +"_header").text();
				$('#CurrentStepTextTime').text("Current Step ( "+ _stepTime + " ):");
				_ingHtml = $('#step_' + _currentStep + " a");  //need to grab an array rather than only one...
				
				if(_ingHtml){
					var _ingFound = false;
					var _timeFound = false;
					for(_i=0;_i<_ingHtml.length;_i++){
						if($(_ingHtml[_i]).attr("className") == "ingAmount"){
							if(!_ingFound){
								$('#CurrentStepTextDivIngsHeader').text("Ingredients Involved:");
								$('#CurrentStepTextDivIngs').html($(_ingHtml[_i]).attr("title") + "<br />");
								_ingFound = true;
							}
							else{
								$('#CurrentStepTextDivIngs').append($(_ingHtml[_i]).attr("title") + "<br />");
							}
						}
						else if($(_ingHtml[_i]).attr("className") == "timers"){
							if(!_timeFound){
								$('#CurrentStepTextDivTimerHeader').text("Timers Involved:");
								$('#CurrentStepTextDivTimers').html($(_ingHtml[_i]).text() + "<br />");
								_timeFound = true;
							}
							else{
								$('#CurrentStepTextDivTimers').append($(_ingHtml[_i]).text() + "<br />");
							}
						}
					}
					if(!_ingFound){
						$('#CurrentStepTextDivIngsHeader').text('');
						$('#CurrentStepTextDivIngs').text('');
					}
					if(!_timeFound){
						$('#CurrentStepTextDivTimerHeader').text('');
						$('#CurrentStepTextDivTimers').text('');
					}
				}
				else{
					$('#CurrentStepTextDivIngsHeader').text('');
					$('#CurrentStepTextDivIngs').text('');
					$('#CurrentStepTextDivTimerHeader').text('');
					$('#CurrentStepTextDivTimers').text('');
				}
				tb_show("Sous Chef","#TB_inline?height=300&width=500&inlineId=CurrentStepTextDiv");
			}
		}
	return(_currentStep);
}

function recipeMngerChange(_change){
}
function CreateLinksSkill1(_text){   //keep adding to check out the wiki article on marinating, it has a good list
	_text = _text.replace(/simmer /gi, "<a class=\"links\" target=\"_blank\" href=\"http://en.wikipedia.org/wiki/Simmering\">Simmer </a>&nbsp;");
	_text = _text.replace(/broil /gi, "<a class=\"links\" target=\"_blank\" href=\"http://en.wikipedia.org/wiki/Saut%C3%A9ing\">Broil</a>&nbsp;");
	_text = _text.replace(/marinate /gi, "<a class=\"links\" target=\"_blank\" href=\"http://en.wikipedia.org/wiki/Marination\">Marinate</a>&nbsp;");
	//boil?
	return(_text);
	
	//chop the onion video : '_TKpzPfh_uo'
}
function CreateLinksSkill2(_text){
	_text = _text.replace(/saute /gi, "<a class='instructVideo' title='ifTqaK8oXJA' name='saute' >saute</a>&nbsp;");
	_text = _text.replace(/Sauté /gi, "<a class='instructVideo' title='ifTqaK8oXJA' name='saute' >saute</a>&nbsp;");
	_text = _text.replace(/brine the/gi, "<a class=\"links\" target=\"_blank\" href=\"http://en.wikipedia.org/wiki/Brining\">Brine the</a>&nbsp;");
	_text = _text.replace(/Braise /gi, "<a class=\"links\" target=\"_blank\" href=\"http://en.wikipedia.org/wiki/Braising\">Braise </a>&nbsp;");
	return(_text);
}
function CreateLinksSkill3(_text){
	_text = _text.replace(/cream the/gi, "<a class=\"links\" target=\"_blank\" href=\"http://en.wikipedia.org/wiki/Creaming_(food)\">Cream the</a>&nbsp;");
	_text = _text.replace(/temper /gi, "<a class=\"links\" target=\"_blank\" href=\"http://thefoodgeek.com/technique/temper-temper\">Temper</a>&nbsp;");
	return(_text);
}
function CreateLinksSkill4(_text){
	_text = _text.replace(/blanch the/gi, "<a class=\"links\" target=\"_blank\" href=\"http://en.wikipedia.org/wiki/Blanching \">Blanch the</a>&nbsp;");
	_text = _text.replace(/deglaze the/gi, "<a class=\"links\" target=\"_blank\" href=\"http://en.wikipedia.org/wiki/Deglazing \">Deglaze the</a>&nbsp;");
	_text = _text.replace(/flambe /gi, "<a class=\"links\" target=\"_blank\" href=\"http://en.wikipedia.org/wiki/Flamb%C3%A9 \">Flambe</a>&nbsp;");
	//debone
	return(_text);
}



function CreateTimers(_text){  //not catching everything?
	
	var regExpression = new RegExp(" min[s]?[ .]","gi");
	_text = _text.replace(regExpression , " Minutes" ); 
	
	regExpression = new RegExp("(\\d{1,}) to (\\d{1,}) minutes","gi");
	_text = _text.replace(regExpression , "<a class='timers' name='$1'> $1 (to $2) Minutes</a>" ); 
	
	regExpression = new RegExp(" (\\d{1,}) minutes","gi");
	_text = _text.replace(regExpression , "<a class='timers' name='$1'> $1 Minutes</a>" );
	
	
	_text = _text.replace(/ 1 hour/gi, "<a class='timers' name='60' > 60 Minutes</a>");
	_text = _text.replace(/ 1 minute/gi, "<a class='timers' name='1' > 1 Minute</a>");
	_text = _text.replace(/ 1 min /gi,  "<a class='timers' name='1'> 1 Minute</a>");
	_text = _text.replace(/ one minute/gi, "<a class='timers' name='1'> 1 Minute</a>");
	_text = _text.replace(/ one min /gi,  "<a class='timers' name='1'> 1 Minute</a>");
	_text = _text.replace(/ two minutes/gi, "<a class='timers' name='2'> 2 Minutes</a>");
	_text = _text.replace(/ three minutes/gi, "<a class='timers' name='3'> 3 Minutes</a>");
	_text = _text.replace(/ four minutes/gi, "<a class='timers' name='4'> 4 Minutes</a>");
	_text = _text.replace(/ five minutes/gi, "<a class='timers' name='5'> 5 Minutes</a>");
	_text = _text.replace(/ six minutes/gi, "<a class='timers' name='6'> 6 Minutes</a>"); 
	_text = _text.replace(/ seven minutes/gi, "<a class='timers' name='7'> 7 Minutes</a>");
	_text = _text.replace(/ eight minutes/gi, "<a class='timers' name='8'> 8 Minutes</a>");
	_text = _text.replace(/ nine minutes/gi, "<a class='timers' name='9'> 9 Minutes</a>");
	_text = _text.replace(/ ten minutes/gi, "<a class='timers' name='10'> 10 Minutes</a>");
	
	
	//would like to do this to regular expressions...
	for(_i=1;_i<100;_i++){
		var _tempString1 = new RegExp(" " + _i + " hours", "gi");
		var _convertedToMinutes = 60 * _i;
		var _tempString2 = "<a class='timers' name='"+ _convertedToMinutes +"' > "+ _convertedToMinutes +" Minutes (" + _i+ " hours)</a>";
		_text = _text.replace(_tempString1 , _tempString2);  
	}
	
	/* add more! */


return(_text);
}
