$(document).ready(function() {
	
	$("body").addClass("js");
	
	//////////////////////////////
	// Video togglage apparatus 
	////////////////////////////
	
	$('#media-info a').click( function()
	{
		switch (this.id)
		{
			case "select-images":
				$('#video-media').fadeOut("fast");
				$('#photo-media').fadeIn("fast");
				$(this).addClass("deselected");
				$('#select-video').removeClass("deselected");
				break;
			
			case "select-video":
				$('#photo-media').fadeOut("fast");			
				$('#video-media').fadeIn("fast");				
				$(this).addClass("deselected");
				$('#select-images').removeClass("deselected");				
				break;
		}
		
		return false;
	});
	
	//////////////////////////////
	// Tool:  Your power
	////////////////////////////
	
	$('#power-tool,#power-tool1').click( function()
	{
		$('#overlay').fadeIn("fast");
		$('#overlay #cards-viral').fadeIn("fast");
		
		return false;
	});
	
	$('#tool-ammount').change(calculatePotential);
	$('#tool-ammount').blur(calculatePotential);
	
	//////////////////////////////
	// Questionaire tomfoolery
	////////////////////////////

	$('#questionaire,#questionaire1').click( function()
	{
		$('#overlay').fadeIn("fast");
		$('#cards').fadeIn("fast");
		$('#overlay #cards-0').fadeIn("fast");				
		
		return false;
	});
});

function calculatePotential()
{
	if (!isNaN(this.value))
	{
		$('#tool-results, #tool-results2').text(this.value*this.value);
		$('#results-p').fadeIn("fast");
	}
}


function qPageTransition( from, to )
{
	$("#overlay #cards-" + from ).hide();
	$("#overlay #cards-" + to ).show();
}

function qShowResults()
{	
	var aAnswers = Array();
	aAnswers[0] = $("input[name='q1']:checked").val();
	aAnswers[1] = $("input[name='q2']:checked").val();
	aAnswers[2] = $("input[name='q3']:checked").val();
	aAnswers[3] = $("input[name='q4']:checked").val();
	aAnswers[4] = $("input[name='q5']:checked").val();
	
	var lookup = new Object;
	
	var highestValue = 'c';
	var highestCount = 0;
	
	for (var i=0; i < aAnswers.length; i++) 
	{
		var value = aAnswers[i];
		
		if (!lookup.hasOwnProperty(value))
			lookup[value] = 1;
		else
			lookup[value]++;
		
		if (lookup[value] > highestCount)
		{
			highestCount = lookup[value];
			highestValue = value;
		}
	}
	
	qPageTransition(5,highestValue);
}