	function xmenuMenu(parent, width, height, closebutton, createmask) {		
		var o = this;
		this.quisoc = "xmenuMenu";
		this.showitemstimer;
		this.hideitemstimer;
		this.activemenu;
		this.child;

		this.hideTimer;
		this.xStep = 1;
		this.minHeight = 0;
		this.Potencia = 5;
		this.xStart = -100;
		this.Width;
		this.Height = 0;
		this.x = 0;
		this.parent = parent;
		
		this.activesubmenu = null;
		
		this.amagat = false;
		
		this.groupcount = 0;
		this.groups = Array();
		
		this.addGroup = xmenuMenuaddgroup;
		this.switchto = xmenuMenuswitchto;
		this.switchstate = xmenuMenuswitchstate;
		this.openmenu = xmenuMenuopenmenu;
		this.closemenu = xmenuMenuclosemenu;
		this.quickclose = xmenuMenuquickclose;
		this.setMinHeight = xmenuMenusetminheight;
		this.expand = xmenuMenuexpand;
		this.ancla = xmenuMenuAncla();

		if(ie) { window.attachEvent("onresize", xmenuMenuAncla) };
				
		menudiv = document.createElement("div");

		if(height) {
			this.Height = height;
			menudiv.style.height = height + "px";
		}
		
		if(width) {
			this.Width = width;
			menudiv.style.width = width + "px";
		}
		
		menudiv.className = "xmenu";
		parent.appendChild(menudiv);

		if(createmask) {
			menudiv.style.position = "absolute";
			menudiv.style.left = getleftpos(parent);
			menudiv.style.top = gettoppos(parent);
			
			mask = document.createElement("div");
			mask.style.position = "absolute";
			mask.className = "xmenumask";
			mask.style.width = width + "px";
			mask.style.height = height + "px";
			mask.style.top = gettoppos(menudiv);
			mask.style.left = getleftpos(menudiv);
			menudiv.style.zIndex++;
			mask.style.zIndex = menudiv.style.zIndex - 1;
			parent.appendChild(mask);
			this.mask = mask;
		}
		
		if(closebutton) {
			closediv = document.createElement("div");
			closediv.innerHTML = closedivcaption(this.amagat);
			closediv.onclick = function() { o.switchstate(); }
			menudiv.appendChild(closediv);
			this.closediv = closediv;
		}

		this.div = menudiv;
		xmenuMenuAncla();
				
		function xmenuMenuaddgroup(caption, enabled) {
			
			grup = new xmenuGrup(caption, this, enabled);
			this.groups[this.groupcount] = grup;	
			this.groupcount++;
			x = new xmenuMenu(this.div);
			x.div.style.height = "0px";
			x.amagat = true;
			grup.setmenu(x);
			return x;
		}
		
		function xmenuMenuswitchto(grup) {
			for(i=0; i<this.groupcount; i++) {
				m = this.groups[i].childmenu;
				m.closemenu();
				if(m.activemenu) {
					m.activemenu.closesubmenu();
				}
			}
			
			if(!this.amagat) {
			 	grup.childmenu.openmenu();
		   	}
		}
		
		function xmenuMenuopenmenu() {
			if(this.amagat) {
				this.switchstate();
			}
		}
		
		function xmenuMenuclosemenu() {
		  if(!this.amagat) {
				this.switchstate();
			}
		}
		
		function xmenuMenusetminheight(h) {
			this.minHeight = h;
		}

		function xmenuMenuexpand() {
			this.div.style.height = this.Height + "px";
			this.amagat = false;
		}
		
		function xmenuMenuquickclose() {
			this.amagat = true;
			this.div.style.height = this.minHeight + "px";
			if(this.mask) {
				this.mask.style.height = this.minHeight + "px";
			}
			if(this.closediv) {
				this.closediv.innerHTML = closedivcaption(this.amagat);
			}	
		}
		
		function xmenuMenuswitchstate() {
			if(!this.amagat) {
				m = this;
			}
			if(this.activesubmenu) {
				this.activesubmenu.closesubmenu();
			}
				
			if(!this.Height) {
				this.Height = this.div.offsetHeight;
			}
			this.x = this.xStart;
			this.amagat = !this.amagat;
			clearInterval(this.hideTimer);
			var o = this;
			if(this.closediv) {
				this.closediv.innerHTML = closedivcaption(this.amagat);
			}	
			this.hideTimer = setInterval(function() { xmenuMenutimer(o); }, 5);
	 	}
		
		function xmenuMenutimer(obj) {

    		obj.x+=obj.xStep;
    		y = Math.pow(obj.x, obj.Potencia);
    	
    		mH = (y*obj.Height);
    		mH = mH / Math.pow(obj.xStart, obj.Potencia);
			mH = Math.abs(mH) + obj.minHeight;

    		if(!obj.amagat) { 
				mH = (obj.Height - mH) + obj.minHeight;
			}
			if(obj.mask) {
				obj.mask.style.height = mH + "px";
			}
			obj.div.style.height = mH+ "px";
			if(obj.x>=0) { 
				clearInterval(obj.hideTimer); 
				obj.x = obj.Start*-1;
			}
    	}	

		function xmenuMenuAncla() {
			if(o.parent) {
				l = getleftpos(o.parent) + "px"; 
				t = gettoppos(o.parent) + "px";
				if(o.div) { o.div.style.left = l; 
							o.div.style.top = t; 
				}
				if(o.mask) { o.mask.style.left = l; 
							o.mask.style.top = t;
				}
			}
		}

	}
	function xmenuGrup(caption, parent, enabled) {

		var o = this;

		this.div = null;
		this.childmenu = null;
		this.parent = parent;
		this.ndx;
		
		this.setmenu = xmenuGrupsetmenu;
		
		div = document.createElement("div");
		div.innerHTML = caption;
		div.className = "xmenuGrup";
		parent.div.appendChild(div);
		this.ndx = parent.groupcount;
		
		this.div = div;
		if(!enabled) {
			this.div.onclick = function() { o.parent.switchto(o) }
			this.div.onmouseover = function() { xmenuGrupmousemove(o); }
			this.div.onmouseout = function() { xmenuGrupmouseout(o); }
		}
		
		function xmenuGrupsetmenu(menu) {
			this.childmenu = menu;
		}	
		
		function xmenuGrupmousemove(obj) {
			obj.div.className = "xmenuGrupHover";
		}
		
		function xmenuGrupmouseout(obj) {
			obj.div.className = "xmenuGrup";
		}
	}
	function xmenuItem(caption, parent, url, img, img1, target) {		
	
		var div = null;
		var o = this;
		
		this.quisoc = "menuItem";
		this.child;
		this.submenu = null;	
		this.trow = null;
		this.tsel = null;
		this.setsubmenu = xmenuItemsetsubmenu;		
		this.pnt = false;
		this.img = null;
		this.img1 = null;
		this.imgsubmenu = null;
		this.imgsubmenu1 = null;
		this.imgsubmenuact = false;
		this.mouseout = xmenuItemmouseout;

		this.margeInferior = xmenuItemMargeInferior;
		
		if(img) { 	
			this.img = new Image;
			this.img.src = img; 
		}
				
		if(img1) { 	
			this.img1 = new Image;
			this.img1.src = img1; 
		}
		
		this.imgsubmenu = new Image;
		this.imgsubmenu.src = "http://www.augassantas.es/img/xmenu_submenu.gif";
		this.imgsubmenu1 = new Image;
		this.imgsubmenu1.src = "http://www.augassantas.es/img/xmenu_submenu1.gif";
		
		parent.child = this;
		
		this.pnt = true;
		if(this.img) {
			this.pnt = false;
		}
		

		div = document.createElement("div");
		div.style.width = "90%";
		//div.style.height = "15px";
		this.trow = xmenuItemcreatecaption(caption, url, div, img, this.pnt, target);

		div.onmouseover = function() { xmenuItemonmousemove(o, div); }
		div.onmouseout = function() { xmenuItemmouseout(o, div); }
		
		div.className = "xmenuItem";
		parent.div.appendChild(div);
		
		this.div = div;
		parent.Height += div.offsetHeight;
		
		function xmenuItemonmousemove(obj, div) {
			div.className = "xmenuItemHover";
			clearTimeout(parent.showitemstimer);
			parent.showitemstimer = setTimeout(function() { xmenuItemtimeout(obj); }, 500);
			if(obj.pnt) {
				td = obj.trow.getElementsByTagName("td")[0];
				td.style.visibility = "visible";
			}
			
			if(obj.img && obj.img1) {
				img = obj.trow.getElementsByTagName("img")[0];
				img.src = obj.img1.src;
			}
			
			if(obj.submenu) {
				img = obj.trow.getElementsByTagName("img")[2];
				
				if(obj.submenu.amagat && !obj.imgsubmenuact) {
					img.src = obj.imgsubmenu1.src;
					obj.imgsubmenuact = false;
				} else {
					img.src = obj.imgsubmenu.src;
				}
				img.style.visibility = "visible";
				
			}
		}
		
		function xmenuItemmouseout(obj, div) {
			
			if(obj.submenu) {
				if(!obj.submenu.amagat) {
					return;
				}
			}
			div.className = "xmenuItem";

			clearTimeout(parent.showitemstimer);
			if(obj.pnt) {
				td = obj.trow.getElementsByTagName("td")[0];
				td.style.visibility = "hidden";
			}

			if(obj.img && obj.img1) {
				img = obj.trow.getElementsByTagName("img")[0];
				img.src = obj.img.src;
			}

			if(obj.submenu) {
				img = obj.trow.getElementsByTagName("img")[2];
				img.style.visibility = "hidden";
			}
			
		}
		
		function xmenuItemtimeout(obj) {
			clearTimeout(parent.showitemstimer);
			if(parent.activemenu) {
				if(parent.activemenu != obj.submenu) {
					parent.activemenu.closesubmenu();
				}
			}
			
			if(obj.submenu) {
				obj.submenu.opensubmenu();
				img = obj.trow.getElementsByTagName("img")[2];
				if(obj.imgsubmenu) img.src = obj.imgsubmenu.src;
				
				parent.activemenu = obj.submenu;
			} else {
				parent.activemenu = null;
			}
		}
		
		function xmenuItemsetsubmenu() {
			tcl = document.createElement("td");
			tcl.innerHTML = "<img src='http://www.augassantas.es/img/xmenu_submenu.gif' style='visibility:hidden; margin-top:3px'>";
			this.trow.appendChild(tcl);
			this.pnt = false;
			
		}
		
		function xmenuItemcreatecaption(caption, url, div, img, pnt, target) {
			tbl = document.createElement("table");
			tbl.className = "xmenuItem";
			tbd = document.createElement("tbody"); tbl.appendChild(tbd);
			trw = document.createElement("tr"); tbd.appendChild(trw);
			
			tdpnt = document.createElement("td"); 
			trw.appendChild(tdpnt);
			tdpnt.innerHTML = "<img src='http://www.augassantas.es/img/xmenu_punt.gif' style='margin-top:2px'>";
			tdpnt.style.visibility = "hidden";
			tdpnt.style.display="none";
			if(pnt) tdpnt.style.display="inline";

			tdimg = document.createElement("td");
			trw.appendChild(tdimg);
			tdimg.innerHTML = "<img src='"+img+"' style='margin: 1px 3px 0px 0px'>";
			tdimg.style.display = "none";
			if(img) tdimg.style.display="inline";

			tcl = document.createElement("td"); trw.appendChild(tcl);
			tcl.setAttribute("width", "100%");
			tbl.setAttribute("border", "0");
			tbl.setAttribute("cellPadding", "2");
			tbl.setAttribute("cellSpacing", "0");
			if(url) {
				(target)?htmltarget=" target='"+target+"' ":htmltarget="";
				caption = "<a href='"+url+"' class='xmenulink' " + htmltarget + ">"+caption+"</a>";
			}
			tcl.innerHTML = caption;
			div.appendChild(tbl);
			return trw;
		}
		
		function xmenuItemMargeInferior(marge) {
			o.div.style.paddingBottom = marge;	
		}
	}
	

	function xmenuSubMenu(caption, parent, root) {

		var o = this;
		var offset = 5;

		this.child;		
		this.div = null;
		this.mask = null;
		this.timer = null;
		this.quisoc = "submenu";
		this.caption = caption;
		this.root = root;
		this.amagat = true;
		
		parent.child = this;
		
		this.setDescripcio = xmenuSubMenusetDescripcio;
		
		this.opensubmenu = xmenuSubMenuopensubmenu;
		this.closesubmenu = xmenuSubMenuclosesubmenu;
		
		div = document.createElement("div");
		div.className = "xmenu xsubmenu";
		div.innerHTML = createitemcaption(caption, false);

		if(ie) {
			window.attachEvent("onresize", xmenuSubMenuAncla)
		} else {
			window.addEventListener("resize", xmenuSubMenuAncla, true);
		}

		div.style.visibility="hidden";
		div.style.position = "absolute";
		if(ie) { 
			div.style.width  = root.div.offsetWidth; 
			div.style.height = root.div.offsetHeight;	
		} else {
			div.style.width = root.div.style.width;
			div.style.height = root.div.style.height;
		}
		
		div.style.filter = "progid:DXImageTransform.Microsoft.Fade(duration=0.2)";
		div.onmouseout = function() { xmenuSubMenumouseout(o); }
		div.onmouseover = function() { clearTimeout(o.timer); }

		parent.submenu = o;
		parent.setsubmenu();
		
		mask = document.createElement("div");
		mask.style.position = "absolute";
		mask.style.visibility = "hidden";
		mask.className = "xmenumask";

		root.parent.appendChild(div);
		root.parent.appendChild(mask);		

		this.div = div;
		this.mask = mask;

		function xmenuSubMenumouseout(o) {		
			o.timer = setTimeout(function() { o.closesubmenu() }, 1000);
		}

		
		function xmenuSubMenusetDescripcio(desc) {
			div.innerHTML = desc;
		}
		
		function xmenuSubMenuopensubmenu() {
			if(!this.amagat) {
				return;
			}
				  
			this.root.activesubmenu = this;
			
			this.div.style.left = getleftpos(root.div) + root.div.offsetWidth + offset + "px";
			this.div.style.top = root.div.offsetTop + "px";
			this.div.style.zIndex++;

			
			if(ie) { this.div.filters[0].apply(); }
		  	this.div.style.height = this.root.div.offsetHeight + "px";
			this.mask.style.left = this.div.style.left;
			this.mask.style.top = this.div.style.top;
			this.mask.style.width = this.div.style.width;
			this.mask.style.height = this.div.style.height;
			this.mask.style.zIndex = this.div.style.zIndex-1;

			this.mask.style.visibility = "visible";
			this.div.style.visibility = "visible";
			if(ie) {this.div.filters[0].play(); }
			this.amagat = false;
		}
		
		function xmenuSubMenuclosesubmenu() {
			if(this.amagat) {
				return;
			}
			
			root.activesubmenu = null;
			if(ie) { this.div.filters[0].apply(); }
			this.div.style.visibility = "hidden";
			this.mask.style.visibility = "hidden";
			if(ie) { this.div.filters[0].play(); }
			this.amagat = true;
			
			parent.mouseout(parent, parent.div);

		}
		
		function xmenuSubMenuAncla() {
			o.div.style.left = getleftpos(root.div) + root.div.offsetWidth + offset + "px";
			o.div.style.top = root.div.offsetTop + "px";
			o.mask.style.left = o.div.style.left;
			o.mask.style.top = parseInt(o.div.style.top) + "px";
		}
	}
	
	function xmenuContainer(parent, height) {
		
		this.child;
		this.menu;
	 	this.foot;
		this.quisoc = "container";
		parent.child = this;
	 
		maindiv = document.createElement("div");
	 	 
		table   = document.createElement("table");
		tbody   = document.createElement("tbody"); table.appendChild(tbody);
		trow1   = document.createElement("tr");    tbody.appendChild(trow1);
		tcell1  = document.createElement("td");    trow1.appendChild(tcell1);
		trow2   = document.createElement("tr");    tbody.appendChild(trow2);
		tcell2  = document.createElement("td");    trow2.appendChild(tcell2);
		 
		table.className = "xmenu";
		table.setAttribute("border", "0");
		table.setAttribute("cellPadding", "0");
		table.setAttribute("cellSpacing", "0");
		table.setAttribute("height", height);
		table.setAttribute("width", "92%");
		tcell1.setAttribute("height", "99%");
		tcell2.setAttribute("height", "1%");
		tcell1.setAttribute("vAlign", "top");
		maindiv.appendChild(table);
   
		parent.div.appendChild(maindiv);
		 
		this.menu = tcell1;
		this.foot = tcell2;
		this.div = maindiv;
	 
  }

	function closedivcaption(amagat) {
		if(amagat) {
			img = "http://www.augassantas.es/img/xmenu_open.gif";
			return "<table width='165'><tr><td><b>Menú</b><td><td align='right'><img src='"+img+"'></td></tr></table>";
		}
		img = "http://www.augassantas.es/img/xmenu_close.gif";
		return "<table width='165'><tr><td><b>&nbsp;</b><td><td align='right'><img src='"+img+"'></td></tr></table>";
	}

	function createitemcaption(caption, submenu, img) {
		if(caption!="") {
			txt = "<table border='0' cellpaddin='0' cellspacing='0' class='xsubmenudesc'><tr><td>";
			txt += caption;
			txt += "</td></tr>";
			txt += "<tr><td height='8' background='img/xmenu_desc.gif'></td></tr><table>";
		} else {
			txt = "";
		}
		return txt;
	}
	
	function getleftpos(itm) {
		var l = 0;
		while(itm != null)	{
			l += itm.offsetLeft;
			itm = itm.offsetParent;
		}	
		return l;
	}
	
	function gettoppos(itm) {
		var t = 0;
		while(itm != null) {
			t += itm.offsetTop;
			itm = itm.offsetParent;
		}
		return t;
	}