preloadImages(
	"./images/ss_4xfaster_1.jpg",
	"./images/ss_4xfaster_2.jpg",
	"./images/ss_4xfaster_3.jpg",
	"./images/ss_pearson_1.jpg",
	"./images/ss_pearson_2.jpg",
	"./images/ss_pearson_3.jpg",
	"./images/ss_pearson_4.jpg",
	"./images/ss_coloradolaw_1.jpg",
	"./images/ss_coloradolaw_2.jpg",
	"./images/ss_finals-club_1.jpg",
	"./images/ss_finals-club_2.jpg",
	"./images/ss_finals-club_3.jpg",
	"./images/ss_finals-club_4.jpg",
	"./images/ss_mwssa_1.jpg",
	"./images/ss_mwssa_2.jpg",
	"./images/ss_tripology_1.jpg",
	"./images/ss_tripology_2.jpg",
	"./images/ss_tripology_3.jpg",
	"./images/ss_tripology_4.jpg)",
	"./images/ss_compass_1.jpg",
	"./images/ss_compass_2.jpg",
	"./images/ss_radius_1.jpg",
	"./images/ss_radius_2.jpg");

$(function()
{
	$("#spotlight").cycle(
	{
		fx: 'scrollHorz',
		speed:  500,
		timeout: 0,
		next: '#next',
		prev: '#prev',
		after: slideAfter
	});
	getTwitters('twitter-feed',
	{
		id: 'shaneriley',
		count: 3,
		enableLinks: true,
		ignoreReplies: false,
		clearContents: true,
		template: '<blockquote><p>"%text%"</p></blockquote><em><a href="http://twitter.com/%user_screen_name%/statuses/%id%/">%time%</a></em>'
	});
	$("#spotlight ul a").click(function()
	{
		src = $(this).attr("href");
		alt = $(this).children().attr("alt");
		element = $(this).parent().parent().parent().siblings(".ss");
		element.fadeOut(400, function(){element.attr("src", src).attr("alt", alt).fadeIn(400)});
		return false;
	});
	$("#spotlight h1 a").attr("target", "_blank");
	$("#spotlight ul").each(function()
	{
		$("li:odd", $(this)).addClass("even");
	});
	$("li.btn_home a").click(function()
	{
		$("#contact").fadeOut(400, function()
		{
			$("#spotlight, #spotlight-slides").fadeIn(400);
		});
		return false;
	});
	$("li.btn_contact a").click(function()
	{
		$("#spotlight, #spotlight-slides").fadeOut(400, function()
		{
			$("#contact").fadeIn(400);
		});
		return false;
	});
	$("#contact form").submit(function()
	{
		form = $(this);
		variables = "";
		error = false;
		for (i = 0; i < $("input[type=text]", form).length; i++)
		{
			e = $(("input[type=text]:eq(" + i + ")"), form);
			if (e.val() == "")
			{
				e.addClass("error");
				e.prev().addClass("error");
				error = true;
			}
			else if (e.attr("name") == "security_code" && e.val().length < 6)
			{
				e.addClass("error").prev().addClass("error");
				error = true;
			}
			else
				variables += "&" + e.attr("name") + "=" + e.val();
		}
		// Form elements don't exist, but just in case they're added in the future.
		for (i = 0; i < $("input[type=hidden]", form).length; i++)
		{
			e = $(("input[type=hidden]:eq(" + i + ")"), form);
			variables += "&" + e.attr("name") + "=" + e.val();
		}
		for (i = 0; i < $("select", form).length; i++)
		{
			e = $(("select:eq(" + i + ")"), form);
			if (e.val() == "")
			{
				e.addClass("error");
				e.prev().addClass("error");
				error = true;
			}
			variables += "&" + e.attr("name") + "=" + e.val();
		}
		for (i = 0; i < $("textarea", form).length; i++)
		{
			e = $(("textarea:eq(" + i + ")"), form);
			if (e.val() == "")
			{
				e.addClass("error");
				e.prev().addClass("error");
				error = true;
			}
			variables += "&" + e.attr("name") + "=" + e.val();
		}
		variables = variables.substring(1) + "&ajax=true";
		if (error)
		{
			$("h2", form).text('Please complete the marked fields');
		}
		else
		{
			$("#content").append('<div id="sending"></div><div id="ajax-loader"></div>').animate({opacity: 1.0}, 2000, function()
			{
				$.ajax(
				{
					type: "POST",
					url: "emailsend.php",
					data: variables,
					success: function(html)
					{
						(html == "success") ? 
							form.html('<h2 style="padding-left: 0;">Thank you!</h2><p>Thank you for contacting me. You should receive a response within 24 hours.</p>') :
							$("h2", form).text('CAPTCHA Incorrect').parent().find("input[name=security_code]").addClass("error").prev().addClass("error");
						$("#sending, #ajax-loader").remove();
					}
				});
			});
		}
		/*phpData = "security_code=" + $("input[name=security_code]").val() + "&name=" + $("input[name=name]").val() + "&from=" + $("input[name=from]").val() + "&message=" + $("textarea").val();
		$.ajax(
		{
			type: "POST",
			url: "emailsend.php",
			data: phpData,
			beforeSend: function()
			{
				$("#content").append('<div id="sending"></div><div id="ajax-loader"></div>').animate({opacity: 1.0}, 2000);
			},
			success: function(html)
			{
				$("#contact fieldset").html('<h2>Thank you!</h2><p>Thank you for contacting me. You should receive a response within 24 hours.</p>');
				$("#sending, #ajax-loader").remove();
			}
		});*/
		return false;
	});
	$("form input[type=text], form select, form textarea").blur(function()
	{
		$(this).removeClass("error").prev().removeClass("error");
	});
});

function slideAfter()
{
	$("#project-title").html(this.title);
}

function preloadImages()
{
	for (i = 0; i < arguments.length; i++)
	{
		jQuery("<img>").attr("src", arguments[i]);
	}
}