MJL.event.add(window, "load", function(event) {
    MJL.enable.rollover("roll", {disable : "unroll"});
    MJL.enable.heightEqualizer("listIndex01", {groupBy : 2});
    MJL.enable.heightEqualizer("listArtist01", {groupBy : 2});
    MJL.enable.heightEqualizer("listArtist02", {groupBy : 2});
    MJL.enable.heightEqualizer("listArticle01", {groupBy : 3});
    MJL.enable.heightEqualizer("listProduct01", {groupBy : 4});
    MJL.enable.heightEqualizer("listIndex02", {groupBy : 2});
    /*MJL.enable.heightEqualizer("column-col2", {
        groupBy : 2,
        collect : function(parent) {
            return MJL.getElementsByClassName(parent, "box-relation-02");
        }
    });
    MJL.enable.heightEqualizer("column-col3", {groupBy : 3});
    MJL.enable.heightEqualizer("list-index-01-col2", {
        groupBy : 2,
        collect : function(parent) {
            return MJL.getElementsByClassName(parent, "content");
        }
    });
    MJL.enable.heightEqualizer("list-index-01-col3", {
        groupBy : 3,
        collect : function(parent) {
            return MJL.getElementsByClassName(parent, "content");
        }
    });*/

    //
    // 画像とテキスト (based on jQuery)
    //
    // 画像とテキストの並列処理を行う関数を返す高階関数
    function getImgParallelStyler(side) {
        // side は既定値しか認めない
        if ("left" != side && "right" != side) {
            throw Error("invalid side type: '"+side+"'");
        }
        // 実行関数
        return function() {
            var obj = $(this);
            var imgBlock = $("div.image:first-child", obj);
            var imgWidth = $("p.image img", imgBlock).width(); // 画像幅
            imgBlock.css("width", imgWidth+"px"); // 画像幅を強制
            // 別カラムの margin を調整
            $("div.column", obj).css("margin-"+side,
                                     imgBlock[0].offsetWidth+"px");
        };
    }
    // 実行
    $(".imageParallel.imageLeft").each(getImgParallelStyler("left"));
    $(".imageParallel.imageRight").each(getImgParallelStyler("right"));
}, false);

(function($){
$.fn.set_height = function( options ){
   var settings = {
      items_per_row: false,
      one_height: false,
      delay: 1000,
      group_by_parent: false
   };
   if(options){ jQuery.extend(settings, options); };
   if( $("#js_etalon").length ){ var etalon = $('#js_etalon').get(0); }
   else { var etalon = $('body').append('<span style="position:absolute;left:-9999px;top:0;" id="js_etalon">&nbsp;</span>').find('#js_etalon').get(0); };
   var nodes = this;
   var display_parents = [];
   var items = []; var items_height = []; var max_height = 0;
   var main = function( nodes ){
      _set_row_height = function( offset ){
         if( settings.items_per_row && count%settings.items_per_row ){
            for( j = count-offset; j >= (count-count%settings.items_per_row); j-- ){ items[par_id][j].css( "height", max_height+"px" ); items[par_id][j].addClass("nb"+((j%settings.items_per_row)+1)); };
            max_height = 0;
         };
      };
      _init_item = function(node){
         items[par_id][count] = $(node);
         items[par_id][count].height("auto");
         items_height[par_id] = [];
         items_height[par_id][count] = items[par_id][count].outerHeight();
         prev_max_height = max_height;
         max_height = items_height[par_id][count] > max_height ? items_height[par_id][count] : max_height;
      };
      max_height = 0;
      var cur_parent = false;
      var par_id = 0;
      items[par_id] = []; 
      count = 0; nodes_count = 1;
      nodes.each(function(i){
         _init_item(this);
         if( settings.group_by_parent ){ 
            if( cur_parent && cur_parent != items[par_id][count].parent( settings.group_by_parent )[0] ){
               max_height = prev_max_height;
               _set_row_height(1);
               count = 0;
               items[++par_id] = [];
               _init_item(this);
            };
            cur_parent = items[par_id][count].parents( settings.group_by_parent )[0];
         };
         if( items_height[par_id][count] <= 0 ){
            parents = items[par_id][count].parents();
            for (j=0; j<parents.length || j<5; j++){ if( parents[j].style.display == "none" ){ par = parents[j]; break; } };
            for( i = 0; i < display_parents.length; i++ ){
               if( display_parents[i] == par ){ break; };
               if( i == display_parents.length-1 ){ display_parents[display_parents.length] = par; };
            };
            if( display_parents.length == 0 ){ display_parents.push( par ); };
         };
         if( (!settings.items_per_row || settings.one_height) && count==(nodes.length-1) ){
            for( j = count; j >= 0; j-- ){ items[par_id][j].css( "height", max_height+"px" ); if(settings.items_per_row){ items[par_id][j].addClass("nb"+((j%settings.items_per_row)+1)); }; };
            max_height = 0;
         }
         else if( (settings.items_per_row && (count%settings.items_per_row)==(settings.items_per_row-1)) ){ _set_row_height(0); };
         count++; nodes_count++;
      });
      _set_row_height(1)
   };
   if(nodes.length){
      var base_size = $(etalon).height();
      var worked_out = false;
      var interval = setInterval(function(){
         var current_size = $(etalon).height();
         if( current_size != base_size ){ base_size = current_size; main(nodes); };
         for( i = 0; i < display_parents.length; i++ ){
            if( display_parents[i].style.display == "block" ){ display_parents = []; main(nodes); };
         };
      }, settings.delay);
      main(nodes);
   };
   return this;
};
})(jQuery);


/******************************************************************************
 * not MJL Function (based on jQuery)
 *****************************************************************************/
$(function() {

//
// 楽器ナビゲーション制御
//
    function checkInstNavi(){
        var _inst = "#concert, #marching";
        //$(_inst).addClass("pack");
        $("dd", _inst).hide();
        $("dd:first", _inst).show();
        $("dt", _inst).not(".title").mouseover(function(){
            $(this).siblings("dd").hide();
                $(this).parent("dl").children("dt").children("a").removeClass("active")
                $("a", this).addClass("active");
            $("+ dd", this).show();
        });
    }
    checkInstNavi();


//
// グローバルナビゲーション制御
//
    var gNav = $("#contentHeaderNavi");
    function checkGlobalNavi() {
        var bodyClass = $("body").attr("class");
        $("dd > ul > li", gNav).each(function(){
            var listId = $(this).attr("id").replace("chn", "").toLowerCase();
            if(bodyClass == listId) {
                $(this).addClass("unroll");
                $("> a > img", this).each(function(){
                    this.src = this.src.replace(/(\.[a-z]{3})$/, "_o$1");
                });
            }
        });
    }
    function hoverGlobalNavi() {
        $("dd > ul > li", gNav).hover(function(){
            $(this).children("ul").stop();
            $(this).children('ul').css({display:'block', height:'auto', opacity:'0.5'});
            $(this).children('ul').animate({opacity:'1'},100);
            $(this).children('ul').fadeIn('fast');
        },function() {
            $(this).children('ul').fadeOut(400);
        });
    }
    checkGlobalNavi();
    hoverGlobalNavi();


//
// ローカルナビゲーション制御（基本形）
//
    function localNaviCheck(){
        var path = window.location.pathname.replace(/\/index\.html?/, "");
        var _a = Array(path);
        while(path != "/") {
            path = path.replace(/[^/]*\/?$/, "");
            _a.push(path);
        }
        var flag = false;
        for(i = 0; i < _a.length; i++) {
            if(flag == true) { break; }
            $("a", "#localNavi").each(function(){
                var _href = $(this).attr("href").replace(/\/index\.html?/, "");
                if(_href == _a[i]) {
                    $(this).addClass("current");
                    flag = true;
                    return;
                }
            });
        }
    }
    localNaviCheck();


//
// ラインナップテーブルのストライプ化
//
    $("#lineupTable tbody tr:nth-child(2n), .tableData02 tr:nth-child(2n)").addClass("even");


//
// 高さ揃え
//

    $('ul.banner > li').set_height({ items_per_row:3 });
    $('.layoutM ul.banner > li').set_height({ items_per_row:4 });

//
// 順列リストの番号付け
//
    $("ol.listOrdered01").each(function(){
        $(">li", this).each(function(i){
            $(this).addClass("nb"+(i+1));
        });
    });

//
// カラーバリエーションビューワ
//
    $('div.colorVariationStage').each(function(){
        var stage = $(this);
        var photo = $('p.image img', stage);
        $('ul.menu li a', this).click(function(){
            var obj = $('img', this);
            var menuNum = obj.attr('src').replace(/.+?([0-9]{2})\.gif$/, '$1');
            photo.each(function(){
                this.src = this.src.replace(/(_)[0-9]{2}(\.jpg)$/, '$1' + menuNum + '$2');
            });
            return false;
        });
    });

});

