function initRollOverImages() {
	var image_cache = new Object();
	j$("div#top img,div#nvg img,div#header img,#navi_system 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;
		j$(this).hover(
			function() { this.src = imgsrc_on; },
			function() { this.src = imgsrc; }
		);
	});
}
j$(document).ready(initRollOverImages);

j$(function(){
        j$('#nvg div.glp').hover(function(){
                j$(this).children('ul').fadeIn("fast");
        },function(){
                j$(this).children('ul').fadeOut("fast");
        });
});

(function($) {
    
    /**
     * letter-spacingの計算
     */
    var calcLetterSpacing = function(element, width){
        
        var letterSpacing = 0;
        
        // elementを複製
        var copy = $(element).clone();
        copy.hide();
        $(element).before(copy);
        
        // letter-spacing 0の状態で幅を取得
        copy.css({letterSpacing: 0, float: 'left', width: 'auto'});
        if (jQuery.browser.msie && jQuery.browser.version >= 8) {
            copy.css({display: 'table-cell'});
        }
        var innerWidth = copy.innerWidth();
        
        // 文字数
        var textLength = jQuery.trim(copy.text()).length;
        
        // 文字数からletter-spacingを算出
        letterSpacing = (width - innerWidth) / (textLength - 1);
        
        copy.remove();
        
        letterSpacing = Math.floor(letterSpacing);
        
        return letterSpacing;
    }
    
    /**
     * console.log wrapper
     */
    var log = function(msg){
        if (typeof console != 'undefined') {
            console.log(msg);
        }
    };
    
    jQuery.fn.justify = function(){
        // 最大幅の取得
        var maxWidth = 0;
        this.each(function(){
            if (maxWidth < $(this).innerWidth()) {
                maxWidth = $(this).innerWidth();
            }
        });
        
        // letter-spacingの計算
        this.each(function(){
            
            var letterSpacing = 0;
            
            if (jQuery.trim($(this).text()).length < 2) {
                return;
            }
                
            letterSpacing = calcLetterSpacing(this, maxWidth);
            
            if ($.browser.msie && $.browser.version < 8) {
                // 文字列をtrim
                $(this).text(jQuery.trim($(this).text()));
            } else {
                // 末尾の文字のletter-spaceを除去
                var text = $(this).text();
                $(this).text(text.slice(0, text.length - 1));
                var lastText = $('<span>').text(text.slice(text.length - 1));
                $(this).append(lastText);
                $(lastText).css({letterSpacing: 0, display: 'inline', padding: 0});
            }
            
            $(this).css({letterSpacing: letterSpacing + 'px'});
        });
        
    };
}(jQuery));

j$(document).ready(function(){
    j$('#main address th').justify();
});


j$(function(){
	j$("form#sort select").change(function () {
	j$("form#sort").submit();
});
});
