$(document).ready(function() {
		rebindlive_foodlog();
});

function rebindlive_foodlog()
{
		$("img.expandFoodline")
			.unbind()
			.bind('click', function() {
		var str = $(this).attr('id').replace('img_','');
		if($(this).attr("src") == "/gfx/expand.gif") {
			$('#'+str).css({"display":"none"});
			$(this).attr({"src":"/gfx/expand2.gif"});
		}
		else {
			$('#'+str).css({"display":"block"});
			$(this).attr({"src":"/gfx/expand.gif"});
		}
		if(typeof xajax_selected_recipe_div == 'function') {
			xajax_selected_recipe_div(str);
		} 
	});

	$(".foodline:not(.skipHover), .mealheader:not(.skipHover)")
		.unbind('.foodlog')
		.bind('mouseover.foodlog', function(e) {
				if (e.target.className == "mTooltip")
				{
					return;
				}
		if($(this).hasClass("mealheader"))
		{
			$(this).addClass('mealheader_hover');
		}
		else{
			$(this).addClass($(this).closest('.meal_container').attr('id')+'_hover');
		}
		})
		.bind('mouseout.foodlog', function() {
			if($(this).hasClass("mealheader"))
			{
				$(this).removeClass('mealheader_hover');
			}
			else{
				$(this).removeClass($(this).closest('.meal_container').attr('id')+'_hover');
			}
		})
		.bind('click.foodlog contextmenu.foodlog', function(e) {
			$(".mTooltipContent").remove();
			$("#dialog1").dialog('close');
			return foodline_click($(this).attr('id'), $(this).data('menu'), e);
	});

  $(".foodlog_weight")
		.unbind()
		.bind('mouseover', function() { $(this).css({"text-decoration":"underline"}); })
		.bind('mouseout', function() { $(this).css({"text-decoration":"none"}); })
		.bind('click', function(e) {
			e.stopPropagation();
			// init dialog
			$("#dialog1").text('{{LANG_2913}}...');
			var $dialog = $('#dialog1').dialog({ autoOpen: false, resizable: false, width: 320, minHeight: 0, position: [e.clientX, e.clientY] });
			$dialog.dialog('open');
			// get content
			var parent_div  = $(this).parents("div.foodline");
			var data        = parent_div.data('data').split(';');
			var line_id     = parent_div.attr('id');
			if(line_id.match(/^id/g))
			{ xajax_change_amount_food(data[0], 'dialog1', data[1], data[2], '/index.php?id=207'); }
			if(line_id.match(/^cd/g))
			{ xajax_change_consumption_details_amount(data[0], data[1], 'dialog1', '/index.php?id=207'); }
			if(line_id.match(/^ex/g))
			{ xajax_show_exercise_details(data[0], data[1], 'dialog1', 12, '/index.php?id=207'); }
			$(".mTooltipContent").remove();
			return false;
  	});
}
