$(document).ready(function(){
	// Start Tooltips
    $(".box").tooltip({
       effect: 'slide',
       relative: true,
       position: 'top center',
       offset: [30, 0]
    }).dynamic({ top: { direction: 'up', bounce: true } }); // End Tooltips

	// Start Fake Checkboxes
    // check for what is/isn't already checked and match it on the fake ones
    $("input:checkbox").each( function() {
        (this.checked) ? $("#fake"+this.id).addClass('fakechecked') : $("#fake"+this.id).removeClass('fakechecked');
    });
    // function to 'check' the fake ones and their matching checkboxes
    $(".fakecheck").click(function(){
        ($(this).hasClass('fakechecked')) ? $(this).removeClass('fakechecked') : $(this).addClass('fakechecked');
        $(this.hash).trigger("click");
        
        var n = $("input:checked").length;
        // enable if at least one check is clicked
    	if (n >= 1) {
    		$('#formy').slideDown('1500');
    		$("a#final-submit").removeClass('disabled').bind('click', function() {
    			$(this).colorbox({inline:true, href:"#formup", opacity:0.50});
			})
 		// disable if no checks are clicked
    	} else if (n == 0) {
    		$('#formy').slideUp('2000');
    		$("a#final-submit").addClass('disabled').unbind('click');
    	}
    	
        return false;
    }); // End Fake Checkboxes
    
    $("input:checkbox").click( function() {
    	$( 'html, body' ).animate({scrollTop:320}, 1500);
    });

	// Start Link Behaviors
	$("a.twitter").colorbox({width:"30%", height:"30%", inline:true, href:"#twitter-instructions", opacity:0.50});
	$("a.facebook").colorbox({width:"30%", height:"30%", inline:true, href:"#facebook-instructions", opacity:0.50});
	// End Link Behaviors

		function confirmMessage() {
			pledgelist = "";
			if ($('#no-car').attr('checked')) pledgelist += "\t<li>Get out of your car</li>\n";
			if ($('#no-junkmail').attr('checked')) pledgelist += "\t<li>Say \"NO\" to junkmail</li>\n";
			if ($('#no-lint').attr('checked')) pledgelist += "\t<li>Clean your dryer's lint screen</li>\n";
			if ($('#cold-wash').attr('checked')) pledgelist += "\t<li>Wash in cold water</li>\n";
			if ($('#tell-senate').attr('checked')) pledgelist += "\t<li>Tell the Senate to pass climate and energy legislation</li>\n";
			if (pledgelist == "") {
				msg = "Thank you for your information.";
			} else {
				msg = "You are pledging to\n";
				msg += "<ul>\n";
				msg += pledgelist;
				msg += "</ul>\n";
			}
			
			// $('#confirmation').append(msg);
			// $.fn.colorbox({inline:true, href:"#confirmation-message", opacity:0.50, width:300, height:300});
			$('#pledge').css('height','100px').html('<p id="confirmation">Thank you for your pledge.<br />See how you can spread the word below!</ >');
			$('#formy').slideUp('slow');
			$( 'html, body' ).animate({scrollTop:0}, 1500);
		}
		
		$("#dirty-energy-form").validationEngine({
			promptPosition: "bottomLeft", // OPENNING BOX POSITION, IMPLEMENTED: topLeft, topRight, bottomLeft, centerRight, bottomRight
			beforeSuccess:  function() { confirmMessage(); },
			ajaxSubmit: true,
				ajaxSubmitFile: "form-process.php",
			success: function(){ confirmMessage(); },
			// failure: function(){ alert('Please correct the listed errors to submit your entry.'); }
		});
	
});
