/*
 * What's New
 * v1.0
 */

(function(jQuery) {
	
    var wnTimer = null;
	var wnDelay = 5000;		// Delay in ms between item changes
	var wnAnimDur = 250;	// Duration in ms for item animation
	var wnActiveId = 1;		// Id of acive item
	
	function nextItem() {
		if (wnTimer) {
			clearTimeout(wnTimer);
	    }
	    // Fade out current item
	    jQuery('#whats-news-item-'+wnActiveId).fadeOut(wnAnimDur, function() {
	    	// Assign next item
			wnActiveId++;
			if (wnActiveId>wnItemCount)
				wnActiveId=1;
				
			// Show next item
			jQuery('#whats-news-item-'+wnActiveId).fadeIn(wnAnimDur);
	    });
		
		try {
            wnTimer = setTimeout(nextItem, wnDelay);
        } catch(e) {}

        return false;
	}
	
    jQuery(document).ready(function() {
    	// Reveal first item
		jQuery('#whats-news-item-'+wnActiveId).fadeIn(wnAnimDur);
		
		// Start animation if more than one panel
		var wnPanels = jQuery('div.block-whats-new').find('div.item-container');
		if (wnPanels.size()>1)
		{
			try {
	            if (!wnTimer) {
					wnTimer = setTimeout(nextItem, wnDelay);
	            }
	        } catch(e) {}
	    }	
    });
})(jQuery);