var recommendation_form = {
	fade_in: function() {
		$("#tool_recommendation").animate({
			'top': '0px',
			'height' : '0px'
		}, 700);
		$('#layout_modal').hide();
	},
	
	fade_out: function() {
		$('#layout_modal').css({
			'height': $('body').height() + 'px',
			'opacity': '0.5'
		}).show();
		$("#tool_recommendation").animate({
			'top': '-400px',
			'height' : '380px'
		}, 700);
	},
	
	submit: function() {
		$('<input>')
			.css('display', 'none')
			.attr({
				name: 'recommendation_sent',
				value: 'sent_true'
			})
			.appendTo('#form_recommendation');

		$('#form_recommendation').attr({
			method: 'post'
		}).submit();
	},
	
	chars_left: function(element, ekey) {
		var recommendation_message = '';
		
		$('#recommendation_msg_count').text(100 - $(element).val().length);
		
		if (recommendation_message.length >= 100 && ekey.which != 8 && ekey.which != 46) {
			$(element).val(recommendation_message);
		} else {
			recommendation_message = $(element).val();
		}
	}
};

$(document).ready(function() {
	$("#recommendation_toggler").click(function () {
		recommendation_form.fade_out();
	});
	
	$("#hide_recommendation").click(function () {
		recommendation_form.fade_in();
	});
	
	$('#recommendation_message').keyup(function(ekey) {
		recommendation_form.chars_left(this, ekey);
	});
	
	$("#send_recommendation").click(function () {
		recommendation_form.submit();
	});
	
	$("#layout_modal").click(function () {
		recommendation_form.fade_in();
	});
});


