jQuery(document).ready(function($){
	$('.boxposts').boxpostsanim();
});

(function($){

$.fn.boxpostsanim = function(){
	return this.each(function(){
		$this = $(this);
		var divh = 0;
		var q = $(this).children('.post').size();
		var curr = q-1;
		var timer;
		var step = function(box){
			$($('.post',box)[curr])
				.animate({opacity:0},200,function()
				{
					$(this).hide();
					curr = (curr+1)%q;
					$($('.post',box)[curr])
						.show().animate({opacity:1},200,function()
						{
							timer = setTimeout(function(){step(box);},5000);
						}
					);
				}
			);
		};
		
		$('.post',$this).hover(
			function(){clearTimeout(timer);},
			function(){timer = setTimeout(function(){step();},2500);}
		);
		$('.post',$this).each(function()
			{if (this.offsetHeight>divh) divh=this.offsetHeight;}
		);
		$this.css({height:divh});
		$('.post',$this).hide().css({opacity:0});
		step($this);
	});
};

})(jQuery);
