// var current_quote = 0; wird im seiten JS gesetzt

var busy = false

var quote;

onload_callbacks.push(function() {

	quote = $("#quote blockquote");
	
	if (quotes_autoplay == true) {
		var quote_interval = window.setInterval(function() {
			changeQuote(1, 1000);
		}, 10000);
	}


	$("#quote_next").click(function() {
		window.clearInterval(quote_interval);
		
		if (!busy) {
			changeQuote(1, "normal");
		}
	});
	
	$("#quote_previous").click(function() {
		window.clearInterval(quote_interval);
		
		if (!busy) {
			changeQuote(-1, "normal");
		}
	});
	
});

function changeQuote(direction, speed) {
	if (quotes.length > 1) {

		busy = true;

		current_quote = (current_quote + quotes.length + direction) % quotes.length;

		quote.fadeOut(speed, function() {
			num = current_quote + 1;
			$(this).empty().append('<p><a href="/customer-quotes">„' + quotes[current_quote][0] + '”</a></p><p class="cite"><img src="/img/zitate/' + quotes[current_quote][2] + '" alt="' + quotes[current_quote][1] + '" /></p>').fadeIn(speed);
			
			busy = false;
		});
	}
}
