$(document).ready(function(){
 
 	var rotating_images = new Array();
   	for (var i=0; i<11; i++) {
   		rotating_images[i] = new Image(561,169);
   	}
 
   	rotating_images[0].src = '/wp-content/themes/IREC/images/workforcedevhome.jpg';
   	rotating_images[1].src = '/wp-content/themes/IREC/images/sun.jpg';
   	rotating_images[2].src = '/wp-content/themes/IREC/images/pvroof.jpg';
   	rotating_images[3].src = '/wp-content/themes/IREC/images/pvhouse.jpg';
   	rotating_images[4].src = '/wp-content/themes/IREC/images/pvhouse2.jpg';
   	rotating_images[5].src = '/wp-content/themes/IREC/images/PVinstallation.jpg';
   	rotating_images[6].src = '/wp-content/themes/IREC/images/pvpanelsgrid.jpg';
   	rotating_images[7].src = '/wp-content/themes/IREC/images/solarthermal.jpg';
   	rotating_images[8].src = '/wp-content/themes/IREC/images/smallwind.jpg';
   	rotating_images[9].src = '/wp-content/themes/IREC/images/groundpv.jpg';
 	rotating_images[10].src = '/wp-content/themes/IREC/images/missionstatement.jpg';
 	 
  	var speed = 1000;
  	var pause = 9000;
 	var next;
 	var counter = 0;
 
	/* function dynamically adds next image in queue as the background image so the transition will fade to the next image
         *  instead of fading out to white 
        */  
  	function startRotating() {
  		next = rotating_images[counter].src;
  		$(".top-left-home").css('background', 'transparent url('+next+') no-repeat top center');
  		$(".top-left-home").attr("opacity", 0);
  		$(".top-left-home").animate({opacity: 1}, 0)
  		.fadeIn(speed);
    		$("#rotatingImg").animate({opacity: 0}, 0)
  		.fadeOut(speed, function() { 
  			$(this).attr("src", next);
  			$(this).animate({opacity: 1}, speed)
  			.fadeIn(speed);
  			if (counter == 10) {
  				counter = 0;
  			} else {
  				counter++;
  			}
  		});
  	}
   	intervalFadeOut = setInterval(startRotating, pause);
});