var active = "cards",
	cardsDelta = 1500,
	flashDelta = 1500,
	flashWidth = 760,
	fadeOutTime = 1000;
	
function showCards(fromRight)
{
	var deltaFlash = fromRight ? "+=" + flashDelta + "px" : "-=" + flashDelta + "px",
		deltaCards = fromRight ? "+=" + cardsDelta + "px" : "-=" + cardsDelta + "px";
	
	if (fromRight)
	{
		$('#pContent').css("left", "-" + cardsDelta + "px");
	}
	else
	{
		$('#pContent').css("left", cardsDelta + "px");
	}
	
	//animate the flash out of the screen to the right
	$('#flash').animate({
		marginLeft: deltaFlash
	}, fadeOutTime, 'swing',
	function() 
	{
		$(this).hide();
	});
			
	$('#pContent').css("opacity", 0).css("visibility", "visible").animate({
		opacity: 1,
		left : deltaCards
	}, fadeOutTime, 'swing',
	function() 
	{
		active = "cards";
		$("#rightarrow, #leftarrow").show();
	});
}

function showFlash(fromRight)
{
	var deltaFlash = fromRight ? "+=" + flashDelta + "px" : "-=" + flashDelta + "px",
		deltaCards = fromRight ? "+=" + cardsDelta + "px" : "-=" + cardsDelta + "px";
		
	if (fromRight)
	{
		$('#flash').css("margin-left", + (-flashDelta - flashWidth / 2) + "px");
	}
	else
	{
		$('#flash').css("margin-left", (flashDelta - flashWidth / 2) + "px");
	}
		
	//animate initial content 
	$('#pContent').animate({
		left : deltaCards, //to the left
		opacity: 0 //and fade out
	}, fadeOutTime, //1 second animation
	'swing',
	function() 
	{
		$(this).css("visibility", "hidden"); //hide initial content after it's faded out
	});
	
	//flash is hidden by default, so show it
	$('#flash').css("display", "block");
		
	//animate the flash to the left in the screen
	$('#flash').animate({
		marginLeft: deltaFlash
	}, fadeOutTime, 'swing',
	function() 
	{
		active = "flash";
		$("#rightarrow, #leftarrow").show();
	});
}

$(document).ready(function()
{
	$("#rightarrow").click(function()
	{
		$("#rightarrow, #leftarrow").hide();
		
		if (active == "cards")
			showFlash(false);
		else
			showCards(false);
	});
	
	$("#leftarrow").click(function()
	{
		$("#rightarrow, #leftarrow").hide();
		
		if (active == "cards")
			showFlash(true);
		else
			showCards(true);
	});
	
});




