// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

/** One on One namespace to avoid naming collisions. */
var Ono = {};

/**
 * Object for managing user preferences.
 */
Ono.Preferences = {
  values: {},

  changeFontSize: function(ch) {
    if (ch.toString().match(/px$/i)) {
      document.body.style.fontSize = ch;
      return;
    }

    var currentSize = document.body.style.fontSize;

    if (currentSize == '') {
      currentSize = "14";
      document.body.style.fontSize = currentSize + 'px';
    }

    currentSize = parseInt(currentSize);

    if (ch == '0'){
      if (currentSize < 18){
        currentSize += 1;
        document.body.style.fontSize = currentSize + 'px';
      }
    }
    else {
      if (parseInt(document.body.style.fontSize) > 10){
        currentSize -= 1;
        document.body.style.fontSize = currentSize + 'px';
      }
    }

    this.values["font_size"] = currentSize;
    new Ajax.Request("/preferences/create", {
        method:"get",
        parameters: {prefs: Object.toJSON(this.values)}
      });
  },

  apply: function(prefs) {
    if (prefs && prefs["font_size"]) this.changeFontSize(prefs["font_size"] + "px");
  },

  reset: function() {
    document.body.style.fontSize = "14px";
  }
}

Ono.redirect = function(uri) {
  setTimeout("top.location='" + uri + "'", 100);
}

// setup easy access variables for the objects above
var prefs = Ono.Preferences;