(function ($) {
    $.fn.heightAdjust = function (row, child) {
        this.each(function () {
            var elems = $(child, this);
            var nelems = elems.length;
            var heights = new Array(nelems);
            var setHeight = function () {
                for (var i = 0; i < nelems; i++) {
                    elems[i].style.height = "";
                    heights[i] = $(elems[i]).height();
                }
                var max = 0;
                for (var i = 0; i < nelems; i++) {
                    if (0 == i % row) {
                        max = Math.max.apply(Math, heights.slice(i, i + row));
                    }
                    heights[i] = max;
                }
                for (var i = 0; i < nelems; i++) {
                    elems[i].style.height = heights[i] + "px";
                }
            }
            setHeight();
            if ($("#font-checker").length == 0) {
                $("body").append('<div id="font-checker" style="position:absolute;left:-9999px;top:0;">&nbsp;</div>');
            }
            var baseSize = $("#font-checker").height();
            var checkSize = 0;
            setInterval(function () {
                checkSize = $("#font-checker").height();
                if (baseSize !== checkSize) {
                    setHeight();
                    baseSize = checkSize;
                }
            }, 1000);
        });

    }
})(jQuery);

(function ($) {
    $.fn.rollover = function () {
        var elems = this;
        var nelems = elems.length;
        var off = "_off";
        var on = "_on";
        var preLoadImg = new Object();
        for (var i = 0; i < nelems; i++) {
            preLoadImg[elems[i]] = new Image();
            preLoadImg[elems[i]].src = elems[i].src.replace(off, on);
            elems[i].onmouseover = function () {
                this.src = this.src.replace(off, on);
            }
            elems[i].onmouseout = function () {
                this.src = this.src.replace(on, off);
            }
        }
    }
})(jQuery);

$.event.add(window, "load", function () {

});

$(function () {
    $("img[src *= _off.], input[type = image]").rollover();

    $("div.box-01").each(function(){
        var _hash = window.location.hash;
        if(_hash != "" && _hash.match(/^#case-[0-9][0-9]$/i) != null){
            $(_hash).children("div.box-content").show();
        }
    });

	$("div.block-child > h3", "div.layout-index").siblings().hide();
	$("div.block-child > h3", "div.layout-index").addClass("close");
	$("div.block-child > h3", "div.layout-index").click(function(){
		if($(this).siblings("div.content").length != 0){
			$(this).parents("div.block-child").siblings("div.block-child").find("h3").addClass("close").removeClass("open");
			$(this).parents("div.block-child").siblings("div.block-child").find("h3").siblings().slideUp();
			$(this).removeClass("close").addClass("open");
			$(this).siblings().slideDown();			
		} else {
			window.open($("a", this).attr("href"), "_self");
		}
	});

//    $("div.block-child > h3 a", "div.layout-index").click(function(){
//        window.open($(this).attr("href"), "_self");
//    });

    $(".box-head").click(function(){
            $(this).parents("div.block").siblings("div.block").children("div.box-content").slideUp();
    		$(this).parents("div.block").children("div.box-content").slideDown();
    });

    $("a", "#lnv-static").each(function(){
        var _url = window.location.pathname;
        var _href = $(this).attr("href");

        if(_url.match(/^(\/english)?\/products\/.*?$/i) != null){
            _url = _url.replace(/[^\/]+\.html$/i, "");
            _href = _href.replace(/[^\/]+\.html$/i, "");
        }

        if(_href == _url){
            $(this).parent("li").addClass("current");
        }
    });

	$("ul > li", "div.tab-product-02").not(".current").hover(function(){
		$(this).addClass("current");
	}, function(){
		$(this).removeClass("current");
	});

    $("a[rel^='lightbox']").prettyPhoto({theme: 'light_square'});
    $("ul.list-sitemap").heightAdjust(3, "li");
});

