var $delay;
var $fastElement;

function fastShow() {
	$fastElement.trigger('fastShow');
}

$().ready(function() {
	
	$("#comments .toggle").live('click',function() {
		$o = $(this);
		$p = $o.parents('.comment').eq(0);
		$('.comment-full').css('display', '');
		$p.toggleClass('show-branch').toggleClass('hide-branch');
	});
	
	$("#comments .comment-full").each(function() {
		$(this).data('full-height', $(this).height());								   
	});
	
	$("#comments .comment-body").bind('fastShow',function() {
		$f = $(this).children('.comment-full');
		if ($f.css("display") == 'none') $f.data('fast-view', true);
		if ($f.data('fast-view')==true) {
			var $iFormHeight =  parseInt($('.add_comment',$f).css("height")) ? parseInt($('.add_comment',$f).css("height")) : 0;
			if ($f.css("display") == 'none') $f.css({display:'block', height:0}).hide();
			$f.stop().animate({height:$f.data('full-height')+($iFormHeight||0)}, 'slow');
		}
	});
	
	$("#comments .comment-body").hover(function() {
		$fastElement = $(this);							
		$delay = setTimeout("fastShow()", 1500); 
		
	}, function(){
		clearTimeout($delay);
		$f = $(this).children('.comment-full');
		if ($f.data('fast-view')==true) {
			$f.stop().slideUp('slow', function() { $f.css('height', 'auto') });
			$f.data('fast-view', '');
		}
	});
});
