﻿    
	function Menu(container, event){    
        var that = this;
        this.container = container;
        this.event = event;
        this.timeoutId = 0;
        this.elements = new Array();
        
        this.add = function(element){
            this.elements.push(element);
        }
        
        this.div = document.createElement("div");
        
        
        this.init = function(){
            container.style.cursor = "pointer";    
            that.div.style.display = "none";
            that.div.style.position = "";
            
            
            container.appendChild(that.div);
            for (var i=0;i<that.elements.length;i++){
                var element = that.elements[i];
                element.draw(that.div);
            }
        }
        
			this.draw = function(){
            if (that.div.style.display=="block"){
                that.div.style.display = "none";
            } else {
                that.div.style.display = "block";
            }
        }

        
        this.clear = function(){        
            that.timeoutId = setTimeout(function(){that.div.style.display = "none"},300);
        }
        
        if (event=='onclick'){
            container.onclick = this.draw;
            //container.onmouseout = this.clear;
            //this.div.onmouseover = function(){clearTimeout(that.timeoutId)};
        } else if (event=='onmouseover') {
            container.onmouseover = this.draw;
            container.onmouseout = this.clear;
        }
    }
    
    function Element(text, url){
        this.text = text;
        this.url = url;

		
        this.draw = function(container){
            var el = document.createElement("div");
			el.className="li_item"; 
            with(el .style){
                paddingTop = "-20px;"
				border = "1px solid blue";
                backgroundColor = "white";
                width= "220px";
                height = "30px";
                marginTop = "10px";
				
            } 
			
            var a = document.createElement("a");
            a.href=this.url;
            a.innerHTML = text;
            el.appendChild(a);
            container.appendChild(el);
        }
    }
    
    function createMenu(){
        var menu = new Menu(document.getElementById('BLABLA100'),"onclick");        
        var el1 = new Element("150freedolars","http://150freedolars.ru");
        var el2 = new Element("150freedolars","http://150freedolars.ru");
        var el3 = new Element("150freedolars","http://150freedolars.ru");
        var el4 = new Element("sex","http://sex.ru");    
        menu.add(el1);
        menu.add(el2);
        menu.add(el3);
        menu.add(el4);
        menu.init();
        
        var menu2 = new Menu(document.getElementById('BLABLA200'),"onclick");        
        menu2.add(new Element("150freedolars","http://150freedolars.ru"));
        menu2.add(new Element("150freedolars","http://150freedolars.ru"));
        menu2.add(new Element("йцуйцу","http://ya.ru"));
        menu2.add(new Element("йцуйцу","http://ya.ru"));
        
        menu2.init();
    
    
    }
