	
	function floatMenu (InstanceName)
	{
	    this.instanceName = InstanceName;
	    var tmp = "this.closeThem = function () { for (var i = "+this.instanceName+".toClose.length - 1; "+this.instanceName+".toClose.length > 0 ; i = "+this.instanceName+".toClose.length - 1) {"+this.instanceName+".toClose[i].style.display = 'none';"+this.instanceName+".toClose[i].parentNode.ref.Open = false;"+this.instanceName+".toClose.pop();document.body.onclick = null;}}"
	   
	    eval (tmp);
	    
        this.mainUL = new Object();
        this.ulToCloseTimer = null;
        this.menuArray = new Array();
	   
	};
        
       
      floatMenu.prototype.toClose = new Array();
       
        
        //floatMenu.constructor.prototype.initialize = function () {alert (teste);  };
        //opções
        floatMenu.prototype.imgUp = "";
        floatMenu.prototype.imgDown = "";
	    floatMenu.prototype.enableClickOutToClose = false;
        floatMenu.prototype.enableCloseOthers = false;
        floatMenu.prototype.enableMouseOver = false;
	    floatMenu.prototype.enableMouseOutToClose = false;
	    floatMenu.prototype.defaultTimeOut = 250;
        //fim opções
         

        floatMenu.prototype.liOnMouseOver = function (e) {
                               if (!e) var e = window.event;
                               e.cancelBubble = true;
                               if (e.stopPropagation) e.stopPropagation();
                               this.code.openNode(this)
        }
        floatMenu.prototype.openNode = function (el){
                             if (el.code.ulToCloseTimer) clearTimeout(el.code.ulToCloseTimer);
                             el.parentNode.closeOthers(); 
                             el.ref.Open = true; 
                             el.ref.UL.style.display = "block"; 
                             
                             if (el.code.enableClickOutToClose){el.code.toClose.push(el.ref.UL); document.body.onclick = el.code.closeThem;} 
                             if (!el.ref.UL.loaded) el.code.refresh(el.ref);
        }
        
        
        floatMenu.prototype.closeOthers = function () {
                    if (arguments[0])
                       for (var i = 0; i < arguments[0].childNodes.length ; i ++) {
                           if (arguments[0].childNodes[i].ref) {
                              this.closeOthers(arguments[0].childNodes[i].ref.UL);
                              arguments[0].childNodes[i].ref.Open = false;
                              arguments[0].childNodes[i].ref.UL.style.display = 'none';   
                           }
                    }
                    else for (var i = 0; i < this.childNodes.length ; i ++) {
                            if (this.childNodes[i].ref) {
                               this.closeOthers(this.childNodes[i].ref.UL);
                               this.childNodes[i].ref.Open = false;
                               this.childNodes[i].ref.UL.style.display = 'none';   
                            }
                    }
        }

     
        
        floatMenu.prototype.liOnClick = function (e) { 
                                 if (!e) var e = window.event;
                                 e.cancelBubble = true;
                                 if (e.stopPropagation) e.stopPropagation();
                                 if(!this.ref.Open) {  this.code.openNode(this)  }
                                 else {
                                      this.ref.Open = false; 
                                      this.ref.UL.style.display = "none"; 
                                 } 
                                 if (!this.ref.UL.loaded) this.code.refresh(this.ref);
                              }

       floatMenu.prototype.listItem = function (obj, parent) {
                               this.Obj = obj;
                               this.Open = new Boolean();
                               this.Open = false;
                               this.Parent = parent;
                               this.Children = new Array();
                               this.UL = new Object();
                            }
        
       floatMenu.prototype.init = function (id) {
                               place = document.getElementById(id);
                               this.mainUL = document.createElement("UL");
                               this.mainUL.style.display = "block";
                               if (!this.enableCloseOthers) this.mainUL.closeOthers = function () {}
                               else this.mainUL.closeOthers = this.closeOthers;
                               place.appendChild(this.mainUL);
                               this.mainUL.code = this;
                               if (this.enableMouseOutToClose && this.enableMouseOver) 
                                  this.mainUL.onmouseout = function () {  
                                                              eval("this.code.ulToCloseTimer = setTimeout(function(){"+this.code.instanceName+".mainUL.closeOthers();},this.code.defaultTimeOut);");
                                                           }            
       }


       floatMenu.prototype.add = function (ul,parent,contents,tag) {
            li = document.createElement("LI");
            li.id = "LI_" + parent.Obj.id.replace('LI_','') + parent.Children.length;
            li.code = this;
            li.ref = new this.listItem(li,parent);
            if (this.imgDown.length == 0)  parent.Children.push(li.ref);
            else parent.insertBefore(parent.lastChild,li.ref);
            if (tag.Subs == 0) {
		li.innerHTML = "<div style=\"position:relative;float:left;\"><img src=\""+BaseURL+"images/bullet_menu_verde.gif\" border=\"0\"/>&nbsp;</div>";
                var a = document.createElement("A");
                a.href = "listaProduto.aspx?IDSite="+IDSite+"&IDCategoria=" + tag.CatID;
		a.innerHTML = contents;
                		
		//li.innerHTML = "<img src=\""+BaseURL+"images/bullet_menu_verde.gif\" border=\"0\"/>&nbsp;" + contents;
                //var a = document.createElement("A");
                //a.href = "listaProduto.aspx?IDSite="+IDSite+"&IDCategoria=" + tag.CatID;
                //a.innerHTML = "<img src=\""+BaseURL+"images/bullet_menu_verde.gif\" border=\"0\"/>&nbsp;" + contents;
                li.appendChild(a);
                li.onclick = function (e){        
                                if (!e) var e = window.event;
                                e.cancelBubble = true;
                                if (e.stopPropagation) e.stopPropagation();
				if (this.code.enableCloseOthers) this.parentNode.closeOthers(); 
                                if (this.code.ulToCloseTimer) clearTimeout(this.code.ulToCloseTimer);
                             }
                if (this.enableMouseOver) li.onmouseover = li.onclick

                if (parent.Children.length > 1) 
                    if (parent.Children[parent.Children.length - 2].Obj.className == "LiLast") 
			parent.Children[parent.Children.length - 2].Obj.className = "";
                    else parent.Children[parent.Children.length - 2].Obj.className = "LiMother";
                li.className = "LiLast";
            }
            else {
		li.innerHTML = "<div style=\"position:relative;float:left;\"><img src=\""+BaseURL+"images/bullet_menu_verde.gif\" border=\"0\"/>&nbsp;</div><a href=\"javascript:;\">" + contents + "<div class=\"LiMotherIMG\"><img  src=\""+BaseURL+"images/setBaixo.gif\" border=\"0\"/></div></a>";
               //li.innerHTML = "<img src=\""+BaseURL+"images/bullet_menu_verde.gif\" border=\"0\"/>&nbsp;" +contents+ "<div class=\"LiMotherIMG\"><img  src=\""+BaseURL+"images/setBaixo.gif\" border=\"0\"/></div>";
               li.onclick = this.liOnClick;
               if (this.enableMouseOver)
                  li.onmouseover = this.liOnMouseOver;
               if (parent.Children.length > 1) 
                  if (parent.Children[parent.Children.length - 2].Obj.className == "LiLast") 
                     parent.Children[parent.Children.length - 2].Obj.className = "";
                  else parent.Children[parent.Children.length - 2].Obj.className = "LiMother"
               li.className = "LiMotherLast";
            }                          
            ul.appendChild(li);
            ul = document.createElement("UL");
            ul.style.display = "none";
            ul.name = "sub";
            ul.tag = tag;
            if (this.imgUp){ 
                var img = document.createElement("img");
                img.src = this.imgUp;
                ul.appendChild(img);
            }
            if (this.imgDown) {
                var img = document.createElement("img");
                img.src = this.imgDown;
                ul.appendChild(img);
            }
            if (!this.enableCloseOthers) ul.closeOthers = function () {};
            else ul.closeOthers = this.closeOthers;
            li.appendChild(ul);
            li.ref.UL = ul;
        }
       
        floatMenu.prototype.addFirsts = function (contents,tag) {
            li = document.createElement("LI");
            li.id = "LI_" + this.menuArray.length;
            li.code = this;
            li.ref = new this.listItem(li,null);
            li.tag = tag;
            this.menuArray.push(li.ref);
            if (tag.Subs == 0) {
		li.innerHTML = "<div style=\"position:relative;float:left;\"><img src=\""+BaseURL+"images/bullet_menu_verde.gif\" border=\"0\"/>&nbsp;</div>";
                var a = document.createElement("A");
                a.href = "listaProduto.aspx?IDSite="+IDSite+"&IDCategoria=" + tag.CatID;
		a.innerHTML = contents;
                //a.innerHTML = "<img src=\""+BaseURL+"images/bullet_menu_verde.gif\" border=\"0\"/>&nbsp;" + contents;
                li.appendChild(a);
                li.onclick = function (e){        
                                       if (!e) var e = window.event;
                                       e.cancelBubble = true;
                                       if (e.stopPropagation) e.stopPropagation(); 
                                       if (this.code.enableCloseOthers) this.parentNode.closeOthers();
                                       this.parentNode.closeOthers(); 
                                       if (this.code.ulToCloseTimer) clearTimeout(this.code.ulToCloseTimer);
                             }   
                if (this.enableMouseOver) li.onmouseover = li.onclick
            }
            else {
               li.innerHTML = "<div style=\"position:relative;float:left;\"><img src=\""+BaseURL+"images/bullet_menu_verde.gif\" border=\"0\"/>&nbsp;</div><a href=\"javascript:;\">" + contents + "<div class=\"LiMotherIMG\"><img  src=\""+BaseURL+"images/setBaixo.gif\" border=\"0\"/></div></a>";
               li.onclick = this.liOnClick;
               if (this.enableMouseOver) li.onmouseover = this.liOnMouseOver;
               li.className = "LiMother";
            }
            this.mainUL.appendChild(li);
            ul = document.createElement("UL");
ul.setAttribute("style","z-index:1000;");
ul.style.zIndex= "1000";
            ul.name = "sub";
            ul.tag = tag;
            ul.style.display = "none";
            if (!this.enableCloseOthers) ul.closeOthers = function () {}
            else ul.closeOthers = this.closeOthers;
            li.appendChild(ul);
            li.ref.UL = ul;        
        }

        floatMenu.prototype.refresh = function (obj) {
            ul = obj.UL;
            if (obj.Children.length > 0) { 
                if (!obj.Open) ul.style.display = "none";
                else  ul.style.display = "";
                return;
            }
            this.getContents(obj);        
        }
                
        floatMenu.prototype.getContents = function(obj) {
             this.getAjaxCategoria('custom.aspx?IDSite='+IDSite+'&arquivo=GetCategoriaAjax.htm&IDCategoria='+obj.UL.tag.CatID,obj.UL.tag,obj,this);         
        }

        floatMenu.prototype.showLoading = function(obj) {
            li = document.createElement("LI");
            li.innerHTML = "Carregando";
            obj.appendChild(li);
        }

        floatMenu.prototype.removeLoading = function(obj) {   
            obj.removeChild(obj.firstChild);  
        }

        floatMenu.prototype.loadingText = function(obj,text) {
            obj.firstChild.innerHTML = text;
        }
        
        
        floatMenu.prototype.getAjaxCategoria = function (url,cat,obj,code) {       
            var xmlHttp = new ajax();
            this.showLoading(obj.UL);
            obj.UL.loaded = true; 
           
            xmlHttp.onreadystatechange=function() {
                switch(xmlHttp.readyState) {
                    case 0:
                    //Não Inicializado
                        break;
                    
                    case 1:
                        //Abrindo Conexão
                         code.loadingText(obj.UL,'Buscando...');
                            //     alert("l");
                        break;
                
                    case 2:
                        //Enviado
                        code.loadingText(obj.UL,"Enviado...");
                              //  alert("l");
                        break;
                
                    case 3:
                        //Recebendo
                        code.loadingText(obj.UL,"Recebendo...");
                              //  alert("l");
                        break;
                    case 4:
                         code.loadingText(obj.UL,"Montando...");
                              //   alert("l");
                        var ret = xmlHttp.responseText;
                        ret = ret.split("#LISTASUB#")[1];
                        if(ret)
                            var ret = ret.split("\n");
                        for (var i = 0; i < ret.length - 1; i ++) {
                            var cat = ret[i].split(",");
                            var tag = new Res(cat[0],cat[1],cat[2],cat[3],cat[4]);
                            code.add(obj.UL,obj,tag.Nome,tag);                             
                        }
                        code.removeLoading(obj.UL);
                        break;                
                }
            }        
            xmlHttp.open("GET",url,true);
            xmlHttp.send(null);         
        }
        
        floatMenu.prototype.dad = function (obj) {
            if (obj.parentNode.ref)
            return obj.parentNode.ref.Open;
            return true;
        }

        
        function Res() {
            this.CatID = arguments[0]
            this.Nome = arguments[1];
            this.Imagem = arguments[2];
            this.Subs = arguments[3];
            this.Prods = arguments[4];
        }

