//		Copyright © 2009 ExIdeas, Inc.*
// 		version 1.78

/**************************************************************************************************************/
//	Data structure for ME_keyboard. This may include additional language keybaords.
/**************************************************************************************************************/
Menu_data = 
{
	"Typing Match":{
		"loc":		{
						"top"	:100,
						"left"	:0
					},
		"style":	"menuStyle",
		"bg_color":	"#aaaaaa",
		"items":	{
						"ANIHORTES":{
								"legend": "Start with ANIHORTES",
								"param"	: "ANIHORTES",
								"tool_tip": "The simplest group: Only most frequent letters or tap keys are used for this group."},
						"ANI-QUP":{
								"legend": "Start with ANI + QUP",
								"param"	: "ANI-QUP",
								"tool_tip": "Medium group: most frequent and letters on the center key are used only."}, 
						"ANI-VLX":{
								"legend": "Start (ANI + VLX)",
								"param"	: "ANI-VLX",
								"tool_tip": "Medium group: most frequent and letters on the outside keys sliding to the center are used."},
						"com1000":{
								"legend": "Start (Common words)",
								"param"	: "com1000",
								"tool_tip": "Common 1000 English words are used for this test."},
						"stop":{
								"legend": "Stop",
								"param"	: "stop",
								"tool_tip": "Stop the Typing Match"}
					},
		"call_function":	"StartStopTTest"
	},// Typing Match 
	"Languages":{
		"loc":		{
						"top"	:100,
						"left"	:-30
					},
		"style":	"menuStyle",
		"bg_color":	"#aaaaaa",
		"items":	{
						"English":{
								"legend": "English",
								"param"	: "English",
								"tool_tip": "Change the keyboard to English"},
						"Katakana":{
								"legend": "&#12459;&#12479;&#12459;&#12490;",
								"param"	: "Katakana",
								"tool_tip": "Change the keyboard to &#12459;&#12479;&#12459;&#12490; (Japanese Katakana)"} 
					},
		"call_function":	"change_keyboard_language"
	}// Typing Match 
	
};// menu_data


/****************************************************************************************************************************/
function popMenu(owner){
	var title = owner.innerHTML;
	var d = document.getElementById('menuDiv');

	if(menu_showing_flag){
		hideDiv('menuDiv');
		menu_showing_flag = false;
	}
	else{
		var d =	document.getElementById('menuDiv');
		d.style.width = "";
		d.style.height = "";
		changeClassName('menuDiv',  Menu_data[title]["style"])							// change it's style
		fill_menu( Menu_data[title]);											// put the items in a table
		var menutop = parseInt(owner.style.top) + parseInt(owner.offsetHeight);						// calculate vert location, just below the title 
		var menuleft = parseInt(owner.style.left) +  parseInt(owner.offsetWidth) - parseInt(d.offsetWidth) + parseInt(Menu_data[title]["loc"]["left"]);

		moveDivXY('menuDiv', menuleft, menutop);	
		
		showDiv('menuDiv');
		menu_showing_flag = true;
		
		displayObject['menu'].width= parseInt(d.offsetWidth); 
		displayObject['menu'].leftAdjust= menuleft - (WinCenter - Math.floor (parseInt(d.offsetWidth)/2));
	}
}
/****************************************************************************************************************************    
function change_category(m, v){
	//mouseaction = ["onmousedown", "onmouseup"]
	;;alert(mouseaction[m] + '  ' + v);
	ttest_level	= v;
}
/****************************************************************************************************************************/    
function toggle_visibility(id) {
	var e = document.getElementById(id);
	if(e.style.display == 'block')
		e.style.display = 'none';
	else
		e.style.display = 'block';
}
/****************************************************************************************************************************/
function fill_menu(title){
	var legend, param, call_str1, call_str2, tooltip, tooltip_str;
	var pre1 ="div class='menuItemStyle' onmouseover=this.style.backgroundColor='" + title["bg_color"]  + "' " +
	" onmouseout=this.style.backgroundColor=''  ";

	var str ="";

	for (var key in title["items"]){
		legend 		= title["items"][key]["legend"]; 			// this will produce a menue item string
		param 		=  title["items"][key]["param"]; 
		tooltip 	=title["items"][key]["tool_tip"];
		toltip_str 	= "title=\"" + tooltip + "\"";
		call_str1 	= " onmousedown=\"" +  title["call_function"] + "('"  + param + "')\" " ;
		call_str2 	= " onmouseup=\"" +  title["call_function"] + "('"  + param + "')\" " ;
		str 		+=  "<"  + pre1  + call_str1 + call_str2 + toltip_str +   " >" + legend + "</div>";
	}
	document.getElementById('menuDiv').innerHTML = str;
}
/**********************************************************function hideDiv(divName) **************************************************/
function changeClassName(divName, newClassName){
	document.getElementById(divName).className=newClassName;
}
/************************************************************************ moveDivXY *********************************/
function moveDivXY(divName, x, y){
	var d =	document.getElementById(divName).style;
	d.left = x;
	d.top  = y;
	//d.visibility = 'visible';
}
