jQuery(document).ready(function(){

	 intervalObject = setInterval(countDown, 1000);
	
	jQuery("#featurelist .feature").each(
	
	function (IntIndex) {
		
		jQuery(this).hover(featureOn, featureOff);

		
		function featureOn() {
			
			jQuery('.feature').removeClass("featureon");
			jQuery(this).addClass("featureon");
			jQuery('.featurepic').hide();
			jQuery('#featurepic'+IntIndex).fadeIn("fast");
			pause();
			
		}
		
		function featureOff() {
			play();
		}
		
					  
					 }
					  
					 );
	
	
		
});



var totalSec = 5;
var intervalObject;
var isPlaying = true;

function featurePlay() {
	
	
	
}


function play() {
    if (isPlaying == false) {
       
        isPlaying = true;
        intervalObject = setInterval(countDown, 1000);
    }
}

/*
 *  Control of the play/pause button's image and functionality
 */
function pause() {
    if (isPlaying == true) {
        

        isPlaying = false;
        clearInterval(intervalObject);
        totalSec = 5;
    }
}


function countDown() {


    if (totalSec < 0 )  {
    	totalSec = 5;
       
    	var currentDiv = jQuery('#featurelist .featureon').attr('id');
    	var count = currentDiv.charAt(7);
    	count++;
    	if  (count > 3) {
    		count = 0;
    	} else {
    		
    	}
    	
    	jQuery('.feature').removeClass("featureon");
		jQuery('#feature'+count).addClass("featureon");
		jQuery('.featurepic').hide();
		jQuery('#featurepic'+count).fadeIn("fast");
    	
    	
    	
       
        
        
    }
    
       
    else {
    
       totalSec--;
    }
}