// 画像のロールオーバー
function initRollOverImages() {	
	var image_cache = new Object();
	$("#gNavi li a img").not("[src*='_on.']").each(function(i) {
		var imgsrc = this.src;
		var dot = this.src.lastIndexOf('.');
		var imgsrc_on = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_on;
		$(this).hover(
			function() { this.src = imgsrc_on; },
			function() { this.src = imgsrc; }
		);
	});
}
$(document).ready(initRollOverImages);

//トップページ、スクール情報のボックス高さ揃え
jQuery.changeLetterSize = {
	handlers : [],
	interval : 1000,
	currentSize: 0
};

(function($) {
	var self = $.changeLetterSize;
	var ins = $('<ins>M</ins>').css({
		display: 'block',
		visibility: 'hidden',
		position: 'absolute',
		padding: '0',
		top: '0'
	});
	var isChanged = function() {
		ins.appendTo('body');
		var size = ins[0].offsetHeight;
		ins.remove();
		if (self.currentSize == size) return false;
		self.currentSize = size;
		return true;
	};
	$(isChanged);
	var observer = function() {
		if (!isChanged()) return;
		$.each(self.handlers, function(i, handler) {
			handler();
		});
	};
	self.addHandler = function(func) {
		self.handlers.push(func);
		if (self.handlers.length == 1) {
			setInterval(observer, self.interval);
		}
	};
})(jQuery);

(function($) {
	var sets = [];
	var flatHeights = function(set) {
		var maxHeight = 0;
		set.each(function(){
			var height = this.offsetHeight;
			if (height > maxHeight) maxHeight = height;
		});
		set.css('height', maxHeight + 'px');
	};
	jQuery.fn.flatHeights = function() {
		if (this.length > 1) {
			flatHeights(this);
			sets.push(this);
		}
		return this;
	};
	$.changeLetterSize.addHandler(function() {
		$.each(sets, function() {
			this.height('auto');
			flatHeights(this);
		});
	});
})(jQuery);

$(function(){
	var sets = [], temp = [];
	$('#east > dl').each(function(i) {
		temp.push(this);
		if (i % 3 == 2) {
			sets.push(temp);
			temp = [];
		}
	});
	if (temp.length) sets.push(temp);
	temp = [];
	$.each(sets, function() {
		$(this).flatHeights();
	});
});

$(function(){
	var sets = [], temp = [];
	$('#west > dl').each(function(i) {
		temp.push(this);
		if (i % 3 == 2) {
			sets.push(temp);
			temp = [];
		}
	});
	if (temp.length) sets.push(temp);
	temp = [];
	$.each(sets, function() {
		$(this).flatHeights();
	});
});


// ドロップダウンメニュー

$(function(){
	$("ul#gNavi li").hover(function(){
		$(this).addClass("hover");
		$('ul:first',this).css('visibility', 'visible');
	}, function(){
		$(this).removeClass("hover");
		$('ul:first',this).css('visibility', 'hidden');
    });
	$("ul#gNavi li ul li:has(ul)").find("a:first").append(" &raquo; ");
});
