$(document).ready(function(){
	$ec = $("#endorsements").children();
	if($ec.length > 1) {
		$("#endorsements").cycle({
			fx:'fade', 
			speed: 1000, 
			before: onBefore,
			random: 1,
			delay: -3000,
			timeout: 10000,
			sync: 1,
			pause: 1,
			cleartypeNoBg: true
		});
	}
	
	// Ad rotation
	var $r = $('#rotate');
	if ($r.length > 0) {
		var which = 0;
		var $widgets = $('.widget', $r);
		var w_count = $widgets.length;
		$widgets.css('position', 'absolute').not(':first').removeClass('active').hide().end().first().show().addClass('active');
		setInterval(function() {
			$widgets.filter('.active').fadeOut().removeClass('active');
			which = (which >= (w_count - 1)) ? 0 : which + 1;
			$widgets.eq(which).fadeIn().addClass('active');
		}, 5000);
	}
});

function onBefore(currSlideElement, nextSlideElement, options, forwardFlag) {
	//$(currSlideElement).animate({opacity:0}, 500);
	newHeight = $(nextSlideElement).height();
	$(currSlideElement).parent().animate({height: newHeight}, 500);
}
