var TimeOut         = 300;
var currentLayer    = null;
var currentitem     = null;
var currentLayerNum = 0;
var noClose         = 0;
var closeTimer      = null;

function mopen(n) {
  var l  = document.getElementById("menu"+n);
  var mm = document.getElementById("mmenu"+n);
	
  if(l) {
    mcancelclosetime();
    l.style.visibility='visible';
    if(currentLayer && (currentLayerNum != n))
      currentLayer.style.visibility='hidden';
    currentLayer = l;
    currentitem = mm;
    currentLayerNum = n;			
  } else if(currentLayer) {
    currentLayer.style.visibility='hidden';
    currentLayerNum = 0;
    currentitem = null;
    currentLayer = null;
 	}
}

function mclosetime() {
  closeTimer = window.setTimeout(mclose, TimeOut);
}

function mcancelclosetime() {
  if(closeTimer) {
    window.clearTimeout(closeTimer);
    closeTimer = null;
  }
}

function mclose() {
  if(currentLayer && noClose!=1)   {
    currentLayer.style.visibility='hidden';
    currentLayerNum = 0;
    currentLayer = null;
    currentitem = null;
  } else {
    noClose = 0;
  }
  currentLayer = null;
  currentitem = null;
}

document.onclick = mclose; 

//listener load

function addEvent(elm,listener,fn){
	try{
		elm.addEventListener(listener,fn,false);
	}catch(e){
		elm.attachEvent("on"+listener,fn);
	}
}

//thum load

var souceURL    = null;
var souceLeng     = null;
var sharedAdress     = null;
var rootLeng     = null;
var rootAdress     = null;

function submenu(){
	souceURL = document.getElementById("Honda_logo").src;
	souceLeng = souceURL.length - 12;
	rootLeng = souceURL.length - 23;
	sharedAdress = souceURL.substring(0,souceLeng);
	rootAdress = souceURL.substring(0,rootLeng);
	
	//aryOff aryOn preload image
	aryAutoOff = new Array("sub_jazz_off.jpg","sub_accordeuro_off.jpg","sub_civic_off.jpg","sub_cr-v_off.jpg");
 aryAutoOn = new Array("sub_jazz_on.jpg","sub_accordeuro_on.jpg","sub_civic_on.jpg","sub_cr-v_on.jpg");
	
 prImgAutoOff= new Array();
 for (i=0; i<aryAutoOff.length; i++)
 {
	 prImgAutoOff[i] = new Image();
	 prImgAutoOff[i].src = sharedAdress + aryAutoOff[i];
 }
 prImgAutoOn= new Array();
 for (i=0; i<aryAutoOn.length; i++)
 {
	 prImgAutoOn[i] = new Image();
	 prImgAutoOn[i].src = sharedAdress + aryAutoOn[i];
 }
	
	//aryMotorOff aryMotorOn preload image
	aryMotorOff = new Array("sub_cb600f_off.jpg","sub_cb1000r_off.jpg","sub_cbr250r_off.jpg","sub_cbr600rr_off.jpg","sub_cbr1000rr_off.jpg","sub_vfr800x_off.jpg","sub_xl125v_off.jpg","sub_xl700v_off.jpg","sub_xr125l_off.jpg","sub_lead100_off.jpg","sub_pcx_off.jpg","sub_sh125i_off.jpg","sub_sh300i_off.jpg","sub_swt400_off.jpg","sub_crf50f_off.jpg","sub_crf150rb_off.jpg","sub_crf250r_off.jpg","sub_crf450r_off.jpg");
	aryMotorOn = new Array("sub_cb600f_on.jpg","sub_cb1000r_on.jpg","sub_cbr250r_on.jpg","sub_cbr600rr_on.jpg","sub_cbr1000rr_on.jpg","sub_vfr800x_on.jpg","sub_xl125v_on.jpg","sub_xl700v_on.jpg","sub_xr125l_on.jpg","sub_lead100_on.jpg","sub_pcx_on.jpg","sub_sh125i_on.jpg","sub_sh300i_on.jpg","sub_swt400_on.jpg","sub_crf50f_on.jpg","sub_crf150rb_on.jpg","sub_crf250r_on.jpg","sub_crf450r_on.jpg");
	
	prImgMotorOff= new Array();
 for (i=0; i<aryMotorOff.length; i++)
 {
	 prImgMotorOff[i] = new Image();
	 prImgMotorOff[i].src = sharedAdress + aryMotorOff[i];
 }
 prImgMotorOn= new Array();
 for (i=0; i<aryMotorOn.length; i++)
 {
	 prImgMotorOn[i] = new Image();
	 prImgMotorOn[i].src = sharedAdress + aryMotorOn[i];
 }
	
	//aryPowerOff aryPowerOn preload image
 aryPowerOff = new Array();
 aryPowerOn = new Array();
	
	prImgPowerOff= new Array();
 for (i=0; i<aryPowerOff.length; i++)
 {
	 prImgPowerOff[i] = new Image();
	 prImgPowerOff[i].src = sharedAdress + aryPowerOff[i];
 }
 prImgPowerOn= new Array();
 for (i=0; i<aryPowerOn.length; i++)
 {
	 prImgPowerOn[i] = new Image();
	 prImgPowerOn[i].src = sharedAdress + aryPowerOn[i];
 }
	
 document.getElementById("menu1").innerHTML="<a href='"+ rootAdress +"jazz/index.html' onMouseOver='swapImg(1, 1 ,\"Auto\");' onMouseOut='swapImg(0, 1 ,\"Auto\");'><img src='"+ sharedAdress +"sub_jazz_off.jpg' alt='JAZZ' width='129' height='127' name='swapAutoImg1' /></a><a href='"+ rootAdress +"accordeuro/index.html' onMouseOver='swapImg(1, 2 ,\"Auto\");' onMouseOut='swapImg(0, 2 ,\"Auto\");'><img src='"+ sharedAdress +"sub_accordeuro_off.jpg' alt='ACCORD EURO' width='129' height='127' name='swapAutoImg2' /></a><a href='"+ rootAdress +"civic/index.html' onMouseOver='swapImg(1, 3 ,\"Auto\");' onMouseOut='swapImg(0, 3 ,\"Auto\");'><img src='"+ sharedAdress +"sub_civic_off.jpg' alt='CIVIC' width='129' height='127' name='swapAutoImg3' /></a><a href='"+ rootAdress +"cr-v/index.html' onMouseOver='swapImg(1, 4 ,\"Auto\");' onMouseOut='swapImg(0, 4 ,\"Auto\");'><img src='"+ sharedAdress +"sub_cr-v_off.jpg' alt='CR-V' width='129' height='127' name='swapAutoImg4' /></a>";
	
 document.getElementById("menu2").innerHTML="<a href='"+ rootAdress +"motorcycles/cb600f/index.html' onMouseOver='swapImg(1, 1 ,\"Motor\");' onMouseOut='swapImg(0, 1 ,\"Motor\");'><img src='"+ sharedAdress +"sub_cb600f_off.jpg' alt='CB600F' width='129' height='127' name='swapMotorImg1' /></a><a href='"+ rootAdress +"motorcycles/cb1000r/index.html' onMouseOver='swapImg(1, 2 ,\"Motor\");' onMouseOut='swapImg(0, 2 ,\"Motor\");'><img src='"+ sharedAdress +"sub_cb1000r_off.jpg' alt='CB1000R' width='129' height='127' name='swapMotorImg2' /></a><a href='"+ rootAdress +"motorcycles/cbr250r/index.html' onMouseOver='swapImg(1, 3 ,\"Motor\");' onMouseOut='swapImg(0, 3 ,\"Motor\");'><img src='"+ sharedAdress +"sub_cbr250r_off.jpg' alt='CBR250R' width='129' height='127' name='swapMotorImg3' /></a><a href='"+ rootAdress +"motorcycles/cbr600rr/index.html' onMouseOver='swapImg(1, 4 ,\"Motor\");' onMouseOut='swapImg(0, 4 ,\"Motor\");'><img src='"+ sharedAdress +"sub_cbr600rr_off.jpg' alt='CBR600RR' width='129' height='127' name='swapMotorImg4' /></a><a href='"+ rootAdress +"motorcycles/cbr1000rr/index.html' onMouseOver='swapImg(1, 5 ,\"Motor\");' onMouseOut='swapImg(0, 5 ,\"Motor\");'><img src='"+ sharedAdress +"sub_cbr1000rr_off.jpg' alt='CBR1000RR' width='129' height='127' name='swapMotorImg5' /></a><a href='"+ rootAdress +"motorcycles/vfr800x/index.html' onMouseOver='swapImg(1, 6 ,\"Motor\");' onMouseOut='swapImg(0, 6 ,\"Motor\");'><img src='"+ sharedAdress +"sub_vfr800x_off.jpg' alt='VFR800X' width='129' height='127' name='swapMotorImg6' /></a><a href='"+ rootAdress +"motorcycles/xl125v/index.html' onMouseOver='swapImg(1, 7 ,\"Motor\");' onMouseOut='swapImg(0, 7 ,\"Motor\");'><img src='"+ sharedAdress +"sub_xl125v_off.jpg' alt='XL125V' width='129' height='127' name='swapMotorImg7' /></a><a href='"+ rootAdress +"motorcycles/xl700v/index.html' onMouseOver='swapImg(1, 8 ,\"Motor\");' onMouseOut='swapImg(0, 8 ,\"Motor\");'><img src='"+ sharedAdress +"sub_xl700v_off.jpg' alt='XL700V' width='129' height='127' name='swapMotorImg8' /></a><a href='"+ rootAdress +"motorcycles/xr125/index.html' onMouseOver='swapImg(1, 9 ,\"Motor\");' onMouseOut='swapImg(0, 9 ,\"Motor\");'><img src='"+ sharedAdress +"sub_xr125l_off.jpg' alt='XR125' width='129' height='127' name='swapMotorImg9' /></a><a href='"+ rootAdress +"motorcycles/lead100/index.html' onMouseOver='swapImg(1, 10 ,\"Motor\");' onMouseOut='swapImg(0, 10 ,\"Motor\");'><img src='"+ sharedAdress +"sub_lead100_off.jpg' alt='Lead100' width='129' height='127' name='swapMotorImg10' /></a><a href='"+ rootAdress +"motorcycles/pcx/index.html' onMouseOver='swapImg(1, 11 ,\"Motor\");' onMouseOut='swapImg(0, 11 ,\"Motor\");'><img src='"+ sharedAdress +"sub_pcx_off.jpg' alt='PCX' width='129' height='127' name='swapMotorImg11' /></a><a href='"+ rootAdress +"motorcycles/sh125i/index.html' onMouseOver='swapImg(1, 12 ,\"Motor\");' onMouseOut='swapImg(0, 12 ,\"Motor\");'><img src='"+ sharedAdress +"sub_sh125i_off.jpg' alt='SH125i' width='129' height='127' name='swapMotorImg12' /></a><a href='"+ rootAdress +"motorcycles/sh300i/index.html' onMouseOver='swapImg(1, 13 ,\"Motor\");' onMouseOut='swapImg(0, 13 ,\"Motor\");'><img src='"+ sharedAdress +"sub_sh300i_off.jpg' alt='SH300i' width='129' height='127' name='swapMotorImg13' /></a><a href='"+ rootAdress +"motorcycles/swt400/index.html' onMouseOver='swapImg(1, 14 ,\"Motor\");' onMouseOut='swapImg(0, 14 ,\"Motor\");'><img src='"+ sharedAdress +"sub_swt400_off.jpg' alt='SW-T400' width='129' height='127' name='swapMotorImg14' /></a><a href='"+ rootAdress +"motorcycles/crf50f/index.html' onMouseOver='swapImg(1, 15 ,\"Motor\");' onMouseOut='swapImg(0, 15 ,\"Motor\");'><img src='"+ sharedAdress +"sub_crf50f_off.jpg' alt='CRF50F' width='129' height='127' name='swapMotorImg15' /></a><a href='"+ rootAdress +"motorcycles/crf150rb/index.html' onMouseOver='swapImg(1, 16 ,\"Motor\");' onMouseOut='swapImg(0, 16 ,\"Motor\");'><img src='"+ sharedAdress +"sub_crf150rb_off.jpg' alt='CRF150RB' width='129' height='127' name='swapMotorImg16' /></a><a href='"+ rootAdress +"motorcycles/crf250r/index.html' onMouseOver='swapImg(1, 17 ,\"Motor\");' onMouseOut='swapImg(0, 17 ,\"Motor\");'><img src='"+ sharedAdress +"sub_crf250r_off.jpg' alt='CRF250R' width='129' height='127' name='swapMotorImg17' /></a><a href='"+ rootAdress +"motorcycles/crf450r/index.html' onMouseOver='swapImg(1, 18 ,\"Motor\");' onMouseOut='swapImg(0, 18 ,\"Motor\");'><img src='"+ sharedAdress +"sub_crf450r_off.jpg' alt='CRF450R' width='129' height='127' name='swapMotorImg18' /></a>";

 //document.getElementById("menu3").innerHTML="";
}

//swap image
function swapImg(mode, num, cate)
{
	var aryMode = (mode == 0) ? "Off" : "On";
	var aryCate = cate;
	var aryName = "ary" + aryCate + aryMode;
	if(mode == 0) document["swap" + aryCate + "Img"+ num].src = sharedAdress + eval(aryName)[num-1];
	else if(mode == 1) document["swap" + aryCate + "Img" + num].src = sharedAdress + eval(aryName)[num-1];
}
