//
function sendComment()
{
	var params=$('#commentForm').serialize();
	$.post('/uusihaku?a=doComment', params, function(ret) {
		if (ret=="ok") {
			$('#commentForm')[0].reset();
			$('#comments').html("Ladataan...").load('/uusihaku?a=loadComments', {receipt_id: $('#receipt_id').val()});
			alert("Kommentti on nyt lisätty!");
		}
	});
	return false;
}


function scrollToComment()
{
	$.scrollTo('#commentForm', 800);
}


$(document).ready(function()  {
	
	$('#query').autocomplete({
		source: '/uusihaku?a=doAutocomplete'
	});
	
	$('.star1').rating();

	$('#category,#diets').hover(function() {
		$(this).addClass('activeCategory');
		$(this).find('.categoriesContainer').show();
	}, function() {
		$(this).removeClass('activeCategory');
		$(this).find('.categoriesContainer').hide();
	});


	$('.receipt').hover(function() {
		$(this).find('.image').addClass('receiptActive');
	}, function() {
		$(this).find('.image').removeClass('receiptActive');
	} );
	
	
	$('#tab .item').click(function() {
		var id=$(this).attr('href');
		var origId=id;
		
		if (id[0]=="#") {
			id=id.substring(2);
		}
		$('.window').each(function(key, value) {
			if ($(value).attr('id')==id) {
				$('#active').val(id);
				$(value).show();
			} else {
				$(value).hide();
			}
		});
		
		
		$('#tab li a ').each(function(key, value) {
			if ($(value).attr('href')==origId) {
				$(value).addClass('active');
				$(value).removeClass('inactive');
			} else {
				$(value).addClass('inactive');
				$(value).removeClass('active');
			}
		});
	})
});


function printRecipe(el)
{
	var url=$(el).attr('href');
	var newWindow=window.open(url, 'name', 'width=700,height=500');
	if (window.focus) {newWindow.focus()}
	return false;
}
