// JavaScript Document
// www.veselo.de

var menu=[];
var sub_menu=[];
var menu_id = 0;
var sub_menu_id = 0;
var sub_m_frame;
var sub_color_n;
var sub_color_o;
var sub_font;
var sub_font_size;
var active = 0; //number of active item

function add_menu(text,link,target){
	sub_menu_id = 0;
	menu_id++;
	menu[menu_id]={
		id: menu_id,
		text: text,
		link: link,
		target: target,
		sub_menu: []
	};
}

function add_sub_menu(text,link,target){
	sub_menu_id++;
	menu[menu_id].sub_menu[sub_menu_id]={
		id: sub_menu_id,
		text: text,
		link: link,
		target: target
	};
}

//parameters div id and color
function change_text_color(id,color){
	if(id != active)
		document.all.item(id).style.color=color;
}

function set_active_menu_item(id, color_normal){
	temp_id = active;
	active = id;
	change_text_color(temp_id, color_normal);	
}


//sub_menu_frame - were sub_menu will be shown as pointer, example: parent.leftFrame
//sub_menu_frame - target for sub_menu links as string, example:"parent.leftFrame"
function draw_menu(color_normal, color_over, font, font_size ){
	document.write('<table width="650" border="0" cellspacing="0" cellpadding="0"><tr>');
	for(i=1; i < menu.length; i++){
		var m = menu[i];
		document.write('<td>');
		menu_item(window, m.id, m.text, m.id, m.link, m.target , color_normal, color_over, font, font_size);
		document.write('</td>');
	}
	document.write('</tr></table>');
}

function draw_sub_menu(sub_menu_frame, sub_color_normal, sub_color_over, font, font_size){
	sub_m_frame = sub_menu_frame;
	sub_color_n = sub_color_normal;
	sub_color_o = sub_color_over;
	sub_font = font;
	sub_font_size = font_size;
}


// parameters div 
// id (name, can be string)
// text(label) and so on 
// sub_menu_name array of (name, link)s
function menu_item(where,id, text, sub_m_id, link, target, color_normal, color_over, font, font_size){
	
	var tag =  "<div id=\"" + id + "\" ";
		tag += "style='color:" + color_normal + "; " ;
		tag += 'font-family: "' + font + '"; ';
		tag += 'font-size: ' + font_size + '; ';
		tag += "cursor:hand;'";
		tag += "onMouseOver=\"change_text_color('" + id + "',";
		tag += "'" + color_over + "')\" ";
		tag += "onMouseOut=\"change_text_color('" + id + "',";
		tag += "'" + color_normal +"')\" ";
		tag += "onClick=\"";
		tag += "set_active_menu_item('" + id + "','" + color_normal + "'); ";
		if(sub_m_id != 0){
			tag += "show_sub_menu(" + sub_m_id + "); ";
		}
		if(link != ""){
			if(target != "")
				tag += target +".";
			tag += "location.href = '" + link + "'";
		}
		tag += "\" "; 
		tag += "> ";
		tag += text;
		tag += " </div>";
	where.document.write(tag);
}


function show_sub_menu(sub_m_id){
	f=sub_m_frame.document;
	f.open();
	f.write('<html>																							\
			<head>																							\
			<title>Submenu</title>																			\
			<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">						\
			<script language="JavaScript" type="text/JavaScript" src="menu_functions.js">					\
			</script>																						\
			</head>																							\
			<body background="images/hgr.jpg" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">\
			');
			
	f.write('	<div style="{									\
					background-image: url(images/unten.jpg);	\
					background-repeat: no-repeat;				\
					height: 80%;								\
					width: 100%;								\
				}" > 											\
			');
			
	if(menu[sub_m_id].sub_menu.length != 0){		
		f.write('	<table width="190" border="0" align="left" cellspacing="10" cellpadding="0">	\
					<tr>															\
					<td width="175">												\
					<div align="right">												\
				');
	
	
		for(i=1; i < menu[sub_m_id].sub_menu.length; i++){
			var m = menu[sub_m_id].sub_menu[i];
			menu_item(sub_m_frame, "sub"+menu[sub_m_id].id +"_"+m.id , m.text, 0, m.link, m.target , sub_color_n, sub_color_o, sub_font, sub_font_size);		
			f.write("<br>");
		}	
		f.write('	</div>									\
					</td>									\
					<td width="5" bgcolor="#3D872F"></td>	\
					</tr>		\
					</table>	\
				');
	}
	
	f.write('	</div>		\
				</body>		\
				</html>		\
			');
	f.close();	
}
