/*
CMS Menu v1.0
(C)2003 Aptus s.c.
*/

cm_bgcolor_over='#000000';

cm_style_menu='';
cm_style_hdr='';
cm_style_item='font-family:Verdana, Tahoma, Arial; font-size:12px; font-weight:bold; color:#F8EFF5; padding:1px 15px 2px 3px;';
cm_style_link='font-family:Verdana, Tahoma, Arial; font-size:12px; font-weight:bold; color:#F8EFF5; text-decoration:none;';

cm_shiftx=0;
cm_shifty=0;

cm_list=Array();
cm_tabcolor=Array('#990066','#FF0000','#E40084','#FF6600','#F7A0A7','#81C11F');
cm_timer=null;
cm_inited=false;

cm_id=0;

cm_tmpcolor='';

function cm_init()
{
	var i;
	var d='';
	for(i=0; i<cm.length; i++) {
		d+='<div id="cm'+i+'" style="z-index:3;  position:absolute;left:0px; top:0px; visibility:hidden;" onMouseOver="cm_over();" onMouseOut="cm_out();">';
		d+=cm_menustart(i);
		var j;
		for(j=0; j<cm[i].length; j++)
			d+=cm_menuitem(cm[i][j],i);
		d+=cm_menuend();
		d+='</div>';
	}
	document.getElementById('cm').innerHTML=d;
	cm_inited=true;
}

function cm_menu(id,t,c)
{
	if(!cm_inited)
		return;
	cm_hideall();
	var e=document.getElementById('cm'+id).style;
	var x=0;
	var y=150;
	var tmp=t;
	while(tmp!=null) {
		x+=tmp.offsetLeft;
		y+=tmp.offsetTop;
		tmp=tmp.offsetParent;
	}
	e.left=x;
	e.top=y;
	cm_tmpcolor=cm_tabcolor[c];
	document.getElementById('cm'+id+'_t').style.backgroundColor=cm_tmpcolor;
	e.visibility='visible';
	cm_list=Array();
	cm_list[0]=id;
}

function prevcolor(el)
{
	el.style.backgroundColor=cm_tmpcolor;
}

function cm_hidesub(m)
{
	var i;
	for(i=0; i<cm_list.length; i++)
		if(cm_list[i]==m) {
			var j=i;
			for(i++; i<cm_list.length; i++)
				document.getElementById('cm'+cm_list[i]).style.visibility='hidden';
			cm_list=cm_list.slice(0,j+1);
			break;
		}
}

function cm_submenu(id,t,m)
{
	var i;
	for(i=0; i<cm_list.length; i++)
		if(cm_list[i]==m) {
			var j=i;
			for(i++; i<cm_list.length; i++)
				document.getElementById('cm'+cm_list[i]).style.visibility='hidden';
			cm_list=cm_list.slice(0,j+1);
			break;
		}
	var e1=document.getElementById('cm'+id);
	var e2=document.getElementById('cm'+m);
	if(t.offsetLeft+t.offsetWidth+e2.offsetLeft+cm_shiftx+e1.offsetWidth<document.body.clientWidth)
		e1.style.left=t.offsetLeft+t.offsetWidth+e2.offsetLeft+cm_shiftx-1;
	else
		e1.style.left=t.offsetLeft+e2.offsetLeft-e1.offsetWidth-cm_shiftx;
	e1.style.top=t.offsetTop+e2.offsetTop+cm_shifty;
	document.getElementById('cm'+id+'_t').style.backgroundColor=cm_tmpcolor;
	e1.style.visibility='visible';
	cm_list[cm_list.length]=id;
}

function cm_over()
{
	if(cm_timer!=null)
		clearTimeout(cm_timer);
	cm_timer=null;
}

function cm_out()
{
	if(cm_timer!=null)
		clearTimeout(cm_timer);
	cm_timer=setTimeout('cm_hideall();',1100);
}

function cm_hideall()
{
	if(!cm_inited)
		return;
	if(cm_timer!=null)
		clearTimeout(cm_timer);
	cm_timer=null;
	var i;
	for(i=0; i<cm.length; i++)
		document.getElementById('cm'+i).style.visibility='hidden';
	cm_list=Array();
}

function cm_menustart(i)
{
	return '<table id="cm'+i+'_t" bgcolor=\'#CCCCCC\' cellspacing=0 cellpadding=2 border=0 style="'+cm_style_menu+'">';
}

function cm_menuend()
{
	return '</table>';
}

function cm_menuitem(t,m)
{
	if(t.length>1) {
		cm_id=m;
		var s='<tr><td style=\''+cm_style_item+'\'';
		if(t.length>2)
			s+=' onmouseover="cm_submenu('+t[2]+',this,'+m+'); this.style.backgroundColor=\''+cm_bgcolor_over+'\'; this.style.cursor=\'pointer\'; window.status=\''+t[0]+'\';return true;" onmouseout="prevcolor(this); window.status=\'\'; return true;"';
		else
			s+=' onMouseover="cm_hidesub('+m+'); this.style.backgroundColor=\''+cm_bgcolor_over+'\';this.style.cursor=\'pointer\';window.status=\''+t[0]+'\';return true;" onmouseout="prevcolor(this); window.status=\'\'; return true;"';
		if(t[1].length>0)
		{
			s+=' onClick="location.href=\''+t[1]+'\';"';
		}
		s+='>';
		s+='&nbsp;'+t[0];
//		if(t.length>2)
//			s+='&nbsp;&nbsp;&nbsp;<span style="font-size:12px; color:#E9E9E9;">&raquo; </span>';
		s+='</td></tr>';
		return s;
	}
	return '<tr><td style="'+cm_style_hdr+'">'+t[0]+'</td></tr>';
}

