$(function(){

$.hotel = {
  init: function(){
    $('.fn-addComment').click( $.hotel.comment.show );
    $('.fn-newComment .fn-submit').click( $.hotel.comment.save );
  }
};
$.hotel.comment = {
  show: function(){
    $('.fn-newComment').show();
  },
  save: function(){
    $.send($('#new_hotel_comment').attr('action'),
           {
             'authenticity_token' : $('[name=authenticity_token]').val(),
             'hotel_comment[title]' : $('[name=hotel_comment[title]]').val(),
             'hotel_comment[message]' : $('[name=hotel_comment[message]]').val(),
             'hotel_comment[captcha]' : $('[name=hotel_comment[captcha]]').val(),
             'hotel_comment[captcha_key]' : $('[name=hotel_comment[captcha_key]]').val()
           },
           $.hotel.comment.saveCallback
    );
    $('.fn-commentForm').hide();
    $('.fn-submitingComment').show();
    return false;
  },
  saveCallback: function(data){
    $.get('/public/update_captcha/hotel_comment', function(data){ $('.fn-captcha').html(data); });
    $('.fn-commentForm').show();
    $('.fn-submitingComment').hide();
    if(data.hotel_comment!=undefined){
      $('.fn-newComment').hide();
      var box = $($('.fn-commentTemplate .comment')).bindTo( data.hotel_comment );
      $(box).insertAfter('.fn-newComment');
    }
  }
}
$.hotel.init();
	
});

