// JavaScript Document

onload = function() { 
//---------------------------------------------------------------------- 

function PopupView(id) { 
if (!document.getElementById) return; 

var node = document.getElementById(id); 
if (node) PopupView.initializer.call(node.childNodes); 
} 

PopupView.initializer = function() { 
for (var i = 0, I = this.length; i < I; i++) { 
PopupView.switcher.call(this[i].childNodes, 'none'); 

this[i].onmouseover = function() { 
PopupView.switcher.call(this.childNodes, 'block'); 
} 

this[i].onmouseout = function() { 
PopupView.switcher.call(this.childNodes, 'none'); 
} 
} 
} 

PopupView.switcher = function(displayValue) { 
for (var i = 0, I = this.length; i < I; i++) 
if (this[i].nodeName.match(/[OU]L/)) { 
this[i].style.display = displayValue; 
this[i].style.position = 'absolute'; 
} 
} 

// ここに ul/ol 要素の id を指定する（いくつでも指定可） 

new PopupView('navi-menu01'); 

//---------------------------------------------------------------------- 
} 


var openID;
$(function(){
	var imgsrc = $(".tab-box .button a img").attr("src");
	var dot = imgsrc.lastIndexOf('.');
	var imgsrc_ro = imgsrc.substr(0, dot) + '_on' + imgsrc.substr(dot, 4);
			
	$(".tab-box").each(function(){
		var thisID = $(this).attr("id");
		var bgImgs = new Image();
		bgImgs.src = "top_img/base2_" + thisID + ".gif";
	
		$(this).find(".button").bind("mouseover", function(){
			resetButton();
			$(this).find("img").attr("src",imgsrc_ro);
			if(openID != ""){ 
				if($("div#" + thisID + "Tab").css("display")=="none"){
					$("div#" + openID + "Tab").hide();
					openID = "";
					$("div.explanation-box").css({
						height:'210px',
						background: "url(top_img/base2_"+ thisID +".gif)" 
						});
					$("div#" + thisID + "Tab").slideDown();
					openID = thisID;
 				}
			}else{
				$("div.explanation-box").css({
					height:'210px',
					background: "url(top_img/base2_"+ thisID +".gif) "
					});
				$("div#" + thisID + "Tab").slideDown();
				openID = thisID;
 			}
		});
		$(this).find(".button").bind("click", function(){
			resetButton();
			if(openID == thisID){ 
				$("div#" + openID + "Tab").slideUp("normal", function(){ $("div.explanation-box").removeAttr("style"); });
				openID = "";
			}else if(openID != ""){ 
				$("div#" + openID + "Tab").hide();
				openID = "";
				$("div.explanation-box").css({
					height:'210px',
					background: "url(top_img/base2_"+ thisID +".gif)" 
					});
				$("div#" + thisID + "Tab").slideDown();
				openID = thisID;
				$(this).find("img").attr("src",imgsrc_ro);
			}else{
				$("div.explanation-box").css({
					height:'210px',
					background: "url(top_img/base2_"+ thisID +".gif) "
					});
				$("div#" + thisID + "Tab").slideDown();
				openID = thisID;
				$(this).find("img").attr("src",imgsrc_ro);
			}
		});
	});
});
function resetButton(){
	$(".tab-box").each(function(){
		var imgsrc =  $(this).find(".button a img").attr("src");
		$(".tab-box .button a img").attr("src",imgsrc.replace("_on",""));
	});
}


