AMLI.Unit = new Object();
AMLI.Unit.List = new Object();
AMLI.Unit.GetClass = function(hover) {
    if (this.gridLink) {
        return hover ? 'avail_highlight_hover' : 'avail_highlight';
    } else {
        return hover ? 'avail_highlight_hover_nl' : 'avail_highlight_nl';
    }
}
AMLI.Unit.MOver = function(unitid, gridLink) {

    this.gridLink = gridLink;
    _get('tr_' + unitid).className = AMLI.Unit.GetClass(true);
    AMLI.Unit.MOverTimeout = setTimeout("AMLI.Unit.ShowInfo(" + unitid + ", " + this.gridLink + ");", 300);
}
AMLI.Unit.MOut = function(unitid) {

    _get('tr_' + unitid).className = AMLI.Unit.GetClass(false);
    
    if (AMLI.Unit.MOverTimeout) {
        clearTimeout(AMLI.Unit.MOverTimeout);
        AMLI.Unit.MOverTimeout = null;
    }
}
AMLI.Unit.WResize = function() {
    for (var id in AMLI.Unit.List) {
        var apt = AMLI.Unit.List[id];
        if (apt.row) {
            apt.row = _get('tr_' + apt.id);
            apt.pos = new element_info(apt.row.cells[3]);
            apt.pos.top -= 90;
            apt.pos.left += apt.row.cells[3].offsetWidth;
        }
    }
    if (_get('AptInfoDiv')) {
        AMLI.Unit.ShowInfo(_get('AptInfoDiv').aptid, this.gridLink);
    }
}
AMLI.Unit.TopAdjust = function(px, dur) {
    if (_get('AptInfoDiv')) {
        var div = _get('AptInfoDiv');

        div.pos = new element_info(div);

        if (dur != null) {

            if (!div.adjustment) {
                div.adjustment = new AMLI.Effects.Animation(
                    [{ element: div, type: 'top', duration: dur}]
                );
            }

            div.adjustment.run([div.pos.top, div.pos.top += px]);
        } else {

            div.pos.top = parseInt(div.style.top);
            div.style.top = ((div.pos.top += px) + 'px');
        }

        this.lastTop = div.pos.top;
    }
}
AMLI.Unit.ShowInfo = function(unitid, gridLink) {

    var apt = AMLI.Unit.List['u_' + unitid];
    this.gridLink = gridLink;

    if (!apt.row) {

        apt.row = _get('tr_' + unitid);
        apt.pos = new element_info(apt.row.cells[3]);
        apt.pos.top -= 90;
        apt.pos.left += apt.row.cells[3].offsetWidth;

        var s = '<div style="padding:12px 12px 0px 12px; font-size: 11pt;">';
        s += '<b style="background-color: white;">';

        try {
            var p = apt.row.cells[3].innerHTML;
            s += 'Rent ' + p + '<sup>*</sup>';
        } catch (e) { }

        if (apt.amenities.length > 0) {
            s += ' &#8226; Amenities';
        }

        s += '</b>';
        s += '</div><ul>';
        for (var a in apt.amenities) {
            s += '<li style="font-size: 11pt;">' + apt.amenities[a];
            if (a == 4) break;
        }
        s += '</ul>';

        s += '<img src="/cmsdata/files/apartments/' + apt.seorname + '/' + apt.seopname + '/floorplans/414x307-' + apt.fptag + '.png"';
        s += ' style="width:310px;height:230px;margin-left:0px;" >';

        apt.html = s;
    }

    if (!this.AptInfoDiv) {

        this.AptInfoDiv = document.createElement('DIV');
        this.AptInfoDiv.id = 'AptInfoDiv';
        this.AptInfoDiv.className = 'AptInfoDiv';

        //position set the 1st time only to prevent flicker - subsequent positioning is done by animation
        this.AptInfoDiv.style.top = apt.pos.top + 'px';
        this.AptInfoDiv.style.left = apt.pos.left + 'px';
        this.lastTop = apt.pos.top;

        document.forms[0].appendChild(this.AptInfoDiv);

        this.AptInfoDiv.slideA = document.createElement('div');
        this.AptInfoDiv.slideA.id = 'AptInfoSlideA';
        this.AptInfoDiv.slideA.style.position = 'absolute';
        this.AptInfoDiv.slideA.zIndex = 11;
        this.AptInfoDiv.appendChild(this.AptInfoDiv.slideA);

        this.AptInfoDiv.slideB = document.createElement('div');
        this.AptInfoDiv.slideB.id = 'AptInfoSlideB';
        this.AptInfoDiv.slideB.style.position = 'absolute';
        this.AptInfoDiv.slideB.zIndex = 11;
        this.AptInfoDiv.appendChild(this.AptInfoDiv.slideB);

        this.AptInfoDiv.animation = new AMLI.Effects.Animation(
                                            [{ element: this.AptInfoDiv, type: 'top', duration: 350 }
                                            , { element: this.AptInfoDiv.slideA, type: 'opacity', duration: 350 }
                                            , { element: this.AptInfoDiv.slideB, type: 'opacity', duration: 350}]
                                        );
    }
    this.AptInfoDiv.style.left = apt.pos.left + 'px';
    if (this.AptInfoDiv.aptid != apt.id) {

        if (!this.AptInfoDiv.lastSlide || this.AptInfoDiv.lastSlide == 'B') {
            this.AptInfoDiv.lastSlide = 'A';
            this.AptInfoDiv.slideA.innerHTML = apt.html;
            this.AptInfoDiv.animation.run([this.lastTop, apt.pos.top], [0, 1], [1, 0]);
        } else {
            this.AptInfoDiv.lastSlide = 'B';
            this.AptInfoDiv.slideB.innerHTML = apt.html;
            this.AptInfoDiv.animation.run([this.lastTop, apt.pos.top], [1, 0], [0, 1]);
        }
        this.AptInfoDiv.aptid = apt.id;
        this.lastTop = apt.pos.top;
    }
    _ie6pngfix.fixAll(this.AptInfoDiv);
}