/*
* Author:      Marco Kuiper (http://www.marcofolio.net/)
*/

// 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 = 3000;

// 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 = "280px";

// The quotes we'll show
var quotes = [
		{"quote" : "Laissez une impression<br /> inoubliable."},
		{"quote" : "Pour des &eacute;v&eacute;nements uniques qui marqueront votre entreprise."},
		{"quote" : "Marquer les esprits de vos collaborateurs avec un &eacute;v&eacute;nement."}
];

// 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" });
	}	
	
	startAnimation();
});

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

/* Shows the quote container */
var showQuoteContainer = function() {
	// Citation aleatoire
	var randomQuote = Math.floor ( Math.random() * quotes.length );
	// Small fix for the right quotation mark
	jQuery(".rightquote").css({ "margin-left" : "-10px" });
	
	jQuery("<p />")
		.html(quotes[randomQuote].quote)
		.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 = Math.floor ( Math.random() * quotes.length );
	}
	else {
		currentQuote = Math.floor ( Math.random() * quotes.length );
	}
	
	// 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);
	});
}
