$(function(){

var isMSIE = /*@cc_on!@*/false;

if (document.URL.match(/http:\/\/(([^.]*)[^\/]*).*?([^\/]*)\.([^.\/#]*)(#?.*)$/)) {
	server = RegExp.$1;
	host = RegExp.$2;
	file = RegExp.$3;
	ext = RegExp.$4;
	myanchor = RegExp.$5;
	if (!file){
		file = "index";
	}
}
myurl = document.URL.replace(/#.*$/,"");
server = /http[s]?:\/\/([^.]*[^\/]*)/.test(document.URL) ? RegExp.$1 : "";

	AllAnchor = $("a");
	for (var i = 0; i < AllAnchor.length; i++) {
		AllAnchor.eq(i).addClass(AllAnchor.eq(i).attr("href").replace(/.html/ig , "").replace(/#/ig , ""));
	}
	
	$("#faq2 > ul > li").after("<div class='buttonbox f12'><a href='#top'>ページの一番上に戻る</a></div>");
	
	
	
	$("nav").addClass(file);
	if($("#main-nav").is(".photo")){
		$("#main-nav").removeClass();
		$("#main-nav").addClass("photo");
	}
	if($("#main-nav").is(".ishima") || $("#main-nav").is(".daianji") || $("#main-nav").is(".tudaka") || $("#main-nav").is(".minami-fureai")){
		$("#main-nav").removeClass();
		$("#main-nav").addClass("classroom");
	}

	var navP = 0;
	$("#main-nav ul").mousemove(function(e){
		var navX = e.pageX - $("#main-nav ul").position().left;
				
		if(navX < 184 && navX > 0 && navP != 1 && file != "classroom"){
			navP = 1;
			$("#main-nav ul").stop(true, false).animate({"background-position":"0px 0"});
		}else
		if(navX < 368 && navX > 184 && navP != 2 && file != "teacher"){
			navP = 2;
			$("#main-nav ul").stop(true, false).animate({"background-position":"184px 0"});
		}else
		if(navX < 552 && navX > 368 && navP != 3 && file != "taiken"){
			navP = 3;
			$("#main-nav ul").stop(true, false).animate({"background-position":"368px 0"});
		}else
		if(navX < 736 && navX > 552 && navP != 4 && file != "faq"){
			navP = 4;
			$("#main-nav ul").stop(true, false).animate({"background-position":"552px 0"});
		}else
		if(navX < 920 && navX > 736 && navP != 5 && file != "photo"){
			navP = 5;
			$("#main-nav ul").stop(true, false).animate({"background-position":"736px 0"});
		}else{		
			$("a."+file , this).mousemove(function(e){
				if(navP !=6){
					navP = 6;
					menuclose(e);
				}
			});
		}
	});		
	$("#main-nav ul").mouseout(function(e){
		navP = 0;
		menuclose(e);
	});

	function menuclose(e){
		navX = e.pageX - $("#main-nav ul").position().left;
		if(navX < 460){
			$("#main-nav ul").stop(true, false).animate({"background-position":"-184px 0"},{
				complete: function(){
					navP = 0;
				}
			});
		}else{
			navL = 1;
			$("#main-nav ul").stop(true, false).animate({"background-position":"920px 0"},{
				complete: function(){
					navP = 0;
				}
			});
		}
	}
	
	
	$("#class-schedule li.okayama-map").prepend("<a href='ishima.html'>伊島校</a><a href='daianji.html'>大安寺校</a><a href='minami-fureai.html'>南ふれあいセンター校</a><a href='tudaka.html'>津高校</a><a href='hirata.html'>LBD 平田校</a>");
	$("#class-schedule li a").hover(function(){
		$("#class-schedule li a[href='"+ $(this).attr("href") +"'] + p").css("display","block");
	},function(){
		$("#class-schedule li a[href='"+ $(this).attr("href") +"'] + p").css("display","none");
	});
	$("#class-schedule li.okayama-map a").hover(function(){
		$("#class-schedule li a[href='"+ $(this).attr("href") +"'] + p").css("display","block");
		$("#class-schedule li a[href='"+ $(this).attr("href") +"']").addClass("hover")
	},function(){
		$("#class-schedule li a[href='"+ $(this).attr("href") +"'] + p").css("display","none");
		$("#class-schedule li a[href='"+ $(this).attr("href") +"']").removeClass("hover")
	});
	
	
	$("a:not(.notanchor)[href*='#']").click(function() {
		var href= this.hash;
		var $target = $(href == '#top' ? 'body' : href);
		var top = $target.offset().top;
	
		$($.browser.safari ? 'body' : 'html').stop(true, false).animate({scrollTop:top}, 1000, 'swing');
		return false;
	});
	
	
	
	if($("#whats-new").length){
		WhatsNewsBox = $("#whats-new");
		WhatsNewsBox.find("ul").bxSlider({
			mode:'fade',
			controls: true,
			speed:1500,
			pager:true,
			auto:true,
			pause:10000
		});
		for (var i = 0; i < WhatsNewsBox.find("li").length; i++) {
			WhatsNewsBox.find("div.bx-pager a").eq(i).attr("title",WhatsNewsBox.find("li").eq(i).children("time").attr("datetime") + "更新：" + WhatsNewsBox.find("li").eq(i).children("p").text());
		}
		logbana = $("img[src$='img/logo.png']");
		WhatsNewsBox.hover(function(){
			WhatsNewsBox.addClass("on");
			WhatsNewsBox.stop(true, false).animate({"left":"80px"});
			WhatsNewsBox.find("time, div.bx-pager").stop(true, false).animate({"right":"40px"},"slow");
			logbana.animate({opacity: "0.3"});
		},function(){
			WhatsNewsBox.removeClass();
			WhatsNewsBox.stop(true, false).animate({"left":"265px"});
			WhatsNewsBox.find("time, div.bx-pager").stop(true, false).animate({"right":"225px"},"slow");
			logbana.stop(true, false).animate({opacity: "1"});
		});
	}
	
});
