window.addEvent('domready', function() {				
	var getCarousel = function() {
		new SimpleCarousel($('hero-overlay'), $$('#hero-overlay a.slide'), {
			slideInterval: 3500,
			rotateAction: 'click'
		}); 
	};
	
	var imageContainer = $('hero-overlay');
	imageContainer.empty();
	
	var populateCarousel = function(images) {
		var count = 0;
		images.each(function(image) {
			if(image != undefined) {
				var imageLink = new Element('a', {'class': 'slide', 'href': image.link}).inject(imageContainer);
				var img = new Element('img', {'src': image.image}).inject(imageLink);
				count++;
			}
		}); 
		if(count > 1) getCarousel();		
	}
	
	var jsonRequest = new Request.JSON({url: "/json/heroImages.json", onComplete: 
		function(jsonObj) { populateCarousel(jsonObj); }
	}).send();		
});