/**
 * @author pop webdev [cn]
 * @version: 0.3.
 * @classDescription: Gets and sets equal height to a collection of elements
 * @dependencies: Prototype v1.6.1
 */
// start HeightAdjust
var HeightAdjust = Class.create({
    initialize: function (items, options) {
        this.items = items;
        this.length = items.size();
        if (this.length <= 1) { return; }
        this.options = Object.extend({
            parentElem: false, 			// set parent element, defaults to false, or pass in $id
            ieAdj: 0, 					// IE adjustment amt, because IE doesn't always count pixels correctly
            repeatPattern: this.length		// default to all items, intended for future use
        }, options || {});
        this.groups = this.items.eachSlice(this.options.repeatPattern);
        this.groupCount = this.groups.size();

        this.height = 0; // start with 0 height baseline
        this.tpad = parseInt(items[0].getStyle('padding-top')); // get first elements padding-top in pixels as a number
        this.bpad = parseInt(items[0].getStyle('padding-bottom')); // get first elements padding-bottom in pixels as a number

        var first, last, adjHeight = 0;
        for (var i = 0; i < this.groupCount; i++) {
            first = i * this.options.repeatPattern;
            last = first + this.options.repeatPattern;

            adjHeight = this.GetHeight(first, last); // - (this.tpad + this.bpad); // remove vertical padding from height calculation
            if (isIE) { adjHeight += this.options.ieAdj }

            this.SetHeight(first, last, adjHeight);
        }

    },
    GetHeight: function (first, last) {
        var newHeight = this.height;
        for (var i = first; i < last; i++) {
            // loop thru and update this.height with tallest height
            if (this.items[i]) { // make sure element actually exists
                if (this.items[i].getHeight() > newHeight) {
                    newHeight = this.items[i].getHeight();
                }
            }
        }
        return newHeight;
    },
    SetHeight: function (first, last, adjHeight) {
        if (this.options.parentElem) {
            this.options.parentElem.style.height = adjHeight + 'px';
        }
        for (var i = first; i < last; i++) {
            // loop thru and update this.height with tallest height
            if (this.items[i]) { // make sure element actually exists
                this.items[i].style.height = adjHeight + 'px';
            }
        }
    }
});
// end HeightAdjust

