var Slider = function() {};
Slider.prototype = {
    last: false,
    display: false,
    hide: false,
    pixels: 7,
    interval: 8,
    slide_down: function () {
        if(!this.display) return;
        var slider = this;
        if(this.display.style.display=='none')
            this.display.style.display =
(this.display.tagName.match(/^LI$/i))?'list-item':'block';
        var height = this.display.style.height;
        height = height.substring(0, height.length-2);
        height = new Number(height);
        height = height + this.pixels;
        if(height>this.display.scrollHeight)
height=this.display.scrollHeight;
        this.display.style.height=height+"px";
        if(height<this.display.scrollHeight) {
            setTimeout(function() {slider.slide_down();}, this.interval);
        } else {
            this.last=this.display;
            this.display=false;
        }
    },
    slide_up: function() {
        if(!this.hide) return;
        var slider = this;
        var height = this.hide.style.height;
        height = height.substring(0, height.length-2);
        height = new Number(height);
        height = height - this.pixels;
        if(height<0) height=0;
        this.hide.style.height=height+"px";
        if(height>0) {
            setTimeout(function() {slider.slide_up();}, this.interval);
        } else {
            this.hide.style.display = 'none';
            this.hide=false;
        }
    },
    toggle: function (obj) {
        if(this.display||this.hide) return;
        if(typeof obj == 'string')
            obj = document.getElementById(obj);
        if(!obj || obj.nodeType!=1)
            return;
        if(obj.style.height=='0px') {
            this.display=obj;
            if(!this.last) {
                this.hide=false;
            } else {
                this.hide=this.last;
            }
            this.slide_down();
            this.slide_up();
        } else {
            if(obj==this.last) {
                this.hide=obj;
                this.slide_up();
            }
        }
    },
    add_event: function (el, evname, func) {
        if (el.attachEvent) { // IE
            el.attachEvent("on" + evname, func);
        } else if (el.addEventListener) { // Gecko / W3C
            el.addEventListener(evname, func, true);
        } else {
            el["on" + evname] = func;
        }
    },
    add: function (source, target, action) { //click, over
        if(action!='click' && action!='over') action = 'click';
        var slider = this;
        this.add_event(window, 'load', function() {
            if(typeof source == 'string')
                source = document.getElementById(source);
            if(typeof target == 'string')
                target = document.getElementById(target);
            if(!source || source.nodeType!=1 || !target ||
target.nodeType!=1)
                return false;
            if(action=='over') {
                slider.add_event(source, 'mouseover', function()
{if(target.style.height=='0px') slider.toggle(target);});
            } else {
                slider.add_event(source, 'click', function()
{slider.toggle(target);});
            }
            target.style.height = '0px';
            target.style.overflow = 'hidden';
            target.style.display = 'none';
        });
    }
};


