// Speed of the quotation marks to show
var quoteSpeed = 500;

// Speed of the quote container to expand
var quoteContainerSpeed = 1000;

// Time the quote will be visible
var showQuoteSpeed = 10000;

// Time the screen will be empty
var cleanScreenSpeed = 500;

// Width of the quote box
// Would be cool to automatically grow to the containing text size in the future.
var quoteBoxWidth = "335px";

// The quotes we'll show
var quotes = [ {
		"quote" : "..da waren Sie aber schnell die Mitarbeiter",
		"author" : "- Dr. Matthias K. | Thalwil / Schweiz | März 2011 -"
	}, {
		"quote" : "..danke für die gute Arbeit, Super",
		"author" : "- Michael B. | Rülzheim / Deutschland | Februar 2011 -"
	}, {
		"quote" : "..Dank an Sie für Ihre hervorragende Arbeit",
		"author" : "- Michael Sch. | Berlin / Deutschland | März 2010 -"
	}, {
		"quote" : "..Ich bin sehr zufrieden",
		"author" : "- Roland M. | Wald im Pinzgau / Österreich | Juni 2009 -"
	}, {
		"quote" : "..Wir sind begeistert v.a. meine Frau",
		"author" : "- Gerold M. | Oberhausen / Deutschland | Mai 2011 -"
	}, {
		"quote" : "..Danke für die Sonntagsarbeit!",
		"author" : "- Thomas R. | Berlin / Deutschland | April 2011 -"
	}, {
		"quote" : "..Besonders die schnelle und reibungslose Abwicklung",
		"author" : "- Heiko K. | Wiesbaden / Deutschland | April 2011 -"
	}, {
		"quote" : "..für den perfekt ausgeführten Auftrag",
		"author" : "- Dr. Martin H. | Aachen / Deutschland | März 2011 -"
	}
];

// The quote index to start with
var currentQuoteIndex = 0;

// Document ready
jQuery(document).ready(function()
{	
	// Webkit seems to have different ways of cerning the quotation marks
	// This little hack makes sure it's in the correct position
	if(jQuery.browser.webkit) {
		jQuery(".quotemark").css({ "margin-top" : "-22px" });
		jQuery(".rightquote").css({ "margin-top" : "-24px" });
	}
	
	startAnimation();
});

/* Starts the animation */
var startAnimation = function() {
	setTimeout(function() {
		showLeftQuote();
	}, quoteSpeed);	
}

/* Shows left quote */
var showLeftQuote = function() {
	jQuery(".leftquote").show();
	
	setTimeout(function() {
		showRightQuote();
	}, quoteSpeed);
};

/* Shows right quote */
var showRightQuote = function() {
	jQuery(".rightquote").show();
	
	setTimeout(function() {
		showQuoteContainer();
	}, quoteSpeed);
};

/* Shows the quote container */
var showQuoteContainer = function() {
	// Small fix for the right quotation mark
	jQuery(".rightquote").css({ "margin-left" : "0px" });
	
	jQuery("<p />")
		.html(quotes[currentQuoteIndex].quote)
		.css({ "display" : "none"})
		.appendTo(jQuery(".quote"));
		
	jQuery("<p />")
		.addClass("author")
		.html(quotes[currentQuoteIndex].author)
		.css({ "display" : "none"})
		.appendTo(jQuery(".quote"));

	jQuery(".quote")
		.show()
		.animate({ width : quoteBoxWidth }, quoteContainerSpeed, function() {
			showQuote();
		});
}

/* Shows the current quote */
var showQuote = function() {
	jQuery(".quote").children().fadeIn();
		
	setTimeout(function() {
		clearQuote();
	}, showQuoteSpeed);
}

/* Clear the current quote */
var clearQuote = function() {
	// Determine the curren quote index
	if(currentQuoteIndex == quotes.length - 1) {
		currentQuoteIndex = 0;
	}
	else {
		currentQuoteIndex++;
	}
	
	// Fade out the quotation marks
	jQuery(".quotemark").fadeOut();

	// Fade out the current quote and reset the data	
	jQuery(".quote").fadeOut(function() {
		jQuery(".rightquote").css({ "margin-left" : "0px" });
		
		jQuery(".quote")
			.empty()
			.css({ width : "0px" });
		
		setTimeout(function() {
			startAnimation();
		}, cleanScreenSpeed);
	});
}
