//
// Hello World
//

// Be sure of the path of which imports this JavaScript, that is the path of "hello_world.js"
// File.currentDir = new File("/");

document.write("<script src='../js/array.js' type='text/javascript'></script>");
/* document.write("<script src='../js/hello.js' type='text/javascript' ></script>"); */
document.write("<script src='../js/lang.js' type='text/javascript'></script>");
document.write("<script src='../js/country.js' type='text/javascript'></script>");
document.write("<script src='../js/boys_girls.js' type='text/javascript' ></script>");


/*
 * lanuage -> msg[0]
 * word    -> msg[1]
 *
 * boy_girl = new Array ("../images/boymini1", "../image/girlmini1");
 *
 * boy_color[0] = aka_boy;
 * boy_color[1] = ao_boy;
 * boy_color[2] = kiiro_boy;
 * boy_color[3] = kimidori_boy;
 * boy_color[4] = midori_boy;
 * boy_color[5] = mizu_boy;
 * boy_color[6] = orange_boy;
 * boy_color[7] = pink_boy;
 *
 * girl_color[0] = aka_girl;
 * girl_color[1] = ao_girl;
 * girl_color[2] = kiiro_girl;
 * girl_color[3] = kimidori_girl;
 * girl_color[4] = midori_girl;
 * girl_color[5] = mizu_girl;
 * girl_color[6] = orange_girl;
 * girl_color[7] = pink_girl;
 *
 *
 * all = (boy_color, girl_color)
 *
 */


/*
 * CHANGE
 *
 * msg[0].length -> hello.length
 * msgf[1][i] -> getWord(i)
 * msgf[0][i] -> getLang(i)
 *
 */



// show all hello
function showAllHello() {
	// the number of languages registered

	la = hello.length; //

	

	// show Hello
	document.write("<table border='0'>");

	for(i = 0; i < la; i++) {
		{	if(i < 9)
				pad = "&nbsp;"; 
			else
				pad ="";
		}

		document.write("<tr>"+

					"<td>" + pad + (i+1) + "&nbsp;" + " : " + "&nbsp;" + "</td>" +

					"<td>" + "<font color='#ff0000'>" + getWord(i) + "</font>" + "</td>" +
								
					"<td></td>" +

					"<td>" + "<font color='#ff0000'>" + getProno(i) + "</font>" + "</td>" +
								
					"<td>" + "&nbsp;&nbsp;&nbsp;&nbsp;" + " < " + getLang(i) + " >" + "</td>" +

					"<tr />");


		// every time 5 hello
		if((i % 5) == 4) {
			document.write("<tr>" + "<td>&nbsp;</td>" + "<td>&nbsp;</td>" + "<td>&nbsp;</td>" + "</tr>");
			document.write("<tr>" + "<td>&nbsp;</td>" + "<td>&nbsp;</td>" + "<td>&nbsp;</td>" + "</tr>");
		} 	

	} // i-for loop

	document.write("</table>");

} // showAllHello






// show a boy or a girl
function showBG() {

	rand_gen = Math.floor(Math.random() * boy_girl.length);		// 0=boy, 1=girl
	rand_color = Math.floor(Math.random() * boy_color.length);
	rand_look =  Math.floor(Math.random() * boy_color[0].length);

	// define
	boy = 0;
	// girl = 1;

	{
	if(rand_gen == boy)
		who = boy_girl[rand_gen] + "/" + boy_color[rand_color][rand_look];
	else
		who = boy_girl[rand_gen] + "/" + girl_color[rand_color][rand_look];	
	}

	document.write("<img src='" + who + "' />");		

}





// show boys and girls
function showAllBoysGirls() {

	// the number of gender	
	gen = boy_girl.length;

	color = boy_color.length;	// = girl_color.length;

	// the number of expression for each color
	look = boy_color[0].length; // = ... = boy_color[7].length = ... = girl_colork[7].length;


	boy = 0;
	girl = 1;

	// show boys
	for(j = 0; j < color; j++) {
		for(k = 0; k < look; k++) {
			// document.write(boy_girl[boy] + "/" + boy_color[j][k] + ";&nbsp;"); 
			who_boy = boy_girl[boy] + "/" + boy_color[j][k];

			document.write("<img src='" + who_boy + "' />");
			document.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
		} // for

		document.write("<br />");

	} // for

	document.write("<div class='space'></div>");
	document.write("<div class='space'></div>");

	// show girls
	for(j = 0; j < color; j++) {
		for(k = 0; k < look; k++) {
			// document.write(boy_girl[girl] + "/" + girl_color[j][k] + ";&nbsp;"); 
			who_girl = boy_girl[girl] + "/" + girl_color[j][k];
		
			document.write("<img src='" + who_girl + "' />");
			document.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
		} // k- for loop

		document.write("<br />");

	} // j-for loop

} // showAllBoysGirls






//
//　s = ""+i; // i:int を 文字列 "i":string に変換
//
// show boys and girls randomly
//
// rand_th -> unshown No. -> id_no like (1, 3, 2)		--- detour ---
//
function randShowAllBoysGirls() {

	ids = new Array();		// ( (gen, color, look), ... )
	unshown = new Array();  // (0, ... , 79)

	gen = boy_girl.length;
	color = boy_color.length;
	look = boy_color[0].length;

	how_many = gen * color * look;
	
	
	// make all id_no
	for(i=0; i < gen; i++) {
		for(j=0; j < color; j++) {
			for(k=0; k < look; k++) {
				reg_id = new Array();

				reg_id.push(i);
				reg_id.push(j);
				reg_id.push(k);	
			
				ids.push(reg_id);

			} // k-loop	
		} // j-loop
	} // i-loop



	// initialize unshown-list
	for(i=0; i < how_many; i++) {
		unshown.push(i);
	}


	// call nth person
	// nth -> unshown No. -> id like (1, 3, 2)
	for(i=0; i < how_many; i++) {

		rand = Math.floor(Math.random() * unshown.length);

		unshown_no = getNth(unshown, rand);
		id_no = getNth(ids, unshown_no);

		
		rand_gen = getNth(id_no, 0);
		rand_color = getNth(id_no, 1);
		rand_look = getNth(id_no, 2);

		who = boy_girl[rand_gen] + "/" + friends[rand_gen][rand_color][rand_look];
		
		document.write("<img src='" + who + "' />");
		document.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");


		// every time 5 friends show up
		if((i % 5) == 4) {
			document.write("<br />");

			// every time 10 friends show up, put line
			if((i % 10) == 9) {
				document.write("<br />");
				document.write("<img src='../images/line2_3.gif' />");
				document.write("<br /><br /><br />");
			}
		} 


		// replace unshown-list
		unshown = deleteNth(unshown, rand); // rand_th in unshown-list showed up!

	} // for

} // randShowAllBoysGirls







//
// show boys and girls randomly
//
// rand_th -> id_no like (1, 3, 2)
//
function SimpleRandShowAllBoysGirls() {

	ids = new Array();		// ( (gen, color, look), ... )

	gen = boy_girl.length;
	color = boy_color.length;
	look = boy_color[0].length;

	how_many = gen * color * look;
	
	
	// make all id_no
	for(i=0; i < gen; i++) {
		for(j=0; j < color; j++) {
			for(k=0; k < look; k++) {
				reg_id = new Array();

				reg_id.push(i);
				reg_id.push(j);
				reg_id.push(k);	
			
				ids.push(reg_id);

			} // k-loop
		} // j-loop
	} // i-loop



	// call nth person
	// nth -> id_no like (1, 3, 2)
	for(i=0; i < how_many; i++) {

		rand = Math.floor(Math.random() * ids.length);

		id_no = getNth(ids, rand);

		
		rand_gen = getNth(id_no, 0);
		rand_color = getNth(id_no, 1);
		rand_look = getNth(id_no, 2);

		who = boy_girl[rand_gen] + "/" + friends[rand_gen][rand_color][rand_look];
		
		document.write("<img src='" + who + "' />");
		document.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");


		// every time 5 friends show up
		if((i % 5) == 4) {
			document.write("<br />");

			// every time 10 friends show up, put line
			if((i % 10) == 9) {
				document.write("<br />");
				document.write("<img src='../images/line2_3.gif' />");
				document.write("<br /><br /><br />");
			}
		} 


		// replace ids-list
		ids = deleteNth(ids, rand); // rand_th in ids-list showed up!

	} // i-for loop

} // SimpleRandShowAllBoysGirls





//
// show boys and girls randomly
//
//  rand -> id_no like (1, 3, 2)
//
function SmartRandShowAllBoysGirls() {

	unshown = new Array();		// (0, ...)

	gen = boy_girl.length;		// 0,1
	color = boy_color.length;	// 0,1,2,3,4,5,6,7
	look = boy_color[0].length;	// 0,1,2,3,4

	how_many = gen * color * look;
	
	weight_gen 		= Math.pow(gen,0) * color * look;								// gen^0 * color * look
	weight_color	= Math.pow(gen,0) * Math.pow(color,0) * look;					// gen^0 * color^0 * look
	weight_look		= Math.pow(gen,0) * Math.pow(color,0) * Math.pow(look,0);		// gen^0 * color^0 * look^0



	// initialize unshown-list
	for(i=0; i < how_many; i++) {
		unshown.push(i);
	}


	// call rand_nth person
	// rand -> id_no (rand_gen, rand_color, rand_color)
	// rand = (rand_gen * wight_gen) + (rand_color * wight_color) + (rand_lok * wight_look)
	//
	for(i=0; i < how_many; i++) {

		rand = Math.floor(Math.random() * unshown.length);
		rand_no = getNth(unshown, rand);



		// translate rand_no to id_no=(gen, color, look);

		rand_gen = Math.floor(rand_no / weight_gen);
		gen_rest = rand % weight_gen;
		
		rand_color = Math.floor(gen_rest / weight_color);
		color_rest = gen_rest % weight_color;

		rand_look = Math.floor(color_rest / weight_color);

//		rand_gen = getNth(id_no, 0);
//		rand_color = getNth(id_no, 1);
//		rand_look = getNth(id_no, 2);

//		document.write(rand_gen, rand_color, rand_look);




		who = boy_girl[rand_gen] + "/" + friends[rand_gen][rand_color][rand_look];
		
		document.write("<img src='" + who + "' />");
		document.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");


		// every time 5 friends show up
		if((i % 5) == 4) {
			document.write("<br />");

			// every time 10 friends show up, put line
			if((i % 10) == 9) {
				document.write("<br />");
				document.write("<img src='../images/line2_3.gif' />");
				document.write("<br /><br /><br />");
			}
		} 

	
		// replace unshown-list
		unshown = deleteNth(unshown, rand); // rand_th in unshown-list showed up!


	} // i-for loop

} // SmartRandShowAllBoysGirls











function helloWorld() {

	// the number of languages registered
	la = hello.length; // msg[0].length;
	
	hello_no = new Array();
	
	// the number of gender
	gen = boy_girl.length;

	color = boy_color.length;	// = girl_look.length

	// Fix smiling person of each group
	b_look = new Array(1, 2, 3); 				
	g_look = new Array(0, 2);

	// define
	boy = 0;
	girl = 1;


	// hello_no = (0, ... )
	for(i=0; i < la; i++) {
		hello_no.push(i);
	}


	document.write("<table border='0'>");

	for (i=0; i < la; i++) {

		// --- Who will say? ---

		rand_gen = Math.floor(Math.random() * gen);	// 0=boy, 1=girl
		
		// 0=aka, 1=ao, 2=kiiro, 3=kimidori, 4=midori, 5=mizu, 6=orange, 7=pink
		rand_color = Math.floor(Math.random() * color);

		{ // beginning ig if-else
			// boy or girl ?
			if (rand_gen == boy)
			{ //  boy
				num_rand_b_look = Math.floor(Math.random() * b_look.length);
				rand_b_look = b_look[num_rand_b_look]; // which look
				who = boy_girl[rand_gen] + "/" + boy_color[rand_color][rand_b_look];
			}
			else	
			{ // girl
				num_rand_g_look = Math.floor(Math.random() * g_look.length);
				rand_g_look = g_look[num_rand_g_look]; // which look
				who = boy_girl[rand_gen] + "/" + girl_color[rand_color][rand_g_look];
			}
		} // end of if-else



		// --- in what language ? ---

		rand = Math.floor(Math.random() * hello_no.length); 
		rand_hello = getNth(hello_no, rand);

		word  = "<font color='#0000ff'>" + getWord(rand_hello) + "</font>";
		prono = "<font color='#0000ff'>" + getProno(rand_hello) + "</font>";

		document.write(
						"<tr>" +

						"<td>" + "<img src='" + who + "' />" + "&nbsp;" +	" : " + "&nbsp;" + "</td>" +

						"<td>" + word + "</td>" +
						
						"<td></td>" +
						
						"<td>" + prono + "</td>" +						

						"<td>" + "&nbsp;&nbsp;&nbsp;&nbsp;" + " < " + getLang(rand_hello) + " >" + "</td>" + 

						"</tr>"
						);


		// every time 5, put break-line twice
		if((i % 5) == 4) {
			document.write("<tr>" + "<td>&nbsp;</td>" + "<td>&nbsp;</td>" + "<td>&nbsp;</td>" + "</tr>");
			document.write("<tr>" + "<td>&nbsp;</td>" + "<td>&nbsp;</td>" + "<td>&nbsp;</td>" + "</tr>");
		} 	


		// update hello_no
		hello_no = deleteNth(hello_no, rand);	 // said rand_th in hello_no


	} // i-for loop

	document.write("</table>");

} // helloWorld

