var HTPATH = $('#logo').attr('href').replace(/https?.(.*?)\/[^\/]+$/, '$1');
$('#debt-quiz li').each(function(i){
	$(this).wrapInner('<div class="q"/>')
	.append('<div class="f">'
		+'<label><input type="checkbox" name="q'+i+'"/> Yes</label>'
		+'</div>'
	)
}).find('input').change(function(){
	$('.help').remove();
	if(2 <= $(this).closest('ol').find('input:checked').length)
		$(this).closest('ol').after('<h2 class="help"><a href="'+HTPATH+'get-started">It\'s time to get help.</a></h2>');
});
$(function(){
	if(!$('.page-hero #slider').length) return;
    $('.page-hero #slider').nivoSlider({
        effect:'fade',
        slices:15,
        animSpeed:500,
        pauseTime:8000,
        directionNav:false,
        controlNav:false,
        keyboardNav:false,
		pauseOnHover:false
    });
});
$('a[rel="_blank"]').each(function(){
	$(this).attr('target', $(this).attr('rel')).removeAttr('rel');
});
$('a[href*="FillableForm.pdf"]').click(function(e){
	event.preventDefault();
	imgs = [];
	for(i in PDFTrackingURLs){
		imgs[i] = new Image();
		imgs[i].src = PDFTrackingURLs[i];
	}
	window.location = $(this).attr('href');
});
/** FAQ **/
$('body.faq #content h3').next().hide().prev().css('cursor', 'pointer').click(
	function(){$(this).next().toggle(200);},
	function(){$(this).next().toggle(200);}
);
/** Application Form **/
$(
	'#my-take-home,'+
	'#my-other-amount,'+
	'#spouse-take-home,'+
	'#spouse-other-amount,'+
	'#vehicle1-payment,'+
	'#vehicle2-payment,'+
	'#zip,'+
	'#tax-refund,'+
	'#expenses input.text,'+
	'#creditors td.balance input, '+
	'#creditors td.payment input'
).change(function(){
	if(!isNaN($(this).val() * 1))
		return $(this).parent().removeClass('error').removeClass('current');
	$(this).parent().addClass('error').addClass('current');
	setTimeout(
		"$('.current input').get(0).focus(); alert('Please enter a valid number.');", 10
	);
});
