
/* functions/pixel_math.js */

 PixelMath = {
  toPx: function(number, negative) {
    if (number == null) {
      number = '0';
    }
    if (negative === undefined) {
      return number + 'px';
    }
    return (negative ? Math.abs(number) + 'px' : -number + 'px');
  },
  toNum: function(pixel, negative) {
    if (typeof pixel == 'number') {
      if (negative) {
        return Math.abs(pixel);
      }
      else {
        return pixel;
      }
    }
    if (pixel == null) {
      pixel = '0';
    }
    if (negative === undefined) {
      return parseInt(pixel.replace('px', ''));
    }
    return (negative ? Math.abs(pixel.replace('px', '')) : -pixel.replace('px', ''));
  },
  getCompleteElementWidth: function(element) {
    var width = 0;
    ['width','paddingRight','paddingLeft','marginRight','marginLeft','borderRightWidth','borderLeftWidth'].each(function(css_property) {
      css_value = PixelMath.toNum(element.getStyle(css_property));
      if (isNaN(css_value)) {
        css_value = 0;
      }
      width = width + css_value;
    });
    return width;
  },
  getCompleteElementHeight: function(element) {
    var height = 0;
    ['height','paddingTop','paddingBottom','marginTop','marginBottom','borderTopHeight','borderBottomHeight'].each(function(css_property) {
      css_value = PixelMath.toNum(element.getStyle(css_property));
      if (isNaN(css_value)) {
        css_value = 0;
      }
      width = width + css_value;
    });
    return height;
  }
}
