$('.hentry').livequery(function() {
	$(this).hover(
		function() {
			$(this).css('background', '#f6f6f6');
		},
		function() {
			var post_details_id = $(this).attr('id') + '-details';
			
			if ($('#' + post_details_id).css('display') == 'none') {
				$(this).css('background', '0');
			}
		}
	);
});


$('.entry-teaser:not(#single-entry)').livequery(function() {
	$(this).click(function() {
		var post_id = $(this).parent().attr('id');
		togglePostDetails(post_id);
	});
});


$('.post-details-collapse a:not(.comments-link)').livequery(function() {
	$(this).click(function() {
		var post_id = $(this).parent().parent().attr('id');
		togglePostDetails(post_id);
	});
});
	


function switchImage(url, post_detail_id, height, width, detail_img_nr)
{
	$('#detail-' + post_detail_id + ' .image-previews span').css('display', 'block');
	$('#detail-' + post_detail_id + ' #preview-detail-' + detail_img_nr).css('display', 'none');
	
	$('#detail-' + post_detail_id + ' .image-big img').attr('width', width);
	$('#detail-' + post_detail_id + ' .image-big img').attr('height', height);
	
	$('#detail-' + post_detail_id + ' .image-big img').attr('src', '/spacer.gif');
	$('#detail-' + post_detail_id + ' .image-big img').attr('src', url);
}


function togglePostDetails(post_id)
{
	var details_id 	= '#' + post_id + '-details';
	var post_nr		= post_id.split('-')[1];
			
	if ($(details_id).css('display') == 'none')
	{
		$(details_id).animate({
			'height': '400px',
		}, 'normal', 'swing');
		
		
		$(details_id).load('?p=' + post_nr + '&detail=1', {}, function() {
			$(this).css('background-image', 'none');
			$(this).css('min-height', '400px');
			$(this).css('height', '');
			
			var command = "$('#detail-" + post_nr + "').show('fast');";

			setTimeout(command, 100);
			$('#post-' + post_nr + ' .post-details-collapse img.img-collapse').attr('src', 'wp-content/themes/neutica/img/buttons/button-detail-close.gif');
		});
		
		gotoAnchor('post-' + post_nr, 'normal');
	} 
	else 
	{
		$(details_id).css('min-height', '1px');
		$(details_id).slideUp('normal', function() {
			$(details_id).css('height', '1px');
			$(details_id).text('');
			$('#detail-' + post_nr).css('display', 'none');
			$(details_id).css('background-image', "url('wp-content/themes/neutica/img/loading.gif')");
			$('#post-' + post_nr).css('background', '0');
			
			$('#post-' + post_nr + ' .post-details-collapse img.img-collapse').attr('src', 'wp-content/themes/neutica/img/buttons/button-detail-open.gif');
		});
	}
}

function reloadTypefaceText()
{
	$('.entry-title').each(function(i) {	
		_typeface_js.replaceText(this); 
		$(this).css({ 'visibility' : 'visible' }); 
	});
}


function gotoAnchor(anchor, speed)
{
	if (speed == undefined) speed = 500;
	var destination  = $('#' + anchor).offset().top - 10;
	
	$("html:not(:animated),body:not(:animated)").animate({scrollTop: destination}, speed, 'swing');
}