var esmart = {
	timeout: undefined,
	shadediv: undefined,
	shadow: function(id) {
			var div = document.getElementById(id);
			var html = div.innerHTML;
			
			var shade = document.createElement('DIV');
			shade.innerHTML=html;
			shade.style.position='absolute';
			shade.style.marginLeft='1px';
			shade.style.marginTop='-1px';
			
			var els = div.getElementsByTagName('A');
			for (var i=0;i<els.length;i++) {
				els[i].style.color='#666666';
				els[i].onmouseover=null;
			}

			div.insertBefore(shade,div.childNodes[0]);
		},
	getpos: function(obj) {
			var x=y=0;
			if (obj.offsetParent) {
				do {
					x += obj.offsetLeft;
					y += obj.offsetTop;
				} while (obj=obj.offsetParent);
			}
			return [x,y];
		},
	hideall: function(except) {
			var els = document.getElementsByTagName('DIV');
			for (var i=0;i<els.length;i++)
			if (els[i].id.match(/^popup/)!=null && els[i]!=except) {
				els[i].style.display='none';
			}
		},
	mover: function(a,id) {
			var popup = document.getElementById('popup'+id);
			if (popup) {
				esmart.hideall(popup);
				var xy = esmart.getpos(a);
				popup.style.top=xy[1]+'px';
				popup.style.left=(xy[0]+15)+'px';
				popup.style.display='block';
				esmart.shade(popup.parentNode,xy[0]+15,xy[1],popup.offsetWidth,popup.offsetHeight);
				document.documentElement.onmouseover=esmart.mout;
			}
		},
	delayedmout: function() {
			esmart.hideall(null);
			esmart.unshade();
		},
	mout: function(e) {
			var targ = undefined;
			if (!e) var e = window.event;
			if (e.target) targ = e.target;
			else if (e.srcElement) targ = e.srcElement;
			if (targ.nodeType==3) targ = targ.parentNode;
			if (targ) {
				clearTimeout(esmart.timeout);
				do {
					if ((targ.id && (targ.id.match(/^popup/)!=null || targ.id=='menu')) || (targ.className && (targ.className=='popup' || targ.className=='popupmenu'))) break;
				} while (targ=targ.parentNode);
				/*if (targ)
					esmart.log(targ.nodeName+' '+targ.className+' '+targ.id+' '+targ.innerHTML);*/
				if (!targ) {
					esmart.timeout=setTimeout(esmart.delayedmout,500);
				}
			}
		},
	log: function(txt) {
			var l = document.getElementById('log');
			l.innerHTML=txt;
		},
	unshade: function() {
			if (esmart.shadediv) esmart.shadediv.parentNode.removeChild(esmart.shadediv);
			esmart.shadediv=undefined;
		},
	shade: function(obj,x,y,width,height) {
			esmart.unshade();
			esmart.shadediv = document.createElement('DIV');
			esmart.shadediv.className='shade';
			esmart.shadediv.style.background='black';
			esmart.shadediv.style.top=(y+3)+'px';
			esmart.shadediv.style.left=(x+3)+'px';
			esmart.shadediv.style.width=width+'px';
			esmart.shadediv.style.height=height+'px';
			obj.parentNode.insertBefore(esmart.shadediv,obj);
		}
};


