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

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

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

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

// Width of the quote box
var quoteBoxWidth = "100%";

// The quotes we'll show
var quotes = [ 
{
		"quote" : "Thanks to direct contracting, our annual medical costs are dramatically lower than the national average.",
		"author" : "Roger Merrill, M.D., Chief Medical Officer, Perdue Farms Inc."
	}, 
{
		"quote" : "Our direct provider networks are extremely stable and our employees are very satisfied with the networks that Blue Bell owns.",
		"author" : "Bill Rankin, CPA, Chief Financial Officer, Blue Bell Creameries, L.P."
	}, 
{
		"quote" : "Our average savings from direct networks are 24% better than commercial managed care networks in the same locations.",
		"author" : "Roger Merrill, M.D., Chief Medical Officer, Perdue Farms Inc."
	}, 
{
		"quote" : "Savings to our claims fund have exceeded 20% and we've saved at least $20 for every dollar spent developing direct networks.",
		"author" : "Bill Rankin, CPA, Chief Financial Officer, Blue Bell Creameries, L.P."
	},
{
		"quote" : "As the recognized leader in direct contracting, A.J. Lester & Associates is saving its clients millions in health plan costs.",
		"author" : ""
	}
];

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