/*
* 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 = 7000;

// 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 = "300px";

// The quotes we'll show
var quotes = [ {
		"quote" : "Moe's turned my computer around in no time flat! Moe's is reliable, fast, thorough, friendly, professional,<br />and they stand behind their work.<br />I'll use Moe's again and again! You should too!.",
		"author" : "- Dave Hoffman <a style='font-family:helvetica;' href='../documents/testimonials.html'> show Testimonials page "
	}, {
		"quote" : "I have both purchased new equipment and had repair work done at Moe's Computers. His new equipment prices were very competitive and came with a guarantee.",
		"author" : "- Terry <a style='font-family:helvetica;' href='../documents/testimonials.html'> show Testimonials page"
	}, {
		"quote" : "Moe has done what I consider a miracle with my laptop and at a great price.<br />Everything was clearly explained and nothing extra was charged.<br />I have told many people about Moes and He can be trusted 100%.",
		"author" : "- Bruce <a style='font-family:helvetica;' href='../documents/testimonials.html'> show Testimonials page"
	}, {
		"quote" : "Moe is helpful friendly bought a computer from him and it runs great<br />..no problems and he explains things in a way that help you understand computer terms,<br />thanks Moe! I will continue to buy from him again.",
		"author" : "- Priscilla <a style='font-family:helvetica;' href='../documents/testimonials.html'> show Testimonials page"
	}, {
		"quote" : "<br />Fast turn around & a good job. Thanks.",
		"author" : "- Jame <a style='font-family:helvetica;' href='../documents/testimonials.html'> show Testimonials page"
	}, {

                "quote" : "<br />Awesome service.<br />friendly service staff and reasonable prices!",
		"author" : "- alex <a style='font-family:helvetica;' href=' http://ratepoint.com/profile/83226' Target='_blank'> show Testimonials page"
	}, {

                "quote" : "<br />Moe's computers has excellent service, fast and reliable.<br />i would recommend Moe's to anyone.",
		"author" : "- Samah <a style='font-family:helvetica;' href=' http://ratepoint.com/profile/83226' Target='_blank'> show Testimonials page"
	}, {


                "quote" : "<br />Moe's computer is very good center. The center provides very good and fast service.",
		"author" : "- Mohannad <a style='font-family:helvetica;' href=' http://ratepoint.com/profile/83226' Target='_blank'> show Testimonials page"
	}, {

                "quote" : "<br />I recently had repairs done on my computer. Everything was done to my satisfaction. Very good service!",
		"author" : "- RatePoint Reviewer <a style='font-family:helvetica;' href=' http://ratepoint.com/profile/83226' Target='_blank'> show Testimonials page"
	}, {
 
		"quote" : "Moe from Moe's Computers is reliable and efficient.<br />He delivered the computer to my apartment and I was up and running in no time.<br />I would recommend Moe's Computer's to all of my friends.",
		"author" : "- Christina <a style='font-family:helvetica;' href='../documents/testimonials.html'> show Testimonials page"
	}
];

// The quote index to start with
var currentQuoteIndex = 4;

// Document ready
$(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($.browser.webkit) {
		$(".quotemark").css({ "margin-top" : "-22px" });
		$(".rightquote").css({ "margin-top" : "-24px" });
	}	
	
	startAnimation();
});

/* Starts the animation */
var startAnimation = function() {
	setTimeout(function() {
		showLeftQuote();
	}, quoteSpeed);	
}

/* Shows left quote */
var showLeftQuote = function() {
	$(".leftquote").show();
	
	setTimeout(function() {
		showRightQuote();
	}, quoteSpeed);
};

/* Shows right quote */
var showRightQuote = function() {
	$(".rightquote").show();
	
	setTimeout(function() {
		showQuoteContainer();
	}, quoteSpeed);
};

/* Shows the quote container */
var showQuoteContainer = function() {
	// Small fix for the right quotation mark
	$(".rightquote").css({ "margin-left" : "-10px" });
	
	$("<p />")
		.html(quotes[currentQuoteIndex].quote)
		.css({ "display" : "none"})
		.appendTo($(".quote"));
		
	$("<p />")
		.addClass("author")
		.html(quotes[currentQuoteIndex].author)
		.css({ "display" : "none"})
		.appendTo($(".quote"));

	$(".quote")
		.show()
		.animate({ width : quoteBoxWidth }, quoteContainerSpeed, function() {
			showQuote();
		});
}

/* Shows the current quote */
var showQuote = function() {
	$(".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
	$(".quotemark").fadeOut();

	// Fade out the current quote and reset the data	
	$(".quote").fadeOut(function() {
		$(".rightquote").css({ "margin-left" : "0px" });
		
		$(".quote")
			.empty()
			.css({ width : "0px" });
		
		setTimeout(function() {
			startAnimation();
		}, cleanScreenSpeed);
	});
}
