var menu1_items = [
	['Home', '/english/main.html', ''],
	['News', '/english/news/index.html', ''],
	['Products', '/english/products/index.html', '',
		['Material', '/english/products/index.html', '',],
		['Equipment', '/english/products/equipment.html', ''],
		['Advanced Technologies', '/english/products/tech.html', ''],
		['R&amp;D', '/english/products/randd.html', ''],
		['Production', '/english/products/productions.html', ''],
],
	['Company', '/english/company/', '',
		['Introduction', '/english/company/index.html',''],
		['History', '/english/company/history.html',''],
		['Message from Management', '/english/company/message.html',''],
		['Relationship with Customer', '/english/company/rwc.html',''],
		['Company Profile', '/english/company/profile.html',''],
		['Relationship with Society', '/english/company/rws.html',''],
		['Quality', '/english/company/quality.html',''],
		['Contribution to Environment', '/english/company/cte.html',''],
		['Philosophy', '/english/company/philosophy.html',''],
		['Global Network', '/english/company/global.html',''],
	],
	['Events', '/english/events/index.html', ''],
	['Contact', '/english/contact/index.php', ''],
];



function addLoadEvent(func) {		// menu uses onLoad event - to have another onLoad event, add it right after BODY tag (eg <SCRIPT>addLoadEvent(function() { javascript:alert('yebagogo'); });</SCRIPT> or <SCRIPT>addLoadEvent(init);</SCRIPT>)
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
		func();
		}
	}
}

var menu_layers = new Array(); var ol = ''; var or = ''; renderMenu('1');
function renderMenu(mnr) {
	window['menu' + mnr + '_old_main_pos'] = 0; window['menu' + mnr + '_new_main_pos'] = 0; window['menu' + mnr + '_to']; window['menu' + mnr + '_opened'];
	menu_start(mnr);		// make position relative
	menu_read(mnr, '', '');		// read menu and build layers
	menu_resize(mnr, '');		// give all relevant layers equal width
	menu_resize(mnr, 'andPosition');	// twice since layers prior to widest may not have been resized yet + place layers at the right position
	menu_end();		// close menu container layer
	ol += "document.getElementById('menu" + mnr + "_container').style.left = document.getElementById('menu" + mnr + "_ref').offsetLeft; document.getElementById('menu" + mnr + "_container').style.top = document.getElementById('menu" + mnr + "_ref').offsetTop; ";
	or += "document.getElementById('menu" + mnr + "_container').style.left = document.getElementById('menu" + mnr + "_ref').offsetLeft; document.getElementById('menu" + mnr + "_container').style.top = document.getElementById('menu" + mnr + "_ref').offsetTop; ";
	if (typeof(menu2_items) != 'undefined' && typeof(menu2_new_main_pos) == 'undefined') renderMenu('2');
}
addLoadEvent(function() { eval(ol); }); 	// if the menu will be placed inside a table, it must be created outside the table
window.onresize= function() { eval(or); }	// if not, all menu layers will have a width of 0px (layer.offsetWidth)

function menu_start(mnr) {
	document.write('<DIV ID="menu' + mnr + '_container" STYLE="position:relative; top:-40px; width:0px; height:0px; z-index:1">');
}

function menu_read(mnr, level, rm_main) {
	if (!level) { level = 'menu' + mnr + '_items'; menu_layers[mnr] = new Array(); }
	var i = 0; var rm_sub = 0;
	while (i < eval(level).length) {
		if (typeof(eval(level)[i]) == 'object') {
			rm_sub++; rm_pos = (rm_main)?(rm_main + '_' + rm_sub):(rm_sub + '');
			document.write('<DIV ID="menu' + mnr + '_' + rm_pos + '" class="menu_new" STYLE="position:absolute; padding:2px; border-left:1px solid #FFFFFF; ' + ((rm_main)?('background-color:#139C83; '):(''))  + 'cursor:' + ((eval(level)[i][1] != '')?('pointer'):('default')) + '" onMouseOver="menu_open(\'' + mnr + '\', \'' + rm_pos + '\', \'1\'); menu_highlight(\'' + mnr + '\', \'on\', \'' + rm_pos + '\')" onMouseOut="menu_close(\'' + mnr + '\', \'' + rm_pos + '\', \'delayed\'); menu_highlight(\'' + mnr + '\', \'off\', \'' + rm_pos + '\')"' + ((eval(level)[i][1] != '')?(' onClick="menu_open_link(\'' + eval(level)[i][1] + '\', \'' + eval(level)[i][2] + '\')"'):('')) + '><NOBR STYLE="font-size:15px; color:#FFFFFF">&nbsp;' + eval(level)[i][0] + '&nbsp;</NOBR></DIV>');
			var mll = menu_layers[mnr].length; menu_layers[mnr][mll] = new Array(); 	menu_layers[mnr][mll]['pos'] = rm_pos; menu_layers[mnr][mll]['width'] = document.getElementById('menu' + mnr + '_' + rm_pos).offsetWidth;
			if (eval(level)[i].length != 3) menu_read(mnr, level + '[' + i + ']', rm_pos);
		}
	i++;
	}
}

function menu_resize(mnr, position) {
	for (i=0; i<menu_layers[mnr].length; i++) {
		var mparent = menu_layers[mnr][i]['pos'].substring(0, menu_layers[mnr][i]['pos'].lastIndexOf('_'));
		if (mparent != '') {
			if (window['m' + mnr + '_' + mparent] >= menu_layers[mnr][i]['width']) {
				menu_layers[mnr][i]['width'] = window['m' + mnr + '_' + mparent];
				document.getElementById('menu' + mnr + '_' + menu_layers[mnr][i]['pos']).style.width = menu_layers[mnr][i]['width'] + 'px';
			}
			window['m' + mnr + '_' + mparent] = menu_layers[mnr][i]['width'];
		} else {
			if (menu_layers[mnr][i]['width'] > window['m' + mnr + '_' + menu_layers[mnr][i]['pos']]) window['m' + mnr + '_' + menu_layers[mnr][i]['pos']]  = menu_layers[mnr][i]['width'];
		}
		if (position) menu_position(mnr, menu_layers[mnr][i]['pos']);
	}
}

function menu_position(mnr, position) {
	var pos_split = position.split('_');
	if (pos_split.length == 1) {
		document.getElementById('menu' + mnr + '_' + position).style.left = window['menu' + mnr + '_new_main_pos'];
		document.getElementById('menu' + mnr + '_' + position).style.top = '0';
		window['menu' + mnr + '_old_main_pos'] = window['menu' + mnr + '_new_main_pos'];
		window['menu' + mnr + '_new_main_pos'] += document.getElementById('menu' + mnr + '_' + position).offsetWidth;
	} else {
		document.getElementById('menu' + mnr + '_' + position).style.visibility = 'hidden';
		if (pos_split.length ==2) {
			document.getElementById('menu' + mnr + '_' + position).style.left = window['menu' + mnr + '_old_main_pos'];
		} else {
			var one_up = position.substring(0, position.lastIndexOf('_'));
			document.getElementById('menu' + mnr + '_' + position).style.left = document.getElementById('menu' + mnr + '_' + one_up).offsetLeft + document.getElementById('menu' + mnr + '_' + one_up).offsetWidth;
		}
		var sumt = 0; for (j=1; j<pos_split.length; j++) { sumt += (pos_split[j]*1); }
		document.getElementById('menu' + mnr + '_' + position).style.top = document.getElementById('menu' + mnr + '_' + position).offsetHeight * (sumt-(pos_split.length-2));
	}
}

function menu_end() {
	document.write('</DIV>');
}

function menu_open(mnr, position, cnt) {
	if (window['menu' + mnr + '_to']) clearTimeout(window['menu' + mnr + '_to']);
	if (document.getElementById('menu' + mnr + '_' + position + '_' + cnt)) {
		document.getElementById('menu' + mnr + '_' + position + '_' + cnt).style.visibility = 'visible';
		cnt++; menu_open(mnr, position, cnt);
	} else menu_close(mnr, position, 'direct');
}

function menu_close(mnr, position, timing) {
	if (timing == 'delayed') { if (window['menu' + mnr + '_to']) clearTimeout(window['menu' + mnr + '_to']); window['menu' + mnr + '_to'] = setTimeout('menu_close(\'' + mnr + '\', \'0\', \'direct\')', 2000); }
	else {
		for (i=0; i<menu_layers[mnr].length; i++) {
			if (menu_layers[mnr][i]['pos'].indexOf('_') != '-1') {
				if (position == '0') document.getElementById('menu' + mnr + '_' + menu_layers[mnr][i]['pos']).style.visibility = 'hidden';
				else {
					if (position.indexOf('_') != -1) { if ((menu_layers[mnr][i]['pos'].split('_').length > position.split('_').length) && (menu_layers[mnr][i]['pos'].indexOf(position) != 0)) document.getElementById('menu' + mnr + '_' + menu_layers[mnr][i]['pos']).style.visibility = 'hidden'; }
					else { if (menu_layers[mnr][i]['pos'].substring(0, menu_layers[mnr][i]['pos'].indexOf('_')) != position) document.getElementById('menu' + mnr + '_' + menu_layers[mnr][i]['pos']).style.visibility = 'hidden'; }
				}
			}
		}
	}
}

function menu_open_link(link, target) {
	link = this.location.href.substring(0, this.location.href.indexOf('')) + '' + link;

	if (!target || target == '_self') document.location.href = link;
	else {
		if (window.parent.frames[target]) window.parent.frames[target].location.href = link;
		else if (target == '_top') top.location.href = link;
		else if (target == '_parent') parent.location.href = link;
		else window.open (link);
	}
}

function menu_highlight(mnr, status, position) {
	var menu_bgc = (position.indexOf('_') != '-1')?('#139C83'):('');
	document.getElementById('menu' + mnr + '_' + position).style.backgroundColor = (status == 'on')?('#6BBBA9'):(menu_bgc);
}