/*********************************************
 *                [[ Node  ]]                *
 *                                           *
 *     2001.01.01                            *
 *     update 2002.10.07                     *
 *     Programed by YIL Akira Yamanouchi     *
 *     Copyright (c) 2002 Akira Yamanouchi   *
 *********************************************/

function n_data(name,disp,alt,dir) {
	this.name = name;
	this.disp = disp;
	this.alt = alt;
	this.dir = dir;
}

var n_info = new Array();
var n_num = 0;

var h_image = new Array();
var l_image = new Array();

var i_form = 0;
var i_image = 1;
var mode;
var work_target = "work";
var i_button_ext = "gif";

function initialize_node() {
	work_target = "work";
	i_button_ext = "gif";
	n_num = 0;
}

function set_work_target(target) {
	work_target = target;
}

function set_button_ext(ext) {
	i_button_ext = ext;
}

function set_node(name,disp,alt,dir) {
	n_info[n_num++] = new n_data(name,disp,alt,dir);
}

function create_form_button() {
	for(i=0;i<n_num;i++) {
		if( top.i_lang == "j" ) {
			document.write("<input type='button' name='b_",n_info[i].name,"' value='",n_info[i].disp,"' onClick=\"node_branch('",n_info[i].name,"')\"> ");
		} else {
			document.write("<input type='button' name='b_",n_info[i].name,"' value='",n_info[i].disp,"' onClick=\"node_branch('",n_info[i].name,"')\"> ");
		}
	}
	mode = i_form;
}

function create_button() {
	for(i=0;i<n_num;i++) {
		l_image[i] = new Image();
		h_image[i] = new Image();
		if( top.i_lang == "j" ) {
			l_image[i].src = "image/f_" + n_info[i].name + "." + i_button_ext;
			h_image[i].src = "image/f_" + n_info[i].name + "_h." + i_button_ext;
		} else {
			l_image[i].src = "image/f_" + n_info[i].name + "-e." + i_button_ext;
			h_image[i].src = "image/f_" + n_info[i].name + "-e_h." + i_button_ext;
		}
	}
	for(i=0;i<n_num;i++) {
		document.write("<a href=\"JavaScript:node_branch('",n_info[i].name,"')\" onMouseOver=\"return highlight('",n_info[i].name,"')\" onMouseOut=\"return lowlight('",n_info[i].name,"')\"><img src=\"",l_image[i].src,"\" border=\"0\" hspace=\"0\" vspace=\"0\" name=\"",n_info[i].name,"\" alt=\"",n_info[i].alt,"\" width=\"",b_width,"\" height=\"",b_height,"\"></a>\n");
	}
	mode = i_image;
}

function reset_button() {
	if( mode == i_form ) {return true;}
	if( top.i_node != "" ) {
		for(i=0;i<n_num;i++) {
			if( n_info[i].name == top.i_node ) {
				break;
			}
		}
		if( i < n_num ) {
			document.images[top.i_node].src = l_image[i].src;
		}
	}
	return true;
}

function press_button() {
	if( mode == i_form ) {return true;}
	if( top.i_node != "" ) {
		for(i=0;i<n_num;i++) {
			if( n_info[i].name == top.i_node ) {
				break;
			}
		}
		if( i < n_num ) {
			document.images[top.i_node].src = h_image[i].src;
		}
	}
	return true;
}

function highlight(node) {
	if( mode == i_form ) {return true;}
	if( node != top.i_node ) {
		for(i=0;i<n_num;i++) {
			if( n_info[i].name == node ) {
				break;
			}
		}
		if( i < n_num ) {
			document.images[node].src = h_image[i].src;
		}
	}
	window.status = "Jump to " + node;
	return true;
}

function lowlight(node) {
	if( mode == i_form ) {return true;}
	if( node != top.i_node ) {
		for(i=0;i<n_num;i++) {
			if( n_info[i].name == node ) {
				break;
			}
		}
		if( i < n_num ) {
			document.images[node].src = l_image[i].src;
		}
	}
	return true;
}

function node_branch(selected_switch) {
	for(i=0;i<n_num;i++) {
		if( n_info[i].name == selected_switch ) {
			break;
		}
	}
	if( i < n_num ) {
		if( work_target == "work" ) {
			indi = n_info[i].dir.indexOf("http://",0);
			if( indi == 0 ) {
				parent.work.location.href = n_info[i].dir;
			} else {
				parent.work.location.href = home_url + "/" + n_info[i].dir;
			}
		} else if( work_target == "subwork" ) {
			parent.subwork.location.href = home_url + "/" + n_info[i].dir;
		}
	}
	reset_button();
	top.i_node = selected_switch;
	press_button();
	window.defaultStatus = "Current Node = " + selected_switch;
}

function change_main_node(path,node) {
	for(i=0;i<n_num;i++) {
		if( n_info[i].name == node ) {
			break;
		}
	}
	if( i < n_num ) {
		top.work.location.href = path + n_info[i].dir;
	}
	reset_button();
	top.i_node = node;
	press_button();
	window.defaultStatus = "Current Node = " + node;
}

