/*
Copyright (c) 2007, KITAMURA Akatsuki
	jquery.flatheights.js
	Version: 2007-08-01
*/

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 = [];
    $('#catArea > .tabBox > .catBox').each(function(i) {
        temp.push(this);
        if (i % 3 == 2) {
            sets.push(temp);
            temp = [];
        }
    });
    if (temp.length) sets.push(temp);
    $.each(sets, function() {
        $(this).flatHeights();
    });
    
    var sets = [], temp = [];
    $('ul.listStart > li').each(function(i) {
        temp.push(this);
        if (i % 3 == 2) {
            sets.push(temp);
            temp = [];
        }
    });
    if (temp.length) sets.push(temp);
    $.each(sets, function() {
        $(this).flatHeights();
    });
    
    var sets = [], temp = [];
    $('.entryBox > .bg > .bg > .listEntry').each(function(i) {
        temp.push(this);
        if (i % 4 == 3) {
            sets.push(temp);
            temp = [];
        }
    });
    if (temp.length) sets.push(temp);
    $.each(sets, function() {
        $(this).flatHeights();
    });
});

