// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// style.js

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// init style

  function init_style () {
    if (list = $$('.teaser')) {
      list.each(function (obj) { $('teaser').insert(obj.remove()); });
    }
    if (teaser = $('teaser')) {
      var pos = 50; teaser.childElements().each(function (obj) {
        var left = to_pct(pos);
        var width = to_pct(100 - pos);
        var style = { 'position': 'relative', 'left': left, 'width': width };

        obj.setStyle(style); pos += 5;
      });
    }
    if (list = $$('.sideblock')) {
      list.each(function (obj) { $('sideblock').insert(obj.remove()); });
      if (list.length > 0) $('sideblock').addClassName('active');
    }
    if (list = $$('.below-page')) {
      list.each(function (obj) { $('below-page').insert(obj.remove()); });
    }
    if (list = $$('p.icons')) {
      list.each(function (p) {
        if (children = p.descendants()) {
          var width = max_width(children) + 40;
          var height = max_height(children) + 0;

          children.each(function (obj) {
            var d_width  = width - obj.getWidth();
            var left     = Math.floor(d_width / 2);
            var right    = d_width - left;
            var d_height = height - obj.getHeight();
            var top      = Math.floor(d_height / 2);
            var bottom   = d_height - top;
            var padding  = [top,right,bottom,left];
                padding  = padding.map(to_px).join(' ');

            obj.setStyle({ 'padding': padding });
          });
        }
      });
    }
    if (list = $$('div.fix-width table')) {
      var max = max_width(list);

      if (max > 0) {
        max = to_px(max);
        list.each(function (obj) { obj.setStyle({ 'width': max }); });
      }
    }
  }

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// get max element dimensions

  function max_width (list) {
    var max = 0; list.each(function (obj) {
      var width = obj.getWidth();
      if (width > max) max = width;
    });
    return max;
  }
  function max_height (list) {
    var max = 0; list.each(function (obj) {
      var height = obj.getHeight();
      if (height > max) max = height;
    });
    return max;
  }

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// format dimensions

  function to_px (int) {
    return int.toString() + 'px';
  }
  function to_pct (int) {
    return int.toString() + '%';
  }

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// showtime

  document.observe('dom:loaded',init_style);

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

