// Generated by CoffeeScript 1.3.2-pre
(function() {

  window.Calculator = (function() {

    function Calculator() {}

    Calculator.bind = function() {
      var calculator;
      calculator = new Calculator;
      $('.calc').click(calculator.toggle);
      $('form#calculator').submit(calculator.calculate).submit(function(e) {
        return e.preventDefault();
      });
      return $('div.help-wrapper a').hover(calculator.helpToggle).click(function(e) {
        return e.preventDefault();
      });
    };

    Calculator.prototype.toggle = function() {
      $('li.calc-main').toggleClass('open');
      $('#calculator_wrapper #calculator_input').focus();
      return $('.calc').toggleClass('closed');
    };

    Calculator.prototype.helpToggle = function() {
      return $('.help').toggleClass('shown');
    };

    Calculator.prototype.calculate = function() {
      return $.getJSON('/calculate', {
        equation: $('#calculator_input').val()
      }, function(data) {
        return $('#calculator_output').val(data.result);
      });
    };

    return Calculator;

  })();

  window.FeedbackForm = (function() {

    function FeedbackForm() {}

    FeedbackForm.bind = function() {
      return $('#feedback_button').click(function() {
        var data;
        data = {
          subject: $('#feedback_subject').val(),
          message: $('#feedback_message').val(),
          url: window.location.href
        };
        return $.post('/send_feedback', data, function() {
          return $('#feedback_div').html('Feedback submitted. Thank you');
        }, 'json');
      });
    };

    return FeedbackForm;

  })();

  $(function() {
    $.ajaxSetup({
      headers: {
        'X-CSRFToken': $.cookie('csrftoken')
      }
    });
    FeedbackForm.bind();
    Calculator.bind();
    return $("a[rel*=leanModal]").leanModal();
  });

}).call(this);
