/*
	This will return a random quote from an array of quotes.
	To change, just remove, edit, or add quotes to the array.
*/
function getQuote() {
	var quotes = new Array();
	quotes[0]="\"It was very well organized, the course was lovely and it was a beautiful day. I hope this will become an annual event. Wonderful folks who put this together!  Great cause!\" ~ Lynne H.";
	quotes[1]="\"Great event!\" ~ Robert G.";
	quotes[2]="\"This event was awesome. I sure hope it is an annual thing. Great people, great weekend, great weather, all around wonderful. Thank you for such a fabulous event.\" ~ Brooke J.";
	quotes[3]="\"Great Race, an absolutely beautiful course. Well organized and great race goodies!\" ~ Patsy B.";
	quotes[4]="\"Great all around fun, event, staff, participants and cause. Recommend it to everyone and would DEFINITELY do it again!!\" ~ Chad S.";
	quotes[5]="\"Well done all around!\" ~ Pete";
	quotes[6]="\"Amazing day! Everything went smoothly.\" ~ Desmoid Dancer";
	quotes[7]="\"Had a great time at the event!! The gift bags were nice, and I enjoyed the location of the event. It was very well organized.\" ~ Sue H.";
	quotes[8]="\"Fun event! Very well organized!\" ~ Frances S.";
	quotes[9]="\"The Running for answers race and corresponding events provided me with a chance to learn more about, and help raise money for, a tremendous organization that has a great cause behind it, Desmoid Tumor Research.  The event also gave me an excuse to catch up with family and friends and put together a team of people that I am closest with to run together.  The experience of participating is something that I will never forget and I'd suggest that most participants would say the same. If you're even remotely thinking about getting involved, Just do it! You won't regret your decision.\" ~ Ryan K.";
	quotes[10]="\"When I was first diagnosed with a desmoid tumor, there was no community of patients and hardly any information available on the subject. In less than a decade, the DTRF has already done incredible work in bringing patients and families together, and in funding research that has made meaningful progress in the fight against desmoids. As a survivor, I'm so happy to be able to participate in Running For Answers and continue working toward a cure.\" ~ Alex F.";
	quotes[11]="\"Our team from Women in Investing Network (WIN) enjoyed the beautiful fall day to participate in the Running for Answers race and support such a great cause.  All the runners were so supportive of each other from the youngest to the oldest.  We can't wait to participate again in 2011.\" ~ Sharon H.";
	
	return quotes[Math.floor(Math.random()*quotes.length)];
}

/*
	This will return a random picture file name from the picture directory.
	To make this work:
		1. Make sure that pictures follow the same naming convention - Run (X).jpg where X is a number i.e. Run (1), Run (123), etc. NO leading zeros.
		2. Put the picture in images/race_pictures.
		3. Make sure the pictureCount variable gets updated.
	
	Hint:
		To make all pictures have the same name in Windows:
			1. Select all pictures.
			2. Right click on the first one and click Rename.
			3. Give it a name (i.e. Run).
			4. All will be renamed to Run (X).jpg where X is the number.
*/
function getPicture() {
	var pictureCount = 539; // CHANGE THIS TO MAKE SURE ALL PICTURES ARE INCLUDED
	
	return "images/race_pictures/Run (" + Math.floor(Math.random()*pictureCount) + ").JPG";
}

function popupPicture(image) {
	imageWindow = window.open(image, 'image', 'height=100%,width=100%,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');
	imageWindow.resizeTo(810,630);
	imageWindow.moveTo(100,50);
	imageWindow.focus();
}

function showQuoteAndPicture() {
	//var picture = getPicture();
	//document.write('<a id="quote-picture-link" href="#" onclick="popupPicture(\'' + picture + '\');return false;"><img id="quote-picture" class="small left" src="' + picture + '" /></a>');	
	document.write('<a id="quote-picture-link" href="#" onclick="popupPicture(\'images/race_pictures/Run (264).JPG\');return false;"><img id="quote-picture" class="small left" src="images/race_pictures/Run (264).JPG" /></a>');
	
	document.write('<p id="quote" class="quote">' + getQuote() + '</p>');
	
	//setInterval("changeQuoteAndPicture()", 15000);
	setInterval("changeQuote()", 15000);
}

function changeQuoteAndPicture() {
	var picture = getPicture();
	
	var quoteImage = window.document.getElementById("quote-picture");
	var quoteImageLink = window.document.getElementById("quote-picture-link");
	var quoteText = window.document.getElementById("quote");
	
	quoteImage.src = picture;
	quoteImageLink.onclick = "popupPicture(\'' + picture + '\');return false;";
	quoteText.innerHTML = getQuote();
}

function changeQuote() {
	window.document.getElementById("quote").innerHTML = getQuote();
}

var currentSponsor = 0;
var totalSponsors = 5;
var sponsors = new Array(totalSponsors);

function setupSponsors() {
	sponsors[0] = new Array(2);
	sponsors[0][0] = "http://www.questdiagnostics.com";
	sponsors[0][1] = "images/quest_small.jpg";

	sponsors[1] = new Array(2);
	sponsors[1][0] = "http://www.citysports.com";
	sponsors[1][1] = "images/city_sports_small.jpg";

	sponsors[2] = new Array(2);
	sponsors[2][0] = "http://www.fairmountparkconservancy.org";
	sponsors[2][1] = "images/fairmount_park_small.jpg";

	sponsors[3] = new Array(2);
	sponsors[3][0] = "http://www.vitacoco.com";
	sponsors[3][1] = "images/vita_coco_small.jpg";

	sponsors[4] = new Array(2);
	sponsors[4][0] = "http://www.phillyfinancialservices.com";
	sponsors[4][1] = "images/rassler_small.jpg";
}

function showSponsor() {	
	setupSponsors();
	
	document.write('<a id="sponsorLink" href="' + sponsors[currentSponsor][0] + '" target="_blank"><img id="sponsorImage" class="sponsor-logo" src="' + sponsors[currentSponsor][1] + '" /></a>');

	currentSponsor++;
	setInterval("changeSponsor()", 5000);
}

function changeSponsor() {
	var sponsorImage = window.document.getElementById("sponsorImage");
	var sponsorLink = window.document.getElementById("sponsorLink");
	currentSponsor++;
	if ( currentSponsor == totalSponsors) {
		currentSponsor = 0;
	}
	
	sponsorImage.src = 'images/' + sponsors[currentSponsor][1];
	sponsorLink.href = sponsors[currentSponsor][0];
}

var currentStart = 0;

function showSponsorsSlider() {
	setupSponsors();
	
	document.write('<a id="sponsorLink1" href="' + sponsors[currentSponsor][0] + '" target="_blank"><img id="sponsorImage1" class="sponsor-logo" src="' + sponsors[currentSponsor][1] + '" /></a>');
	document.write('<a id="sponsorLink2" href="' + sponsors[currentSponsor + 1][1] + '" target="_blank"><img id="sponsorImage2" class="sponsor-logo" src="' + sponsors[currentSponsor + 1][1] + '" /></a>');
	document.write('<a id="sponsorLink3" href="' + sponsors[currentSponsor + 2][2] + '" target="_blank"><img id="sponsorImage3" class="sponsor-logo" src="' + sponsors[currentSponsor + 2][1] + '" /></a>');
	
	setInterval("changeSponsors()", 5000);
}

function changeSponsors() {
	var sponsorImage1 = window.document.getElementById("sponsorImage1");
	var sponsorLink1 = window.document.getElementById("sponsorLink1");
	var sponsorImage2 = window.document.getElementById("sponsorImage2");
	var sponsorLink2 = window.document.getElementById("sponsorLink2");
	var sponsorImage3 = window.document.getElementById("sponsorImage3");
	var sponsorLink3 = window.document.getElementById("sponsorLink3");
	currentStart++;
	if (currentStart >= totalSponsors) {
		currentStart = 0;
	}
	
	for (var i = 1; i <= 3; i++) {		
		if (i == 1) {
			currentSponsor = currentStart;
			if (currentSponsor >= totalSponsors) {
				currentSponsor = 0;
			}
			sponsorImage1.src = sponsors[currentSponsor][1];
			sponsorLink1.href = sponsors[currentSponsor][0];
		} else if (i == 2) {
			currentSponsor++;
			if (currentSponsor >= totalSponsors) {
				currentSponsor = 0;
			}
			sponsorImage2.src = sponsors[currentSponsor][1];
			sponsorLink2.href = sponsors[currentSponsor][0];
		} else if (i == 3) {
			currentSponsor++;
			if (currentSponsor >= totalSponsors) {
				currentSponsor = 0;
			}
			sponsorImage3.src = sponsors[currentSponsor][1];
			sponsorLink3.href = sponsors[currentSponsor][0];
		}
	}
}

function showSponsorsSliderJQuery() {
	setupSponsors();
	
	$('#sponsor1 a').attr("href", sponsors[0][0]);
	$('#sponsor1 img').attr("src", sponsors[0][1]);
	
	$('#sponsor2 a').attr("href", sponsors[1][0]);
	$('#sponsor2 img').attr("src", sponsors[1][1]);
	
	$('#sponsor3 a').attr("href", sponsors[2][0]);
	$('#sponsor3 img').attr("src", sponsors[2][1]);
	
	setInterval("changeSponsorsJQuery()", 10000);
};

function changeSponsorsJQuery() {
	
	currentStart++;
	if (currentStart >= totalSponsors) {
		currentStart = 0;
	}
	
	for (var i = 1; i <= 3; i++) {
		if (i == 1) {
			currentSponsor = currentStart;
			if (currentSponsor >= totalSponsors) {
				currentSponsor = 0;
			}
			var ix1 = currentSponsor;
			$('#sponsor1').fadeOut(1000,function() {
				$('#sponsor1 a').attr("href", sponsors[ix1][0]);
				$('#sponsor1 img').attr("src", sponsors[ix1][1]);
				$('#sponsor1').fadeIn(2000);
			});
		} else if (i == 2) {
			currentSponsor++;
			if (currentSponsor >= totalSponsors) {
				currentSponsor = 0;
			}
			var ix2 = currentSponsor;
			$('#sponsor2').fadeOut(1000,function() {
				$('#sponsor2 a').attr("href", sponsors[ix2][0]);
				$('#sponsor2 img').attr("src", sponsors[ix2][1]);
				$('#sponsor2').fadeIn(2000);
			});
		} else if (i == 3) {
			currentSponsor++;
			if (currentSponsor >= totalSponsors) {
				currentSponsor = 0;
			}
			var ix3 = currentSponsor;
			$('#sponsor3').fadeOut(1000,function() {
				$('#sponsor3 a').attr("href", sponsors[ix3][0]);
				$('#sponsor3 img').attr("src", sponsors[ix3][1]);
				$('#sponsor3').fadeIn(2000);
			});
		}
	}
}
