//GLOBAL VARS
var currentAnswer = 1;
var totalAnswers = 0;

$(document).ready(function() {
	
	//Count number of answers on splash page
	$("#answer_wrapper .answer").each(function(){
		totalAnswers++;
	});
	//$('.main_wrapper').fadeIn();
	$('.main_wrapper').show();
	$('.left').height($('.right').height());
	
	//fade out on click of the navigation
	/*$('a.fade_link').click(function(){
		$('.main_wrapper').fadeOut(500);
		var theURL = $(this).attr("href");
		setTimeout('redirectTo("'+theURL+'")', 500);
		return false;
	});*/
	
	//slide content in
	$('.content').animate({left: 20}, 1000);
	
	
	//Rotate answer text on splash page
	setInterval(function(){
		if(currentAnswer == totalAnswers)
		{
			currentAnswer = 1;
		}
		else
		{
			currentAnswer++;
		}
		//$("#answer_wrapper p").fadeOut(1000);
		//$("#answer_wrapper p").eq(currentAnswer-1).fadeIn(1000);
		$("#answer_wrapper p").animate({
			'left' : -480
		},1000, function() {
			$("#answer_wrapper p").eq(currentAnswer-1).animate({left: 20}, 1000);
		});
		
	},10000);
	
	
	//COLLAPSABLE DIVS FOR INSURED PART
	$('.expandable_div').each(function() {
		var trigger = $('h2 a', this);
		var div = $('div', this);
		var shown = false;
		
		$(div).hide();
		
		$(trigger).click(function() {
			if (shown) {
				$(div).slideUp('fast');
				$(trigger).css('background-position','0 0');
				shown = false;
			} else {
				$(div).slideDown('fast');
				$(trigger).css('background-position','0 -16px');
				shown = true;
			}
		});
	});
	
	
});

// Redirect to the href of the a tag that was
// clicked since the fadeing effect required
// disableing the default action of an a tag.
function redirectTo(theURL){
	window.location = theURL;
}
