/**
 * @desc 	JS helper functions under the DD namespace. Uses jQuery.
 * @author	Jannik Wambsganss <j@matterofinterest.de>
 */

$().ready(function() {
	// Spotlight
	if($('#spotlight-wrapper').length > 0){
	    setTimeout("spotlightSwitch(1)", (Math.floor(Math.random()*7001)+2000));
	    setTimeout("spotlightSwitch(2)", (Math.floor(Math.random()*7001)+2000));
	    setTimeout("spotlightSwitch(3)", (Math.floor(Math.random()*7001)+2000));
	}
});

/**
 * @name	spotlightSwitch
 * @desc	start image rotation for single spotlight container (there are several)
 * @author	Jannik Wambsganss <j@matterofinterest.de>
 * @param 	id: id of spotlight-list
 * @return 	false
 */
function spotlightSwitch(id) {
    var active = $('#spotlight-list-' + id + ' li.active');
    var time = null;

    if ($(active).length == 0) $(active) = $('#spotlight-list-' + id + ' li:last-child');

    var next = $(active).next().length ? $(active).next() : $('#spotlight-list-' + id + ' li:first-child');

    $(active).addClass('last-active');
    
    $(active).fadeOut(3000);
    
	$(next).fadeIn(3000, function(){
		time = (Math.floor(Math.random()*5001)+3000)
	    setTimeout( "spotlightSwitch(" + id + ")", time);
	}).addClass('active');
	
	$(active).removeClass('active last-active');

    
    return false;
}
