// JavaScript Document

$(document).ready(function(){
	
	// Hide website
	$('.container').fadeTo('slow',.02);
	$('.featureBox').fadeTo('slow',.02);
	$('.featureContainer').hide();
	
	
	// Ajax submit
	$("form#formSubmit").submit(function() {
 
	// we want to store the values from the form input box, then send via ajax below
	var first_name = $('#first_name').attr('value');
	var last_name = $('#last_name').attr('value');
	var email = $('#email').attr('value');
	var company = $('#company').attr('value');
	var phone = $('#phone').attr('value');
	var Campaign_ID = $('#Campaign_ID').attr('value');
	var LSD = $('#LSD').attr('value');
	var LS = $('#LS').attr('value');
	var pro = $('#pro').attr('value');
	var cust = $('#learnMore').attr('value');
	var desc = $('#description').attr('value');
 
 		if($('#pro').attr("checked") && $('#email').val() != ""){
		$.ajax({
			type: "POST",
			url: "http://www.copperisgreen.com/includes/php/curlsf.php",
			data: "first_name="+ first_name + "& last_name=" + last_name + "& email="+ email + "& company=" + company + "& phone=" + phone + "& Campaign_ID=" + Campaign_ID + "& 00N80000002mvsA=" + LSD + "& lead_source=" + LS + "& 00N800000034fdq=" + pro + '& 00N80000002nteO=' + cust + '& description=' + desc,
			success: function(del){
					$('#loginBox').fadeOut('slow');
					$('.container').fadeTo('slow',1);
					$('.featureBox').fadeTo('slow',1);
					$('#footer').fadeTo('slow',1);
					$('.featureContainer').show();
					$('#promoTerms').hide();
			}
		});
	return false;
		}
		else{
		if($('#pro').attr("checked") && $('#email').val() == ""){
			alert('Please supply an email address');
		}
		else if(!$('#pro').checked && $('#email').val() == ""){
			alert('Please accept the promotional terms and provide your email address');
		}
		else if(!$('#pro').checked && $('#email').val() != ""){
			alert('Please accept the promotional terms');
		}
		 return false;
		}
	});
	
	// Expand boxes
	$('.featureBox').hover(
	function()  {
		$(this).animate({top:'-310px', height:'560px'},"slow");
			$(this).find('.featuredContent').fadeIn('slow');
		},
		function() {
		$(this).animate({top:'0px', height:'150px'},"slow");
		$(this).find('.featuredContent').fadeOut('slow');
		});
		
		//Show Quiz
	$('#startQuiz').click(function(){
		$('.container').fadeTo('slow', 0.20);
		$('#greenQuiz').show('slow');
		});
	
	// Hide Quiz
	$('#closeQuiz').click(function(){
			$('.container').fadeTo('slow', 1);
		$('#greenQuiz').hide();					   
								   });
	
	$('#promoTermsLink').click(function(){
					$('#promoTerms').fadeIn('slow');
					});
	
	// Show question 1 on load

$("#greenQuiz .quizQuestion:first").show();

	var i = 0;
	var b= 0;
	
	$('#greenQuiz li').click(function(){
		if($(this).attr('class') == 'correct'){
				$(this).parents(".quizQuestion:first").append('<h3>Correct</h3><br/><br/><a href="#" id="next">Next Question</a>');
				$(this).parents('ul').find('.correct').removeClass('correct').addClass('correctAnswer').append('\u00A0\u00A0Correct Answer');
				i = i + 1;
				b = b + 1;
				$('#c3').html(i + " of 9 correct");
				
			} else{
			$(this).parents(".quizQuestion:first").append('<h3>Incorrect</h3><br/><br/><a href="#" id="next">Next Question</a>');
				$(this).parents('ul').find('.correct').removeClass('correct').addClass('correctAnswer').append('\u00A0\u00A0Correct Answer');
				b= b + 1;
				$('#c3').html(i + " of 9 correct");
			}
	});
	
	$('#next').live('click',function(){
		$(this).parents(".quizQuestion:first").hide()
		$(this).parents("div").next('.quizQuestion').fadeIn('slow');
		if(b == 9){
			$('#c3').hide();
			$('#c3Final').html('You scored ' + i + " of 10 correct");
		}
	});
	
});