/* DON'T EDIT THIS GENERATED FILE! Changes will be lost. */

window.addOnload = function() {}
function dynLib() {
    getChildElements = function(root, nodeNames) {
        var result = [];
        if (isNone(nodeNames))        { nodeNames = '*'; }
        else if (!isArray(nodeNames)) { nodeNames = [nodeNames]; }
        for (var i=0; i<root.childNodes.length; i++) {
            if (root.childNodes[i].nodeType == 1) {
                if (nodeNames=='*' || nodeNames.hasValue(root.childNodes[i].nodeName.toLowerCase())) {
                    result.push(root.childNodes[i]);
                }
            }
        }
        return result;
    }
    hasClassName = function(obj, className) {
        return obj.className.split(' ').hasValue(className);
    }
    addClassName = function(obj, className) {
        if (!hasClassName(obj, className)) {
           obj.className = obj.className + ' ' + className; 
        }
    }
    delClassName = function(obj, className) {
        if (obj.className.indexOf(className) != -1) {
            var classNames = obj.className.split(' ');
            classNames.removeValue(className);
            obj.className = classNames.join(' ');
        }
    }
    setActiveListItem = function(item) {
        var list  = item.parentNode;
        var items = getChildElements(list, 'li');
        for (var i=0; i<items.length; i++) {
            var inps = items[i].getElementsByTagName('input');
            if (inps.length && inps[0].type.toLowerCase()=='radio') {
                inps[0].checked = items[i]==item ? true : false;
            }
            if (items[i] != item) {
                delClassName(items[i], 'active');
            }
        }
        addClassName(item, 'active');
    }
    EventHandler = function(obj, events) {
        this._object     = obj;
        this._events     = new Object();
        this._registered = new Array(); 
        this.registerEvent = function(eName) {
            eName = this.normalizeEventName(eName, true);
            if (!this._registered.hasValue(eName.toLowerCase())) {
                this._registered.push(eName.toLowerCase());
                this['add'+eName]     = new Function('func', "this.addEvent('"+eName+"', func)").bind(this);
                this['remove'+eName]  = new Function('func', "this.removeEvent('"+eName+"', func)").bind(this);
                this['get'+eName+'s'] = new Function('',     "this.getEvents('"+eName+"')").bind(this);
                this['run'+eName+'s'] = new Function('e',    "return this.runEvents('"+eName+"', e)").bind(this);
                this._object['add'+eName]    = this['add'+eName];
                this._object['remove'+eName] = this['remove'+eName];
                this._events[eName.toLowerCase()] = new Array();
                if (isSet(this._object[eName.toLowerCase()])) {
                    this['add'+eName](this._object[eName.toLowerCase()].bind(this._object));
                }
                this._object[eName.toLowerCase()] = this['run'+eName+'s'];
            }
        }
        this.normalizeEventName = function(eName, ucfirst) {
            eName = ((eName.substring(0, 2).toLowerCase() == 'on' ? '' : 'on') + eName).toLowerCase();
            return ucfirst ? eName.substring(0,1).toUpperCase()+eName.substr(1) : eName;
        }
        this.getEvents = function(eName) {
            eName = this.normalizeEventName(eName);
            return this._events[eName];
        }
        this.addEvent = function(eName, func) {
            eName = this.normalizeEventName(eName);
            this._events[eName].push(func);
        }
        this.removeEvent = function(eName, func) {
            eName = this.normalizeEventName(eName);
            if (this._events[eName].hasValue(func)) {
                this._events[eName].remove(func);
            }
        }
        this.runEvents = function(eName, e) {
            var events = this.getEvents(eName);
            var result = true;
            for (var i=0; i<events.length; i++) {
                var func = events[i];
                var temp;
                if (isFunction(func)) {
                    temp = func(e);
                } else if (isString(func)) {
                    temp = eval(func);
                }
                if (temp === false) { result = false; }
            }
            return result;
        }
        this.unload = function() {
            for (var r=0; r<this._registered.length; r++) {
                var name = this._registered[r];
                for (var e=0; e<this._events[name].length; e++) {
                    this._events[name][e] = null;
                }
                this._events[name]  = null;
                this._registered[r] = null;
                this._object[name]  = null;
                this._object.registerEvent = null;
                this._object['add'+name.ucfirst()]    = null;
                this._object['remove'+name.ucfirst()] = null;
            }
        }
        if (!isArray(events)) {
            events = new Array('load', 'change', 'keydown');
        }
        for (var i=0; i<events.length; i++) {
            this.registerEvent(events[i]);
        }
        this._object.registerEvent = this.registerEvent.bind(this);
        GC.add(this);
    }
    new EventHandler(window, ['load', 'unload']);
    Tooltip = function(obj) {
        this.object  = obj;
        this.tooltip = obj.getAttribute ? obj.getAttribute('title') : obj.title;
        obj.title    = '';
        this.timeout = 300;
        this.timer   = null;
        this.show = function(e) {
            document.addOnmousemove(this.setPosition.bindAsEventListener(this));
            this.setPosition(e);
            this.timer = window.setTimeout(function() { this.object.tooltipElement.style.display = 'block'; }.bind(this), this.timeout);
        }
        this.hide = function() {
            document.removeOnmousemove(this.setPosition.bind(this));
            if (this.timer) { window.clearTimeout(this.timer); }
            this.object.tooltipElement.style.display = 'none';
        }
        this.setPosition = function(e) {
            if (isNone(e) && isNone(window.event)) { return; }
            var x = window.event ? window.event.clientX + document.documentElement.scrollLeft : e.pageX;
            var y = window.event ? window.event.clientY + document.documentElement.scrollTop  : e.pageY;
            this.object.tooltipElement.style.left = (x+18) + 'px';
            this.object.tooltipElement.style.top  = (y+12) + 'px';
        }
        this.unload = function() {
            this.object.tooltipElement = null;
            this.object.tooltip        = null;
            this.object                = null;
        }
        var className = 'tooltip';
        var html      = this.tooltip.toHtml();
        if (html.length < 30) { className += ' littlecontent'; }
        obj.tooltipElement = newElement('div', {'class':className}, html);
        var body = document.getElementsByTagName('body')[0];
        body.insertBefore(obj.tooltipElement, body.firstChild);
        new EventHandler(obj, new Array('mouseover', 'mouseout', 'click'));
        obj.addOnmouseover(this.show.bind(this));
        obj.addOnmouseout(this.hide.bind(this));
        obj.addOnclick(this.hide.bind(this));
        GC.add(this);
    }
    new EventHandler(document, new Array('mousemove'));
    checkForTooltips = function(els) {
        for (var i=0; i<els.length; i++) {
            if (els[i].getAttribute('title')) {
                els[i].tooltip = new Tooltip(els[i]);
            }
        }
    }
    initTooltips = function(baseElement) {
        var els = new Array(
            'a', 'abbr', 'acronym', 'address', 'blockquote', 'button', 'caption', 'cite', 'code',
            'col', 'colgroup', 'dd', 'del', 'dfn', 'div', 'dl', 'dt', 'em', 'fieldset', 'form',
            'h1', 'h2', 'h3', 'h4', 'h5', 'h6',  'hr', 'img', 'input', 'ins', 'kbd', 'label', 'legend',
            'li', 'object', 'ol', 'optgroup', 'option', 'p', 'q', 'samp', 'select', 'span', 'strong',
            'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'tr', 'ul', 'var'
        );
        for (var i=0; i<els.length; i++) {
            checkForTooltips(baseElement.getElementsByTagName(els[i]));
        }
    }
    jsLoaded('dynLib.js');
}

requires('prototype.js', dynLib);
