function CategoriesDropDown(relParam, dropTime, num) {
    this.relParam = relParam||'more_option';
    this.dropTime = dropTime||10;
    this.num = num;
}

CategoriesDropDown.prototype.move = function (ob, bup) {
    var self = this, i = 0, aLi, aB, t;
    aLi = ob.getElementsByTagName('li');
    aB = ob.getElementsByTagName('b');
    var up = function () {
        var b;
        if (aLi[i].style.display == 'block') {
            b = aLi[i].getElementsByTagName('b');
            if (typeof b[0] == 'undefined') {
                aLi[i].style.display = "none";
            }
        }
    }

    var down = function () {
        if (aLi[i].style.display == 'none') {
            aLi[i].style.display = "block";
        }
    }
    var slowDown = function () {
        down();
        i++;
        if (typeof aLi[i] != 'undefined') {
            if (self.dropTime) {
                t = setTimeout(function () {slowDown();}, self.dropTime);
            } else {
                slowDown();
            }
        } else {
            return false;
        }
        
    }
    var slowUp = function () {
        up();
        i--;
        if (i < 0) {
            return false;
        }
        if ((typeof aB[0] == 'undefined' && i > self.num - 1) || typeof aB[0] != 'undefined') {
            if (self.dropTime) {
                t = setTimeout(function () {slowUp();}, self.dropTime);
            } else {
                slowup();
            }
        } else {
            return false;
        }
    }
    if (bup) {
        if (self.dropTime) {
            for(i = 0, ln = aLi.length; i < ln; i++) {
                up();
            }
            return false;
        }
        i = aLi.length - 1;
        slowUp();
    } else {
        if (self.dropTime) {
            for(i = 0, ln = aLi.length; i < ln; i++) {
                down();
            }
            return false;
        }
        slowDown();
    }
}

CategoriesDropDown.prototype.initialize = function() {
    var link, rel, self = this;
    var onClickFunction = function (ob) {
        var ul;
        ul = ob.parentNode.parentNode;
        ul = ul.getElementsByTagName('UL')[0];
        self.move(ul, ob.more);
        if (ob.more) {
            ob.more = 0;
            ob.innerHTML = 'rozwiń &raquo';
            return false;
        }
        ob.innerHTML = 'zwiń &raquo';
        ob.more = 1;
        return false;
    }
    for (var i = 0, ln = document.links.length; i < ln; i++) {
        link = document.links[i];
        rel = link.getAttribute('rel')||0;
        if (rel == self.relParam) {
            link.more = 0;
            link.onclick = function () {
                var self = this;
                return onClickFunction(self);
            }
        }
    }
}

var categories = new CategoriesDropDown(0, 0, 10);
categories.initialize();

