function Button(title, css, onClick, settings) {
    this.html = new String();
    this.button = null;
    
    this.init = function () {
        // Генерира бутона
        
        this.button             = document.createElement('input');
        this.button.type        = 'button';
        this.button.value       = title;
        this.button.className   = css;
        this.button.onclick     = onClick;
        
        if (settings)
            for (var pr in settings) {
                this.button[pr] = settings[pr];
            }
    }
    
    this.get = function () {
        return this.button;
    }
    
    this.init();
}


function DropDownOption(text, value, onClick, css) {
    this.html = new String();
    this.opt = null;
    this.option = null;
    
    this.init = function () {
        var a = document.createElement('a');
        
        this.opt = document.createElement('li');
        this.opt.v = value;
        this.opt.t = text;
        
        a.appendChild(document.createTextNode(text));
        
        this.opt.onclick = onClick;
        if (css) a.className = css;
        
        this.opt.appendChild(a);
    }
    
    this.getValue = function () {
        return ;
    }
    
     this.getText = function () {
        return text;
     }
    
    this.get = function () {
        return this.opt;
    }
    
    this.init();
}



function DropDown(title, css, settings) {
    var oThis = this;
    
    this.html = new String();
    this.menu = null;
    this.drop_cont = null;
    this.title_a = null;
    this.options =  null;
    
    this.selectOption = function (event, value, text) {
        this.menu.getElementsByTagName('input')[0].value = value;
        this.title_a.innerHTML = text;
        this.toggleMenu(event);
        document.onclick = function () {};
    }
    
    this.getSelected = function () {
        return this.menu.getElementsByTagName('input')[0].value = value;
    }
    
    this.setOptions = function (options) {
        this.options = options;
    }
    
    this.addOption = function (text, value, onClick, css) {
        var opt = new DropDownOption(text, value, onClick, css);
        
        this.drop_cont.getElementsByTagName('ul')[0].appendChild(opt.get());
    }
    
    this.addElements = function (add_elements) {
        if (add_elements)
            for(var i=0; i<add_elements.length; i++) this.drop_cont.appendChild(add_elements[i]);
    }
    
    this.init = function () {
        if(!this.menu) {
            this.menu = document.createElement('div');
            this.menu.className = css;
            this.drop_cont = document.createElement('div'),
            this.drop_wraper = document.createElement('div'),
            this.title_a = document.createElement('a');
            this.drop_menu = document.createElement('ul')
            !this.options && (this.options = new Array());
            
            
            var title_cont  = document.createElement('div'),
                hidden      = document.createElement('input');
            
            title_cont.className = 'dropdown-title';
            
            this.title_a.onclick = function (event) { oThis.toggleMenu(event); }
            title_cont.appendChild(this.title_a);
            
            this.drop_wraper.className = 'dropdown-wrap';
            this.drop_wraper.appendChild(this.drop_menu);
            
            this.drop_cont.className = 'dropdown-menu';
            this.drop_cont.style.display = 'none';
            this.drop_cont.appendChild(this.drop_wraper);
            
            hidden.type = 'hidden';
            
            this.menu.appendChild(hidden);
            this.menu.appendChild(title_cont);
            this.menu.appendChild(this.drop_cont);
        }
        
        this.title_a.innerHTML = '';
        this.drop_menu.innerHTML = '';
        
        this.title_a.appendChild(document.createTextNode(title));
        
        for(var i=0; i<this.options.length; i++) {
            this.drop_menu.appendChild(this.options[i].get());
        }
    }
    
    this.getValue = function () {
        return this.menu.getElementsByTagName('input')[0].value;
    }
    
    this.getText = function () {
        return this.title_a.innerHTML;
    }
    
    this.get = function () {
        return this.menu;
    }
    
    this.toggleMenu = function (e) {
        if (!e) e = window.event;
        
        if (e) {
            if (e.stopPropagation) e.stopPropagation();
            e.cancelBubble = true;
        }
        
        if (this.drop_cont.style.display == 'none') {
            this.handle_onclick();
            this.title_a.className = 'sel';
            this.drop_cont.style.display = 'block';
        } else {
            this.title_a.className = '';
            this.drop_cont.style.display = 'none';
        }
    }
    
    this.handle_onclick = function (event) {
        
        this.drop_cont.onclick = function (e) {
            if (!e) e = window.event;
            
            if (e.stopPropagation) e.stopPropagation();
            e.cancelBubble = true;
        }
        
        document.onclick = function (e) {
            var targ;
            
            if (!e) e = window.event;
            
            if (e.target) targ = e.target;
            else if (e.srcElement) targ = e.srcElement;
            if (targ.nodeType == 3) // defeat Safari bug
                targ = targ.parentNode;
            
            
            if (targ && targ.tagName == 'INPUT') {
                // IE бъг, пуска ми този евент като натисна ENTER в INPUT поле, мноо е прост :)
                return;
            }
            
            var rightclick = false;
            
            if (e.which) rightclick = (e.which == 3);
            else if (e.button) rightclick = (e.button == 2);
            
            if (rightclick) return;
            
            oThis.toggleMenu(e);
            document.onclick = function (){};
        }
        return false;
    }
}