var rotateAd;
var lastAd = 0;

jQuery(function() { // DOM is ready
	
	// Fades out the add, grabs the next via AJAX, and fades it in.
	rotateAd = function() {
	   jQuery(".rotation").animate({opacity: "0"},
			function() {
				var corp_id = jQuery('#corpid').text();
				jQuery(".rotation").load("/wedges/vehicles/_next.php?corpid="+corp_id, {last: lastAd},
					function() {
						jQuery(".rotation").animate({opacity: "1"});
						lastAd = parseInt(jQuery(".item-number").html()) + 1;
					}
				);
			}
		);
	}
	
	jQuery(".rotation").click(rotateAd);
	
	rotateAd();

}); // End DOM is ready

setInterval("rotateAd()", 4 * 1000);
