// current enabled / disabled = false;
var menuCurrent = true;

// rollOut enabled / disabled = false;
var menuRollOut = true;

var menuImages = new Object;
var rollOverObj = new Object();
var menuRollOverPreloads = new Array();
var menuRollOutPreloads = new Array();

function nv_onload(){
	var d = window.document;
	var aObjects = d.getElementsByTagName("a");
	for (i=0;i<aObjects.length;i++) {
		if(aObjects[i].className == "menu"){
			
			//alert( aObjects[i].firstChild);

			var defaultImagePath = aObjects[i].firstChild.src.split('/')[aObjects[i].firstChild.src.split('/').length-1];
			var currentImagePath = defaultImagePath.replace('_none_','_now_');
			var rolloverImagePath = defaultImagePath.replace('_none_','_over_');
			var rolloutImagePath = defaultImagePath; //.replace('_none_','_out_');
			if(location.href == aObjects[i].href && (menuCurrent)){
				aObjects[i].firstChild.src = aObjects[i].firstChild.src.replace(defaultImagePath,currentImagePath);
				aObjects[i].firstChild.className = "now";
			}
			else {
	//	alert(rolloverImagePath);
	
				menuRollOverPreloads[i] = new Image;
				menuRollOverPreloads[i].src = "http://www.isep.or.jp/dev/wp-content/themes/isep_theme/images/common/" + rolloverImagePath;
				if(menuRollOut){
					menuRollOutPreloads[i] = new Image;
					menuRollOutPreloads[i].src ="http://www.isep.or.jp/dev/wp-content/themes/isep_theme/images/common/" + rolloutImagePath;
				}
				
			}
		}
	}
	$("a.menu").mouseover(function(){
		nv_over(this);
	});
	$("a.menu").mouseout(function(){
		nv_out(this);
	});
}

function nv_over(obj){
	if(obj.firstChild.src.indexOf('_now_') == -1){
		var defaultImagePath = obj.firstChild.src.split('/')[obj.firstChild.src.split('/').length-1];
		if(defaultImagePath.indexOf('_out_') > -1)
			var currentImagePath = defaultImagePath.replace('_out_','_over_');
		else
			var currentImagePath = defaultImagePath.replace('_none_','_over_');
		obj.firstChild.src = obj.firstChild.src.replace(defaultImagePath,currentImagePath);
	}
}

function nv_out(obj){
	if(obj.firstChild.src.indexOf('_now_') == -1){
		var defaultImagePath = obj.firstChild.src.split('/')[obj.firstChild.src.split('/').length-1];
		if(menuRollOut)
			var currentImagePath = defaultImagePath.replace('_over_','_none_');
		else
			var currentImagePath = defaultImagePath.replace('_over_','_none_');
		obj.firstChild.src = obj.firstChild.src.replace(defaultImagePath,currentImagePath);
	}
}



$(document).ready(nv_onload);




var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

function jsddm_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}

$(document).ready(function()
{	$('#hmul > li').bind('mouseover', jsddm_open);
	$('#hmul > li').bind('mouseout',  jsddm_timer);});

document.onclick = jsddm_close;


