$(document).ready(function(){
	DLT.feature.init();
});


var DLT = {
	
	feature : {
		interval : 4000,
		duration : 600,
		timer : null,
		
		init : function() {
			DLT.feature.timer = setTimeout( DLT.feature.next, DLT.feature.interval );
		},
		
		showFeature : function( link, index ) {
			
			if (! $(link).hasClass('current')) {
				clearTimeout(DLT.feature.timer);
				// Change link class
				$('#featurePagination a.current').removeClass('current');
				$(link).addClass('current');
				
				// Fade out feature and fade in new
				$('.featureItem:visible').fadeOut( DLT.feature.duration );
				$('.featureItem:nth-child('+index+')').fadeIn( DLT.feature.duration );
				DLT.feature.timer = setTimeout( DLT.feature.next, DLT.feature.interval );
			}
		},
		
		next : function() {
			var index = $('#featurePagination a.current').index('#featurePagination a') + 1;
			var newIndex = index >= $('#featurePagination a').length ? 1 : index + 1;
			
			clearTimeout(DLT.feature.timer);
			
			DLT.feature.showFeature( $('#featurePagination a:nth-child('+newIndex+')'), newIndex );
			
			DLT.feature.timer = setTimeout( DLT.feature.next, DLT.feature.interval );
		}
	}
};


