var App = {

  init: function() {
    jQuery(document).ready(function() {
     this.Layout.init();
    }.bind(this))
  },
  
  Layout : {    
    
    init: function() {
      this.set_main_content_padding();
      Event.observe(document.onresize ? document : window, "resize", this.set_main_content_padding);
    },
    
    set_main_content_padding: function() {
      var new_width = (jQuery('body').width()-940)/2.0;
      if (new_width < 10)
        new_width = 10;
      $('main-content').setStyle('margin-left:'+new_width+'px')
    }
  },
  
  modal: function(path) {
    $.get(path, function(data){
      $(data).modal();
    })
  },
  
  activate_uploads_shortcut: function() {
    $(document).keypress(function (e) {
      if(e.which == 402 && e.altKey) { 
        App.modal("/uploads");
      }
    });
  },
  
  activate_save_shortcut: function(form_id) {
    $(document).keypress(function (e) {
      if((e.which == 100 || e.which == 223) && e.altKey) { 
        $(form_id).submit(); // Alt + s
        $.modal("<h1>Gemmer side...</h1>");
      }
    });
  },
  
  activate_edit_shortcut: function() {
    $(document).keypress(function (e) {
      // alert(e.which + " + Ctrl: " + e.ctrlKey);
      // console.log(e.which + " + Ctrl: " + e.ctrlKey);
      var url = window.location.toString();
      if(e.which == 233 && e.altKey) { // Alt + e
        if(url.indexOf("edit=1") != -1) { // close
          window.location = window.location.pathname
          $.modal("<h1>Lukker redigering ...</h1>");
        } else {
          window.location = window.location.pathname + "?edit=1"
          $.modal("<h1>Åbner redigering ...</h1>");
        }
      }
    });
  },
  
  remove_substring: function(string, sub_string) {
    var head = string.indexOf(sub_string);
    var tail = sub_string.length;
    return string.substring(0, head) + string.substring(head+tail, string.length);
  }
}
