var timer = '';

jQuery(document).ready(function(){
	/*
	 * SLOGANS
	 */
	randomElements = jQuery(".slogan-item:first").get().sort(function(){ 
		  return Math.round(Math.random())-0.5
	}).slice(0,1)
		
	var item = jQuery(randomElements).attr('id');
	showSlogan(item); 
	
	timer = setTimeout( "loopSlogans()", 6000 );
	
	
});

function loopSlogans() {		
	clearTimeout(timer);
	var found = false;
	var changed = false;
	var current = '';
	var next = '';
	jQuery(".slogan-item").each(function() {		
		if(!changed){
			if(found){				
				changed = true;
				next = this;
			}
			if ( jQuery(this).hasClass('active') ) {
				found = true;
				current = this;
			}
		}
		
	});
	
	if(!changed){
		next = jQuery(".slogan-item:first");
	}	
	
	hideSlogan(jQuery(current).attr('id'), function(){ 		
		showSlogan(jQuery(next).attr('id'));
		 
	})
	
	timer = setTimeout( "loopSlogans()", 6000 );	
}


function showSlogan(id)
{	
	jQuery('.slogan-item').css({zIndex:99}).fadeOut(0);
	jQuery('#' + id).css({zIndex:90}).fadeIn(1000,function(){
		//jQuery('#' + id).css('filter','');

		jQuery('#' + id).addClass('active'); 
	});
}

function hideSlogan(id, callback)
{
	var returnCall = callback;
	jQuery('#' + id).css({zIndex:90}).fadeOut(1000,function(){
		//jQuery(this).css('filter','');
		jQuery('#' + id).removeClass('active'); 
		returnCall();
	});	
}


