$(document).ready(function() {

	$("a.toggle_bottom").click(function() {
		var a = $(this);
		$("html, body").animate({ scrollTop: $(a.attr('href')).position().top - 50 }, "slow");
		return false;
	});

	$('a#load-post').click(function() {

		var button = $(this), loading = $('.loading-post'), offset = button.data('offset'), tag = button.data('tag');

		button.hide();
		loading.show();

		$.ajax({
			method: 'POST',
			url: "/blog/post/load",
			data: {
				offset: offset,
				tag: tag
			},
			success: function(response) 
			{
				$('.loaded').append(response.posts);
				button.data('offset', response.offset);

				if(response.count <= response.offset)
				{
					button.hide();
				}
				else
				{
					button.show();
				}

				loading.hide();
			}
		});

		return false;

	});

	$.ajax({
		url: "/sessions/default/add"
	});

	setInterval(function(){
		$.ajax({
			url: "/sessions/default/update"
		});
	}, 1000 * 60 * 5);
	

});