function MoreCat (relParam, moreDiv) {
    this.relParam = relParam;
    this.moreDiv = moreDiv;
}

MoreCat.prototype.$ = function (oid) {
    if (typeof oid == "object") {
        return oid;
    }
    oid = document.getElementById(oid);
    if (oid) {
        return oid;
    } else {
        return null;
    }
};

MoreCat.prototype.inicjalize = function () {
    var rel, link, self = this;
    this.moreList = this.$(this.moreDiv + '-list');
    this.close = this.$(this.moreDiv + '-close')||0;
    this.moreDiv = this.$(this.moreDiv);
    for (var i = 0, ln = document.links.length; i < ln; i++) {
        link = document.links[i];
        rel = link.getAttribute('rel')||'';
        if (rel && rel == this.relParam) {
            link.onclick = function () {
                return self.moreClick(this);
            }
        }
    }
    if (this.close) {
        this.close.onclick = function () {
            this.parentNode.parentNode.style.display = 'none';
            return false;
        }
    }
    return true;
}
MoreCat.prototype.findPosition = function (ob) {
    var nleft = 0;
    var ntop = 0;
    if (ob.offsetParent) {
            nleft = ob.offsetLeft
            ntop = ob.offsetTop
            while (ob = ob.offsetParent) {
                    nleft += ob.offsetLeft
                    ntop += ob.offsetTop
            }
    }
    return [nleft,ntop];
}

MoreCat.prototype.moreClick = function (ob) {
    var div, ul, self = this, aUl, pos = [];
    div = ob.parentNode.parentNode;
    aUl = div.getElementsByTagName('ul');
    ul = aUl[1];
    pos = self.findPosition(aUl[0]);
    self.moreDiv.style.display = 'block';
    self.moreList.innerHTML = ul.parentNode.innerHTML;
    self.moreDiv.style.width = '239px';
    self.moreDiv.style.padding = '5px';
    self.moreDiv.style.left = (pos[0] - 11) + 'px';
    self.moreDiv.style.top = pos[1] + 'px';
    return false;
}

var moreCat = new MoreCat('moreCat', 'more-categories');
moreCat.inicjalize();

