function sin (s)
{
	s.setAttribute('isover', 'true');
	think(s, document.getElementById(s.getAttribute('linkrelated')));
}
function sout (s)
{
	s.setAttribute('isover', 'false');
	think(s, document.getElementById(s.getAttribute('linkrelated')));
}
function ain (a)
{
	a.setAttribute('isover', 'true');
	think(document.getElementById(a.getAttribute('smrelated')), a);
}
function aout (a)
{
	a.setAttribute('isover', 'false');
	think(document.getElementById(a.getAttribute('smrelated')), a);
}
function think (s, l)
{
	if(s.getAttribute('isover')=='true'||l.getAttribute('isover')=='true')
		s.style.display='block';
	else
		s.style.display='none';
}

function getPosition(e){
    var position = {left:0,top:0};
	while (e)
	{
		position.left += e.offsetLeft;
		position.top += e.offsetTop;
		e = e.offsetParent;
	}
	return position;
}

function submenu (parent, id, top, left, buttons, links, lnk)
{
	var p = document.getElementById(parent);
	var l = document.getElementById(lnk);
	var menuHeight = ((buttons.length*36)+(-26)+(buttons.length*2));
	
	//top = getPosition(l).top;
	//left = getPosition(l).left;
	
	
	//alert("height: "  + l.height + "offset height: " + l.offsetHeight);
	//alert("width: "  + l.width + "offset width: " + l.offsetWidth);
	//top = top + l.offsetHeight;
	//left = left - (l.offsetWidth / 2) - (l.style.paddingLeft - l.style.paddingRight - l.style.marginLeft - l.style.marginRight);
	
	
	var container = document.createElement('div');
	container.setAttribute('id', id);
	container.setAttribute('class', "submenu_container");
	container.setAttribute('style', "top:"+top+"px;left:"+left+"px;height:"+menuHeight+"px;display:none;");
	container.setAttribute('onMouseOver', "sin(this);");
	container.setAttribute('onMouseOut', "sout(this);");
	container.setAttribute('linkrelated', lnk);
	container.setAttribute('isover', 'false');
	
	var menubg = document.createElement('div');
	menubg.setAttribute('class', 'submenu');
	
	var top = document.createElement('div');
	top.setAttribute('class', 'submenu_top');
	var main = document.createElement('div');
	main.setAttribute('class', 'submenu_main');
	main.setAttribute('style', 'height:'+menuHeight+'px !important');
	var bottom = document.createElement('div');
	bottom.setAttribute('class', 'submenu_bottom');
	
	menubg.appendChild(top);
	menubg.appendChild(main);
	menubg.appendChild(bottom);
	
	var sb = document.createElement('div');
	sb.setAttribute('class', 'submenu_buttons');
	for(var i=0;i<buttons.length;i++)
	{
		var a = document.createElement('a');
		a.setAttribute('href', links[i]);
		a.innerHTML = buttons[i];
		sb.appendChild(a); 
	}
	
	container.appendChild(menubg);
	container.appendChild(sb);
	
	p.appendChild(container);	
	
	//var l = document.getElementById(lnk);
	l.setAttribute('onMouseOver', 'ain(this);');
	l.setAttribute('onMouseOut', 'aout(this);');
	l.setAttribute('isover', 'false');
	l.setAttribute('smrelated', id);
}
