function Carousel() {
	
	// Private properties
	var interval = "4s";			// interval between change of hero
	var waitTime = "2s";			// time after user has mouse out before changing
  var animationSpeed = 500;	// animation speed		
  var cufonEnabled = true;	// pretty text
	var rotateItem = 0;				// by default set the first item (zero based)
	
	var debug = false;				// debug on
	
	// Public methods
	
	// init
	var init = this.init = function() {
	
		captionInit();
		
		
  	if (cufonEnabled) {
  		Cufon.replace('#carousel #hero h2');
  		Cufon.replace('#carousel #hero p');
		}
		
		setTimer();
		
		jQuery("#carousel #hero").mouseenter(function () {
			// stop the timer
			jQuery("#carousel").stopTime('switch');
		}).mouseleave(function () {
	    // resume the timer rotation
			setTimer();
	  });
		
	}
	
	var captionInit = this.captionInit = function() {
		
		// make all the captions pretty
		if (cufonEnabled) {
  		Cufon.replace('#carousel .caption');
		}
		
		// on hover, make this the hero
		jQuery("#carousel li").hover (function () {
			// stop the timer and display this item
			jQuery("#carousel").stopTime('switch');
			carousel.changeHero('hover',jQuery("#carousel ul").children('li').index(this));
		}, function () {
	    // wait, and then resume the timer rotation
			jQuery(this).oneTime(waitTime, 'changeToActive', function() {
    		setTimer();
  		});
	  });

	}
	
	var setTimer = this.setTimer = function() {
		
		// set 0 second item
		changeHero('timer',rotateItem);
		
		jQuery("#carousel").everyTime(interval,"switch", function() {
			rotateItem = (rotateItem == 3) ? 0 : rotateItem+1; //jQuery("#carousel li").length()  	 
			changeHero('timer',rotateItem);
		});
	}
	
	// change hero item
	var changeHero = this.changeHero = function(changeType,activeItemNum) {
		
		var activeItem = jQuery("#carousel li").eq(activeItemNum);
			
		// check that we are not already on this item
		if (jQuery("#carousel #hero a").attr("href") != jQuery(activeItem).children("a").attr("href")) {
				
			// remove the highlight from the previous item and add to the active item
			jQuery("#carousel li").removeClass('highlight');
			jQuery(activeItem).addClass('highlight');
			
			jQuery("#carousel #hero").css("background-image","url("+jQuery(activeItem).children("a").children("img").attr("src")+")");
			
			jQuery("#carousel #hero div div").animate({opacity: 0},animationSpeed, function() {
				jQuery("#carousel #hero a").attr("href",jQuery(activeItem).children("a").attr("href"));
				jQuery("#carousel #hero h2").html(jQuery(activeItem).children("a").attr("title"));
				jQuery("#carousel #hero p").html(jQuery(activeItem).children("a").children("span.description").html());
	  			
	  		if (cufonEnabled == true) {
	  			Cufon.refresh('#carousel #hero h2');
					Cufon.refresh('#carousel #hero p');
				}
				
				// animation for the fade between images in the hero area 
				jQuery("#carousel #hero div div").css("background-image",jQuery("#carousel #hero").css("background-image"));
				jQuery("#carousel #hero div div").animate({opacity: 1},animationSpeed/4);
				
			});
		}
		
	}

};
		
jQuery(document).ready(function(){
	carousel = new Carousel();
	carousel.init();			
});