var timer;

function Active(){
	$(document).ready(function(){
		var org_href = location.href;

		var now_href="";
			now_href = org_href.replace(/http\:\/\/[^\/]+\//, "/");
			now_href = now_href.replace(/\/([^/]+)\/([^/]+)\/.+$/, "/$1/$2/");

		var now_file = "";
			now_file = org_href.replace(/\#.*$/, "");
			now_file = now_file.match(/([a-zA-Z0-9_\-]+\.[a-z]+)$/);
			if(now_file) now_file = now_file[0];

		var now_href_dir = "";
			now_href_dir = org_href.replace(/http\:\/\/[^\/]+\//, "/");
			now_href_dir = now_href_dir.replace(/\#.*$/, "");
			now_href_dir = now_href_dir.replace(/([a-zA-Z0-9_\-]+\.[a-z]+)$/, "");
			now_href_dir = now_href_dir.replace(/^\/[a-z]+\//, "/");

		$("#pulldown > li > a").each(function(){
			var menu_href = "";
			menu_href = $(this).attr("href");
			menu_href =	menu_href.replace(/\/([^/]+)\/([^/]+)\/.+$/, "/$1/$2/");
			menu_href =	menu_href.replace(/^\/[^/]*\//, "/");
			menu_href =	menu_href.replace(/([a-zA-Z0-9_\-]+\.[a-z]+)$/, "");

			if(now_href_dir == menu_href){
				$("img", this).removeClass("ro");
				var src = $("img", this).attr("src");
				var src_on = src.replace(/^(.+)(\.[a-z]+)$/, "$1_on$2");
				$("img", this).attr("src", src_on);
			}
		});

		$("#pulldown li li a").each(function(){
			var menu_href_org = $(this).attr("href");

			menu_href = menu_href_org.replace(/.*\/([a-zA-Z0-9\-\_]+)\.[a-zA-Z0-9\-\_\#\=]+$/, "$1");

			menu_dir = menu_href_org.replace(/.*\/([a-zA-Z0-9\-\_]+)\/([a-zA-Z0-9\-\_]+)\.[a-zA-Z0-9\-\_\#\=]+$/, "$1");

			var page_id = $("body").attr("id");

			var my_dir = location.href;
			my_dir = my_dir.replace(/\#.*$/, "");
			my_dir = my_dir.replace(/^http\:\/\/[^/]*\/[^/]*\//, "");
			my_dir = my_dir.replace(/\/$/, "");
			my_dir = my_dir.replace(/\/([a-zA-Z0-9_\-]+\.[a-z]+)$/, "");

			if(page_id == menu_href && menu_dir == my_dir){
				$("img", this).removeClass("ro");
				var src = $("img", this).attr("src");
				var src_on = src.replace(/^(.+)(\.[a-z]+)$/, "$1_on$2");
				$("img", this).attr("src", src_on);
			}

			//*/microft/gallery/
			if(now_href_dir == '/microft/gallery/'){
				var selector = "#pulldown li li a[href$='/microft/gallery.html'] img";
				$(selector).removeClass("ro");
				var src = $(selector).attr("src");
				var src_on = src.replace(/^(.+)(\.[a-z]+)$/, "$1_on$2");
				$(selector).attr("src", src_on);
				return false;
			}
			//*/fourthirds/gallery/
			if(now_href_dir == '/fourthirds/gallery/'){
				var selector = "#pulldown li li a[href$='/fourthirds/gallery.html'] img";
				$(selector).removeClass("ro");
				var src = $(selector).attr("src");
				var src_on = src.replace(/^(.+)(\.[a-z]+)$/, "$1_on$2");
				$(selector).attr("src", src_on);
				return false;
			}
		});

		$(".contents_menu a").each(function(){
			var menu_href_org = $(this).attr("href");

			menu_href = menu_href_org.replace(/.*\/([a-zA-Z0-9\-\_]+)\.[a-zA-Z0-9\-\_\#\=]+$/, "$1");

			menu_dir = menu_href_org.replace(/.*\/([a-zA-Z0-9\-\_]+)\/([a-zA-Z0-9\-\_]+)\.[a-zA-Z0-9\-\_\#\=]+$/, "$1");

			var page_id = $("body").attr("id");

			var my_dir = location.href;
			my_dir = my_dir.replace(/\#.*$/, "");
			my_dir = my_dir.replace(/^http\:\/\/[^/]*\/[^/]*\//, "");
			my_dir = my_dir.replace(/\/$/, "");
			my_dir = my_dir.replace(/\/([a-zA-Z0-9_\-]+\.[a-z]+)$/, "");

			if(page_id == menu_href && menu_dir == my_dir){
				$("img", this).removeClass("ro");
				var src = $("img", this).attr("src");
				var src_on = src.replace(/^(.+)(\.[a-z]+)$/, "$1_on$2");
				$("img", this).attr("src", src_on);
			}

		});
		function GalleryActive(){
			var pathname = location.pathname;
			var page_id = $("body").attr("id");

			var parent_dir = pathname.match(/\/[a-z]{2}\/([^/]+)/);

			if(page_id == 'gallery'){
				var pullparent_src = $("#pulldown .parent[href^=" + parent_dir[0] + "] img").attr("src");
				if(!pullparent_src.match(/_on\.([a-z]+)$/)){
					var pullparent_src_on = pullparent_src.replace(/^(.+)(\.[a-z]+)$/, "$1_on$2");
					$("#pulldown .parent[href^=" + parent_dir[0] + "] img").attr("src", pullparent_src_on);
				}

				$(".contents_menu a[href$='gallery.html'] img").removeClass("ro");
				var src = $(".contents_menu a[href$='gallery.html'] img").attr("src");
				if(!src.match(/_on\.([a-z]+)$/)){
					var src_on = src.replace(/^(.+)(\.[a-z]+)$/, "$1_on$2");
					$(".contents_menu a[href$='gallery.html'] img").attr("src", src_on);
				}
			}
		}
		GalleryActive();

		$(".contents_linemenu .ins a").each(function(){
			var menu_href_line = $(this).attr("href");
			menu_href_line = menu_href_line.match(/([a-zA-Z0-9_\-]+\.[a-z]+)$/);
			menu_href_line = menu_href_line[0];
			if(!now_file) now_file = 'index.html';
			if(now_file == menu_href_line){
				$(this).addClass("ac");
			}
			//*lens_technology.html
			//if(now_file == 'lens_technology.html') $(".contents_linemenu .ins a[href$='lens_knowledge.html']").addClass("ac");
		});

		//var test = $("body").get(0).firstChild.nodeValue;
	});
};


Active();
