function slideSwitch() {
	var $active = $('#slider img.active');
	var $activebutton = $('#slider-buttons li.active');

	if ( $active.length == 0 ) $active = $('#slider img:last');
	if ( $activebutton.length == 0 ) $activebutton = $('#slider-buttons li:last');

	var $next =  $active.next().length ? $active.next() : $('#slider img:first');
	var $nextbutton =  $activebutton.next().length ? $activebutton.next() : $('#slider-buttons li:first');

	$active.addClass('last-active');
	$activebutton.addClass('last-active');

	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
		$active.removeClass('active last-active');
		});
	$nextbutton.addClass('active');
	
	$activebutton.removeClass('active last-active');
}

function imagePreview() {
	$(".menu tr").each(function() {
		if($(this).find("td").length > 2) {
			$img_src = $(this).find("td:nth-child(3) img").attr("src");
			if($img_src) {
				$(this).addClass("preview").attr("img_path", $img_src);
				$(this).hover(function(){
					$(this).css("cursor", "pointer");
				},
				function(){
					$(this).css("cursor", "normal");
				});
			}
			$(this).find("td:nth-child(3)").remove();
			$(this).find("td:first-child").addClass("code");
		}
		if($(this).find("td:last-child").text() != "") {
			$(this).find("td:last-child").addClass("price").append(",- Kč");
		}
	});
	
	var $offsetX = 30;
	var $offsetY = 10;
	
	$("tr.preview").mousedown(function(e){
		var $img_path = $(this).attr("img_path");
		if($("#preview").length == 0){
			var $viewport_width = $(window).width();
			var $offsetX_correction = ($viewport_width - 920) / 2;
			$("body #wrapper").append("<div id='preview'><img src='"+ $img_path +"' alt='' /></div>");							 
			$("#preview")
				.css("position", "absolute")
				.css("top",(e.pageY + $offsetY) + "px")
				.css("left",(e.pageX + $offsetX - $offsetX_correction) + "px")
				.fadeIn("fast");
		} else {
			$("#preview").remove();
		}
    }).mouseleave(function(){	
		$("#preview").remove();
    });	
	$("tr.preview").mousemove(function(e){
		var $viewport_width = $(window).width();
		var $offsetX_correction = ($viewport_width - 920) / 2;
		$("#preview")
			.css("position", "absolute")
			.css("top",(e.pageY + $offsetY) + "px")
			.css("left",(e.pageX + $offsetX - $offsetX_correction) + "px");
	});
	$("tr").hover(function(e){
		$(this).children().css("color","#78baeb").css("background-color", "#f4f4f4");
		$(this).find('strong').css("color", "#5aa2da");
	},
	function(){
		$(this).children().css("color", "#888888").css("background-color", "#ffffff");
		$(this).find('strong').css("color", "#666666");
	});
}
function blink() {
	var $dlvr = $('h2#food_delivery');
	$dlvr.animate({opacity: 0.65}, 1000).animate({opacity: 1.0}, 1000);
}
$(function() {
	$(".ngg-album:even").addClass('even');
	$("a#daily_menu").tipsy({ gravity: 'n' });
	//setInterval("blink()", 2000);
	setInterval("slideSwitch()", 10000);
	imagePreview();});
