
function callback (post_id, exception) { 
	if(post_id) { 
		
	} 
	//$('.disable_screen').hide();
} 

function facebookLogin() {
	//$('.disable_screen').show();
	var attachment = {'media':[{'type':'image','src':'http://breakup.lapadoo.com/img/heart.png','href':'http://breakup.lapadoo.com'}]}; 
	var actionLinks = [{"text": "Take the Break-Up Test", "href": "http://breakup.lapadoo.com"}];
	
	FB.Connect.streamPublish($('#fb_message').html(), attachment, actionLinks, null, 'What do you think?', callback);
}


function check_tos() {
	if($('#tos').is(':checked')) {
		return true;
	} else {
		$('.tos_div, #for_tos').addClass('error');
		$('.tos_arrow').show();			
		return false;
	}
}	

	
function navigate(obj) {

	var is_error = true;
	var checked = 0;
	if(!obj.hasClass('prev')) {
		$('.question.visible input.check_it').each(function (i) {
			checked++;
			var val = parseInt($(this).val());
			if(!isNaN(val)) {
				is_error = false;
			}
		});
	}
	
	if(checked == 0 || !is_error) {
		if(obj.hasClass('prev')) {
			$('.question.visible').removeClass('visible').hide().prev().addClass('visible').show();
		} else {
			$('.question.visible').removeClass('visible').hide().next().addClass('visible').show();
		}
		
		//first visible, disable "prev"
		if($('.question.visible').hasClass('first')) {
			$('.container .prev').addClass('disabled');
		} else {			
			$('.container .prev').removeClass('disabled');
		}
		
		//same for "next"
		if($('.question.visible').hasClass('last')) {
			$('.container .next').addClass('disabled');
		} else {			
			$('.container .next').removeClass('disabled');
		}
		
		$('.question.visible input.check_it:first').focus();
		$("#progress").progressBar($('.question.visible .percent').html());
	} else {
		alert($('#check_text').html());
	}
}	



/**
 * document ready function
 */
$(document).ready(function() {
	
	if($("#progress").length > 0) {
		$('.question.visible input.check_it:first').focus();
		$("#progress").progressBar(10, { barImage: 'img/progressbg_orange.gif'});
		
	}
	
	$('.container .prev, .container .next, .step').click(function(e) {
		navigate($(this));
	});
	
	$('input.check_it').keypress(function(e) {
		if(e.keyCode == 13) {
			navigate($(this).siblings('.step'));
			return false;
		}
	});
	
	$('.start_test_a').click(function(e) { 
		return check_tos();
	});
	
	$('#start_test').submit(function() {
		return check_tos();
	});
	
	
});