var activepghAdNum = 0;
var totpghAds = 0;
/* 1*1000 MAKES IT ROTATE VERY FAST;  4*1000 MAKES IT SLOWER */
var pghadSpeed = 4*1000;
var userBusy = false;

rotate_pghads = function() {
	if (userBusy){
		window.setTimeout(rotate_pghads, pghadSpeed);
		return;
	}
	jQuery(function(){

		nextpghAdNum = (activepghAdNum % totpghAds) + 1;
		$("#rotating_pghad_"+activepghAdNum).fadeOut(500, function(){ 
			$("#rotating_pghad_"+activepghAdNum).removeClass("rotating_pghad_active").addClass("rotating_pghad_inactive");
/* THE FADEIN CAN ALSO BE SET TO "SLOW" */
			$("#rotating_pghad_"+nextpghAdNum).fadeIn("fast", function(){
				$("#rotating_pghad_"+nextpghAdNum).removeClass("rotating_pghad_inactive").addClass("rotating_pghad_active");
				activepghAdNum = nextpghAdNum;
			});
		});
	});
	window.setTimeout(rotate_pghads, pghadSpeed);			
}

jQuery().ready(function() {	
	$(".rotating_pghad").hover(
		function(){
			userBusy = true;
		},
		function(){
			userBusy = false;
		}
	);
	var pghadCount = 0;
	$(".rotating_pghad").each(function(){pghadCount++;});
	totpghAds = pghadCount;
	if (totpghAds > 0){
		activepghAdNum = 1;
	}
	
	window.setTimeout(rotate_pghads, pghadSpeed);
});
