﻿/////////////////////////////////////////////////////////////////////////////
// Class : brother_section_navigation_com2
// Comments : 
/////////////////////////////////////////////////////////////////////////////

function brother_section_navigation_com2( imageRoot )
{
	this.m_imageRoot  = imageRoot;
	this.m_NavPath    = g_navNode_Path;
	
	this.m_act_image = new Array();
	this.m_act_image["top"]                     = "/img/secNaviPtop_act.gif";
	this.m_act_image["Overview"]                = "/img/secNaviPpre_act.gif";
	this.m_act_image["Specifications"]          = "/img/secNaviPspe_act.gif";
	this.m_act_image["option"]                  = "/img/secNaviPopt_act.gif";
	this.m_act_image["photo"]                   = "/img/secNaviPpic_act.gif";
	this.m_act_image["spec_model"]              = "/img/secNaviPspeMwP_act.gif";
	this.m_act_image["accessory"]               = "/img/secNaviPacc_act.gif";
	this.m_act_image["download"]                = "/img/secNaviPdown_act.gif";
	this.m_act_image["service"]                 = "/img/secNaviPser_act.gif";
	this.m_act_image["Inquiry"]                 = "/img/secNaviPexaL_act.gif";
	this.m_act_image["Machining example index"] = "/img/secNaviPexa_act.gif";
	this.m_act_image["Machining performance"]   = "/img/secNaviPper_act.gif";
	this.m_act_image["cnc"]                     = "/img/secNaviPwcn_act.gif";
	this.m_act_image["accessory"]               = "/img/secNaviPacc2_act.gif";
	
	this.m_of_image = new Array();
	this.m_of_image["top"]                      = "/img/secNaviPtop_of.gif";
	this.m_of_image["Overview"]                 = "/img/secNaviPpre_of.gif";
	this.m_of_image["Specifications"]           = "/img/secNaviPspe_of.gif";
	this.m_of_image["option"]                   = "/img/secNaviPopt_of.gif";
	this.m_of_image["photo"]                    = "/img/secNaviPpic_of.gif";
	this.m_of_image["spec_model"]               = "/img/secNaviPspeMwP_of.gif";
	this.m_of_image["accessory"]                = "/img/secNaviPacc_of.gif";
	this.m_of_image["download"]                 = "/img/secNaviPdown_of.gif";
	this.m_of_image["service"]                  = "/img/secNaviPser_of.gif";
	this.m_of_image["Inquiry"]                  = "/img/secNaviPexaL_of.gif";
	this.m_of_image["Machining example index"]  = "/img/secNaviPexa_of.gif";
	this.m_of_image["Machining performance"]    = "/img/secNaviPper_of.gif";
	this.m_of_image["cnc"]                      = "/img/secNaviPwcn_of.gif";
	this.m_of_image["accessory"]                = "/img/secNaviPacc2_of.gif";
	
	this.m_lv_top = 3;
	
	brother_section_navigation_com2.prototype.Display = brother_section_navigation_com2_Display;
	brother_section_navigation_com2.prototype.DisplayNode = brother_section_navigation_com2_DisplayNode;
	
}

function isChildOf( node, parentId ){
	
	while( node.m_parent != null ){
		
		if( node.m_id == parentId ){
			return true;
		}
		
		node = node.m_parent;
		
	}
	
	return false;
	
}


function findNodeById( node, id ){
	
	var result = null;
	
	if( node.m_id == id ){
		return node;
	}
	else{
		
		for( var i = 0; i < node.m_subNodes.length; i++ )
		{
			result = this.findNodeById(node.m_subNodes[i], id );
			
			if( result != null ){
				return result;
			}
			
		}
		return null;
	}
	
}


function brother_section_navigation_com2_Display( node )
{
	
	var navRoot = null;
	
	if( this.m_NavPath.length >= this.m_lv_top ){
		navRoot = findNodeById( node, this.m_NavPath[this.m_lv_top] );
	}
	
	if( navRoot != null ){
		
		var ds;
		var di;
		
		ds = new Array();
		di = 0;
		ds[di++] = '<table border="0" cellspacing="0" cellpadding="0" bgcolor="#636563">';
		ds[di++] = '<tr>';
		ds[di++] = '<td>';
		ds[di++] = '<img src="' + this.m_imageRoot + '/img/secNavi00_of.gif" width="24" height="41">';
		ds[di++] = '</td>';
		document.write(ds.join(''));
		
		this.DisplayNode( navRoot );
		
		ds = new Array();
		di = 0;
		ds[di++] = '<td>';
		ds[di++] = '<img src="' + this.m_imageRoot + '/img/secNavi06.gif" width="22" height="41">';
		ds[di++] = '</td>';
		ds[di++] = '</tr>';
		ds[di++] = '</table>';
		document.write(ds.join(''));
		
	}
	else{
		
		document.write( "Error: Can't find navigation root" );
		
	}
}


function brother_section_navigation_com2_DisplayNode( node )
{
	
	var bSelected = false;
	
	if (this.m_NavPath.length > 0 )
	{
		if( this.m_NavPath.length <= ( this.m_lv_top + 1 ) ){
			bSelected = this.m_NavPath[this.m_NavPath.length - 1] == node.m_id;
		}
		else{
			bSelected = isChildOf( node, this.m_NavPath[ this.m_lv_top + 1 ] );
		}
	}
	
	
	var ds = new Array();
	var di = 0;
	
	if( bSelected ){
		
		ds[di++] = '<td>';
		ds[di++] = '<table border="0" cellspacing="0" cellpadding="0">';
		ds[di++] = '<tr id="IMENU1_BACK_AC">';
		ds[di++] = '<td height="23"><font id="IMENU1_FONT_AC"><IMG src="' + this.m_imageRoot + this.m_act_image[ node.m_level == this.m_lv_top ? "top" : node.m_label ] + '" border="0" name="bwsmnACT0" alt="' + node.m_label + '" width="112" height="41"></font></td>';
		ds[di++] = '</tr>';
		ds[di++] = '</table>';
		ds[di++] = '</td>';
		
	} else {
		
		ds[di++] = '<td>';
		ds[di++] = '<table border="0" cellspacing="0" cellpadding="0">';
		ds[di++] = '<tr id="IMENU10_BACK_OF" onMouseOver="styleChange(this,\'IMENU1_BACK_ON\')" onMouseOut="styleChange(this,\'IMENU1_BACK_OF\')">';
		ds[di++] = '<td height="23"><a href="' + node.m_href + '" onMouseOut="return secNaviMouseOut(bwsmn' + node.m_id + ')" onMouseOver="return secNaviMouseOver(bwsmn' + node.m_id + ')" target="_top" class="IMENU1_LINK"><IMG src="' + this.m_imageRoot + this.m_of_image[ node.m_level == this.m_lv_top ? "top" : node.m_label ] + '" border="0" name="bwsmn' + node.m_id + '" alt="' + node.m_label + '" width="112" height="41"></a></td>';
		ds[di++] = '</tr>';
		ds[di++] = '</table>';
		ds[di++] = '</td>';
		
	}
	
	document.write(ds.join(''));
	
	for (var i = 0; i < node.m_subNodes.length; i++)
	{
		this.DisplayNode(node.m_subNodes[i]);
	}
	
}





//---- image swap(over) ----
function secNaviMouseOver(o){
    o.src = o.src.replace(/_of/i,'_on')
    return true;
}

//---- image swap(out) ----
function secNaviMouseOut(o){
    o.src = o.src.replace(/_on/i,'_of')
    return true;
}

//---- STYLE ID Chenge ----
function styleChange(o,id){
    o.id=id;
        return true;
}
