SUM_TEXT = "Hoeveel is {sum}? (tegen spam)";
SUM_ERROR = "De opgegeven som is onjuist. Probeer het nogmaals";

MAX_NUM = 10;
OPERATORS = ['x','+'];

$(function () {
  $.easing.def = "easeOutExpo";
  
  $('a#show_widget_code').attach(ShowWidgetCode);
  $('a#show_send_friend').attach(ShowSendFriend);
  $('.widget-text textarea').attach(SelectAllText);
  
  $('form a.submit').attach(SubmitBehaviour);
  
  $('ul#navigation li.dropdown').hoverIntent(NavigationConfig);
  $('ul#navigation li.dropdown a.dropdown').attach(NavigationBehaviour);
  $('ul#navigation li.dropdown a.dropdown').attach(RollOver);
  
  $('.new_tile p#form-sum').attach(CreateSum);
  
  //-- admin --//
  admin_events();
});

function admin_events (tile_id) {
  if (tile_id == undefined) {
    $('.tile button.feature').attach(FeatureTile);
    $('.tile button.tags').attach(UpdateTile);
    $('.tile a.delete').attach(DeleteTile); 
  } else {
    $('#' + tile_id + ' button.feature').attach(FeatureTile);
    $('#' + tile_id + ' button.tags').attach(UpdateTile);
    $('#' + tile_id + ' a.delete').attach(DeleteTile);
  }
}

function ajax_delete (url, view_function, params) {
  $.ajax({
    type:     "DELETE"
  , cache	:   false
  , url:      url
  , loading:  params.loader.show()
  , success: function (content) {
      setTimeout(function () {
        params.loader.hide();
        if (content.success) {
          view_function(params); 
        }
      }, 2000);
    }
  });
}

function ajax_get (url, view_function) { 
  $.ajax({
    type:     "GET"
  , cache	:   false
  , url:      url
  , loading:  params.loader.show()
  , success: function (content) {
      setTimeout(function () {
        params.loader.hide();
        view_function(content)
      }, 2000);
    }
  });
}

function ajax_post (url, data, view_function, params) {
  $.ajax({
    type:     "PUT"
  , cache	:   false
  , url:      url
  , data:     data
  , loading:  params.loader.show()
  , success: function (content) {
      setTimeout(function () {
        params.loader.hide();
        view_function(content, params);
      }, 2000);
    }
  });
}

function delete_tile (params) {
  $('#' + params.tile_id).remove();
}

function disable_forms (form) {
  form.children('button').attr('disabled', 'disabled');
}

function update_tile (html_content, params) {  
  $('#' + params.tile_id).html(html_content);
  admin_events(params.tile_id);
}

function update_tiles (html_content, params) {  
  $('#' + params.tile_id).html(html_content);
  admin_events();
}