function callback (post_id, exception) { 
	if(post_id) { 
		
	} 
} 

function fb_send(test_name, message) {
	var actionLinks = [{"text": "Take The Test", "href": 'http://health.lapadoo.com/'}];
	message = message+"\n\n"+'http://health.lapadoo.com/';
	var attachment = {'media':[{'type':'image','src':'http://health.lapadoo.com/images/fb_logo.png','href':'http://health.lapadoo.com/'}]}; 
	FB.Connect.streamPublish(message, attachment, actionLinks, null, test_name, callback);
}

/**
 * document ready function
 */

function navigate(obj) {
	//check for error
	if(obj.hasClass('check_number')) {
		var num = parseInt(obj.siblings("input[type='text']").val());
		if(isNaN(num) || num <= 0) {
			alert($('#enter_number').text());
			return false;
		}
	} else if(obj.hasClass('check_radio')) {
		var num = parseInt(obj.siblings("input[type='radio']:checked").val());		
		if(isNaN(num) || num <= 0) {
			alert($('#please_select').text());
			return false;
		}	
	}
	
	if(obj.hasClass('next_question')) {
		obj.parent().hide().next().show();
	} else {
		obj.parent().hide().prev().show();
	}
	
	//focus
	if(obj.parent().next().hasClass('focus')) {
		obj.parent().next().children("input[type='text']").focus();
	}
	
	if(obj.hasClass('finish')) {
		$('.result_box').show();
		var nh = $('.dot.red').length;
		$('.problem_count').html(nh);
		$('.problem_count').parent().addClass(nh > 0 ? 'red' : 'green');
		if(nh == 1) {
			$('.problem_count').siblings('.plural').addClass('hidden').siblings('.single').removeClass('hidden');
		}
	}
	
	if(obj.hasClass('bmi')) {
		var w = parseInt($('#weight').val());
		var h = parseInt($('#height').val());
		var bmi = !isNaN(w) && !isNaN(h) ? 10000*w/(h*h) : 50;		
		var position = bmi > 18.5 && bmi < 23 ? 10 : 90;
		position = bmi > 15 && bmi <= 18.5 ? 45 : position;
		position = bmi >= 23 && bmi < 27.5 ? 51 : position;
		position = bmi >= 27.5 && bmi < 40 ? 70 : position;
		position = bmi >= 40 || bmi <= 15 ? 90 : position;
		
		$('#dot_q_4').css('top', position+'%');
		$('#dot_q_4').removeClass('red green').addClass(position > 50 ? 'red' : 'green');
	} 
}

$(document).ready(function() {
	
	$('input.next_question, input.previous_question').click(function() {
		//check for error
		navigate($(this));
		
		return false;
	});
	
	
	$("input[type='radio']").click(function() {
		var id = 'dot_'+$(this).attr('name');		
		var position = $("input[name='"+$(this).attr('name')+"']:checked").val();		
		
		$('#'+id). css('top', position+'%');
		$('#'+id).removeClass('red green').addClass(position > 50 ? 'red' : 'green');
		
		
		return true;
	});
	
	$('a.tos').click(function(e) {
		$('div.tos').toggle("fast");
		return false;
	});
	
	$(".question.focus input[type='text']").keypress(function(e) {
		if(e.keyCode == 13) {
			
			navigate($(this).siblings('input.next_question'));
			return false;
		}
	});
	
	$('#test_form').submit(function() {
		if($('#tos').is(':checked') || $('.tos_div').length == 0) {
			return true;
		} else {
			$('.tos_div').addClass('error');
			$('#for_tos').addClass('red');
			$('.tos_arrow').show();			
			return false;
		}
	});
	
	$('.fb_send').click(function(e) {
		var test_name = $('#app_name').html();
		var message = $('#fb_message').html();
		fb_send(test_name, message);
		return false;
	});
	
});


