MJL.event.add(window, "load", function() {	

	function globalCurrent(){
		var gNavi = document.getElementById("nav-global");
		if(!gNavi){return false;}
		if(document.getElementById("lyt-mainvisual")){return false;}
		
		var current_directory = location.pathname.match(/[^\/](.[^\/]+)/)[0];
		var exclusionDirectory = ['/work/workInoffice/'];
		var urlBind = [
				["/donate_bin/shiryo.php" , "/donate/index.html"],
				["/donate_bin/shiryoConf.php" , "/donate/index.html"],
				["/donate_bin/shiryoRegist.php" , "/donate/index.html"],
				["/donate_bin/inquiry.php" , "/donate/index.html"],
				["/donate_bin/inquiryConf.php" , "/donate/index.html"],
				["/donate_bin/inquiryRegist.php" , "/donate/index.html"]
			];
		var url = window.location.pathname.replace(/index\.html?/ , "");
		
		var gNavi_li = gNavi.getElementsByTagName("li");
		var gNavi_li_length = gNavi_li.length;
		
		for (var i=0; i<gNavi_li_length; i++) {
			var navi_directory = gNavi_li[i].getElementsByTagName("a")[0].href.replace(/(https?|ftp):\/+([^:\/]+)+/,"").match(/[^\/](.[^\/]+)/)[0];
			if(current_directory === navi_directory){
				for(var j=0; j<exclusionDirectory.length; j++){
					if(window.location.pathname.replace(/index\.html?/ , "") == exclusionDirectory[j]){ return false; }
				}
				MJL.addClassName(gNavi_li[i], "active");
				gNavi_li[i].getElementsByTagName("img")[0].src = gNavi_li[i].getElementsByTagName("img")[0].src.replace(/([^\/]+)(\.[^\.]+)$/,"$1_o$2");
			}
		}
		
		// 資料請求、お問い合わせページをグロナビの『寄付・支援』と紐付けカレント表示
		for(var i=0; i<urlBind.length; i++){
			if(url == urlBind[i][0]){
				for(var j=0; j<gNavi_li_length; j++){
					var bindDirectory = gNavi_li[j].getElementsByTagName("a")[0].href;
					if(bindDirectory.lastIndexOf(urlBind[i][1]) >=0){
						MJL.addClassName(gNavi_li[j], "active");
						gNavi_li[j].getElementsByTagName("img")[0].src = gNavi_li[j].getElementsByTagName("img")[0].src.replace(/([^\/]+)(\.[^\.]+)$/,"$1_o$2");
					}
				}
			}
		}
		
	}
	
	function localCurrent(){
		var lNavi = document.getElementById("nav-local");
		if(!lNavi){return false;}
		
		var body_classes = document.body.className.split(" ");
		var body_classes_length = body_classes.length;
		
		var lNavi_li = lNavi.getElementsByTagName("li");
		var lNavi_li_length = lNavi_li.length;
		
		var active_page1;
		var active_page2;
		
		var urlBind = [
				["/donate_bin/inquiry.php" , "/donate_bin/inquiry.php"],
				["/donate_bin/inquiryConf.php" , "/donate_bin/inquiry.php"],
				["/donate_bin/inquiryRegist.php" , "/donate_bin/inquiry.php"]
			];
		var url = window.location.pathname.replace(/index\.html?/ , "");
		
		for(var i=0; i<urlBind.length; i++){
			if(url == urlBind[i][0]){
				for(var j=0; j<lNavi_li_length; j++){
					var bindFilename = lNavi_li[j].getElementsByTagName("a")[0].href;
					if(bindFilename.lastIndexOf(urlBind[i][1]) >=0){
						MJL.addClassName(lNavi_li[j], "active");
						lNavi_li[j].getElementsByTagName("img")[0].src = lNavi_li[j].getElementsByTagName("img")[0].src.replace(/([^\/]+)(\.[^\.]+)$/,"$1_o$2");
						return false;
					}
				}
			}
		}
		
		for (var j = 0; j < body_classes_length; j++) {
			if(body_classes[j].match(/active-.+$/) !== null){
				active_page1 = body_classes[j].replace(/active-/,"");
			}
		}
		
		for (var k = 0; k < lNavi_li_length; k++) {
			var active_filename = lNavi_li[k].getElementsByTagName("a")[0].href.match(/[^\/]+\.[^\.]+$/);
	
			if ((active_filename == "index.php") || (active_filename == "index.html")) {
				active_page2 = lNavi_li[k].getElementsByTagName("a")[0].href.match(/[^\/]+\/[^\/]+$/).toString().replace(/\/.+/,"");			
			}
			else if(active_filename === null) {
				active_page2 = lNavi_li[k].getElementsByTagName("a")[0].href.match(/([^\/]+)\/$/)[0].toString().replace("/","");
			}else if(active_filename !== null){
				active_page2 = active_filename.toString().split(".")[0];
			}
			
			if(active_page1 == active_page2){		
				MJL.addClassName(lNavi_li[k], "active");
				lNavi_li[k].getElementsByTagName("img")[0].src = lNavi_li[k].getElementsByTagName("img")[0].src.replace(/([^\/]+)(\.[^\.]+)$/,"$1_o$2");
			}
		}
	}
	
	globalCurrent();
	localCurrent();

    MJL.enable.heightEqualizer("equalize");
    MJL.enable.rollover("roll",{disable:"active"});
});

MJL.event.add(window, "load", function() {
	
    var mainvisual = document.getElementById("lyt-mainvisual");
	var emargency = document.getElementById("visual-emergency");
	if(!mainvisual){return false;}
	if(emargency){return false;}
	var visuals = MJL.getElementsByClassName(mainvisual, "visual");
	var visuals_length = visuals.length;
	
	if(visuals_length === 1){return false;}
	
	/*  param setting  */
	//image count
	var count = 0;
	//alpha interval
	var speed_1 = 100;
	//repeat interval
	var speed_2 = 5000;
	
	function changeAlpha(obj,pts){
		if (MJL.ua.trident) {
			obj.style.filter = 'alpha(opacity=' + (pts * 10) + ')';
		}else if(MJL.ua.gecko){
			obj.style.MozOpacity = pts / 10;
		}else{
			obj.style.opacity = pts / 10;
		}
	}
	
	function anime_alpha(){
		
		for (var i=0; i<visuals_length; i++) {
			if(i !== count && i !== (count + 1)){
				visuals[i].style.zIndex = 0;
			}
		}
		
		var opac_mius = 10;
		var opac_plus = 0;
		var next_visuals;
		
		if(count === visuals_length -1){
			next_visuals = visuals[0];
		}else{
			next_visuals = visuals[count + 1];
		}
		
		visuals[count].style.zIndex = 2;
		next_visuals.style.zIndex = 3;

		changeAlpha(next_visuals, 0);
	
		var alphaTimer = setInterval(function(){
			
			changeAlpha(visuals[count], opac_mius);
			changeAlpha(next_visuals, opac_plus);
			
			opac_mius--;
			opac_plus++;
			
			if(opac_mius < 0 && opac_plus > 10){
				opac_mius = 10;
				opac_plus = 0;
				count++;
				clearInterval(alphaTimer);
				anime_repeater();
			}
			if(count === visuals_length){

				count = 0;
			}
		}, speed_1);
	}

	function anime_repeater(){	
		var runTimer = setTimeout(function(){
			anime_alpha();
			clearTimeout(runTimer);		
		}, speed_2);
		
	}
	
	anime_repeater();
	
});
