// platform is just a tidy way to add page functionality as it is required

var run_when_ready = [];
window.addEvent('domready', function(){ run_ready(); });

var run_when_loaded = [];
window.addEvent('load', function(){ run_loaded(); });

function run_ready (scope) {
  if (!scope) scope = document;
  run_when_ready.each(function (fun) { fun.run(scope); });
}

function run_loaded (scope) {
  if (!scope) scope = document;
  run_when_loaded.each(function (fun) { fun.run(scope); });
}





// and some useful element methods

var top_z = null;
var topZ = function () {
  if (top_z) return top_z;
  $$('*').each(function (element) {
    z = parseInt(element.getStyle('z-index'), 10);
    if (z > top_z) top_z = z;
  });
  return top_z;
};

Element.implement({
  bringForward: function () {
    top_z = topZ() + 1;
    this.setStyle('z-index', top_z);
  },
  showInline: function () {
    this.setStyle('display', 'inline');
  },
  show: function () {
    var mode = ($chk(this.previous_display_mode)) ? this.previous_display_mode : 'block';
    this.setStyle('display', mode);
  },
  hide: function () {
    this.previous_display_mode = this.getStyle('display');
    this.setStyle('display', 'none');
  },
  touches: function (x,y) {
    at = this.getCoordinates();
    return (x > at.left) && (x < at.left + at.width) && (y > at.top) && (y <= at.y + at.height);
  }
});

var uneventful = function (e) {
  if (e) {
    new Event(e).stop();
    if (e.target) e.target.blur();
  }
};

var show_and_hides = [];
