jQuery.noConflict();

(function($){
$.fn.set_flash=function( options ){
    var settings={
        version:6,movie:'',name:'',title:'',height:0,width:0,no_version:'no version',no_flash:'no flash'
    };
    if(options){
        jQuery.extend(settings, options);
    }
    return this.each(function(i){
        _flash_version=function(){
            if(navigator.plugins && navigator.plugins.length){
            if(!navigator.plugins["Shockwave Flash"]){
                return false}if(navigator.plugins["Shockwave Flash"].description){
                    navigator.plugins["Shockwave Flash"].description.match(/(\d+)\.\d/);
                    return parseInt(RegExp.$1);
                }
            } else {
                for(var j=15; j >= 0; j--){
                    try{
                        new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+j);
                        return j
                    } catch(e) {}
                }
                return false;
            };
            return false
        };
        var attributes={
        };
        if(settings.height && settings.width && settings.movie != ""){
            attributes=settings
        } else {
            var attrs=this.className.match(/[a-z]+\[[^\]]+\]/g);
            for(i=0; i<attrs.length; i++){
                attrs[i].match(/([a-z]+)\[([^\]]+)\]/);
                attributes[RegExp.$1]=RegExp.$2;
            };
        };
        var embed_options="";
        var params_options="";
        if(attributes["wmode"]){
            embed_options+=' wmode="'+attributes["wmode"]+'"';
            params_options+='<param name="wmode" value="'+attributes["wmode"]+'">'
        };
        if(!_flash_version()){
            $(this).html(settings.no_flash);
            return;
        }
        if(_flash_version() < (attributes["version"] || settings.version)){
        $(this).html(settings.no_version);
            return;
        }
        $("> *", this).hide();
        $(this).html(
            '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" height="'+attributes["height"]+'" width="'+attributes["width"]+'" name="'+attributes["name"]+'" title="'+attributes["title"]+'">' +
            '<param name="movie" value="'+attributes["movie"]+'">' +
            '<param name="name" value="'+attributes["name"]+'">' +
            '<param name="quality" value="high">'+
            params_options +
            '<embed src="'+attributes["movie"]+'" quality="high" type="application/x-shockwave-flash" height="'+attributes["height"]+'" width="'+attributes["width"]+'"'+embed_options+'>' +
            '</object>'
        );
    });
};
})(jQuery);


(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);

(function($){
$.fn.set_rollovers = function( options ){
   var settings = {
      extension: '_o',
      hover_extension: '_h',
      fade: false,
      menu:{}
   };
   if(options){ jQuery.extend(settings, options); };
   var path = String(document.location);
   var active = false;
   var longest_match = 0;
   $.each( settings.menu , function( menu_path ){
      if( menu_path.match(/|/) ){
         menu_path_arr = menu_path.split('|');
         for( k=0; k<menu_path_arr.length; k++ ){
            if( path.match( menu_path_arr[k] ) && menu_path_arr[k].length>longest_match ){ active = settings.menu[menu_path_arr[k]]; longest_match = menu_path_arr[k].length; };
         }
      } else {
         if( path.match( menu_path ) && menu_path.length>longest_match ){ active = settings.menu[menu_path]; longest_match = menu_path.length; };
      }
   });
   return this.filter( '[@src*='+ settings.extension +'.]' ).each(function(){
      var roll = new Image;
      roll.src = this.src.replace( settings.extension+'.', settings.hover_extension+'.');
      if( this.src.match(/[^\/]+$/)[0] == active){ this.src = this.src.replace( new RegExp(settings.extension+"(\.[a-z]+)$"), settings.hover_extension+"$1"); }
      else{
         this._hsrc = this.src.replace( new RegExp(settings.extension+"(\.[a-z]+)$") , settings.hover_extension+"$1");
         this._src = this.src;
         if( !settings.fade ){
            $(this).mouseover(function(){ this.src = this._hsrc; }).mouseout(function(){ this.src = this._src; });
         } else {
            var img_holder = $(this).wrap('<span style="position:relative; display:block;"></span>').parent();
            img_holder.append('<img src="'+roll.src+'" style="position:absolute; top:0; left:0;" />');
            img_holder.find('> :last-child').hide();
            img_holder.hover(
               function(){ $("> img:last-child", this).fadeIn(settings.fade); },
               function(){ $("> img:last-child", this).fadeOut(settings.fade); }
            );
         };
         if( this.parentNode.nodeName.match(/^a$/i) ){
            $(this).parent().focus(function(){ $(">img", this).trigger("mouseover"); }).blur(function(){ $(">img", this).trigger("mouseout"); });
         }else if( this.parentNode.nodeName.match(/span/i) && this.parentNode.parentNode.nodeName.match(/a/i) ){
            $(this).parents("a").focus(function(){ $("> span > img:last-child", this).fadeIn(settings.fade); }).blur(function(){ $("> span > :last-child", this).fadeOut(settings.fade); });
         };
      };
   });
};
})(jQuery);

(function($){
$.fn.custom_bullets = function( options ){
   var settings = { 
      images_path: "/product/wind/shared/images/",
      images_type: "gif"
   };
   if(options){ jQuery.extend(settings, options); };
   return this.each(function(){
      this.className.match(/(alphabet|listType01|roman|custom-([^\s]+))/);
      type = RegExp.$1;
      custom = RegExp.$2;
      if(type != ""){
         $( this ).find( '>li' ).each(function(i){
            if( type == "listType01" ){ id = i+1; }
            else if( type == "alphabet" ){ id = "abcdefghijklmnopqrstuvwxyz".charAt(i); }
            else if( type ==  "roman" ){ id = "roman-"+(i+1); }
            else{ id = custom +"-"+ (i+1); }
			var id = String(id + 100).substring(1);
            $(this).css("background-image", "url('"+settings.images_path+"icon_num"+id+"."+settings.images_type+"')");
            $(this).css("background-repeat", "no-repeat");
			$(this).parent("ol").addClass("listType01-h").removeClass("listType01");
         });
      };
   });
};
})(jQuery);


function inst(){
    var _inst = '#wood,#brass';
    jQuery(_inst).addClass('pack');
    jQuery('dd', _inst).hide();
    jQuery('dd:first', _inst).show();
    jQuery('dt', _inst).mouseover(function(){
        jQuery(this).siblings('dd').hide();
　　　　jQuery(this).parent('dl').children('dt').children('a').removeClass('active')
　　　　jQuery('a', this).addClass('active');
        jQuery('+ dd', this).show();
    });
    jQuery('dd, dl', '#wood, #brass').set_height();
}

function gnvControl(){
    jQuery('.globalNav > li').hover(function() {
        jQuery(this).children('ul').stop();
        jQuery(this).children('ul').css({display:'block', height:'auto', opacity:'0.5'});
        jQuery(this).children('ul').animate({opacity:'1'},100);
        jQuery(this).children('ul').fadeIn('fast');
    },function() {
        jQuery(this).children('ul').fadeOut(400);
    });
}

function naviControl(){
    _p = location.pathname.replace('index.html', '');
    jQuery('a', 'dl.listType03').each(function(){
        _t = jQuery(this).attr('href').replace('index.html', '');
        if(_t == _p){
            jQuery(this).css({'font-weight':'bold','color':'#000'});
            return;
        }
    });
}

function lnvControl(){
    _p = location.pathname.replace('index.html', '');
    _a = Array(_p);
    while(_p != "/"){
        _p = _p.replace(/[^/]*\/?$/, "");
        _a.push(_p);
    }
    var flag = false;
    for(i = 0; i < _a.length; i++){
        if(flag == true){
             break;
        }        
        jQuery('a', '#localNav').each(function(){
            _t = jQuery(this).attr('href').replace('index.html', '');
            if(_t == _a[i]){
                jQuery(this).css({'font-weight':'bold','color':'#000'});
                flag = true;
                return;
            } 
        });
    }
}

function _adjust(){
    jQuery('.layoutA, .layoutB', '#primary').each(function(){
        var _w1 = jQuery(this).width();
        var _w2 = jQuery('.image img', this).width();
        var _w3 = _w1 - _w2 - 15;
        jQuery(this).width(_w1);
        jQuery('.image', this).width(_w2);
        jQuery('.content', this).width(_w3);
    });
    jQuery ('div.product').each(function(){
        var _w1 = 646
        var _w2 = 454
        var _w3 = _w1 - _w2 - 15;
        jQuery(this).width(_w1);
        jQuery('div.images, div.image', this).width(_w2);
        jQuery('div.content', this).width(_w3);    
    });
}

function layout(){
    if(jQuery.browser.safari){
        jQuery(function(){
            setTimeout(_adjust, 100);
        });
    } else {
        _adjust();
    }  
}

function topVisual(){
    jQuery('#mainVisual').html('<img src="/product/wind/images/idx_loading.gif" alt="Yamaha Wind Instruments" width="927" height="248" />');
    jQuery('img', '#mainVisual').hide();
    var _n = Math.floor(Math.random()*4) + 101;
    var _n = _n.toString().substr(1);
    jQuery('img', '#mainVisual').attr('src','/product/wind/images/idx_main-visual' + _n + '.jpg');
    setTimeout(function(){
        jQuery('img', '#mainVisual').fadeIn(2000);
    }, 200);
    inst();
}

function init(){
    jQuery('img').set_rollovers();
    jQuery('img, input', '#gn, #ft, #wr').set_rollovers({ extension: '', hover_extension: 'o' });
    jQuery('ol').custom_bullets();
    jQuery('input,select,textarea').focus(function(){
        jQuery(this).css('background','#ffffcc');
    });
    jQuery('input,select,textarea').blur(function(){
        jQuery(this).css('background','none');
    });
    jQuery('tbody tr:odd', '.tableType01').addClass('odd');
    jQuery('.question > li:even').addClass('even');
    jQuery('a[@href$=".pdf"]').addClass('pdf').append('<img src="/product/wind/shared/images/icon_pdf.gif" alt="PDFファイル" />');
    jQuery('a[@href$=".zip"]').addClass('zip').append('<img src="/product/wind/shared/images/icon_zip.gif" alt="ZIPファイル" />');
    jQuery('a[@target="_blank"]:not(a[@href$=".pdf"], [@href$=".zip"])').addClass('blank').append('<img src="/product/wind/shared/images/icon_window.gif" alt="別ウインドウで開きます" />');
    jQuery('img:not(img[@src*="icon"])', '.blank').siblings('img[@src*="icon"]').remove();
    jQuery('img:not(img[@src*="icon"])', '.blank').parent('a.blank').removeClass('blank');
    naviControl();
    gnvControl();
    lnvControl();
    layout();
    jQuery('ul.double > li').set_height({ items_per_row:2 });
    jQuery('ul.introduction > li').set_height({ items_per_row:2 });
    if(location.pathname.replace('index.html', '') == '/product/wind/'){
        topVisual();
    }
    if(location.pathname.replace('index.html', '') == '/product/wind/instruments/'){
        inst();
    }
    jQuery('#flash').set_flash({ movie:"/product/wind/instruments/navi/swf/wind.swf", width:646, height:570, version:8, wmode:'transparent', no_version:'<p><a target="_blank" href="http://www.adobe.com/shockwave/download/index.cgi?Lang=Japanese&amp;P1_Prod_Version=ShockwaveFlash"><img src="/product/wind/instruments/navi/images/noflash.gif" alt="" /></a></p>', no_flash:'<p><a target="_blank" href="http://www.adobe.com/shockwave/download/index.cgi?Lang=Japanese&amp;P1_Prod_Version=ShockwaveFlash"><img src="/product/wind/instruments/navi/images/noflash.gif" alt="" /></a></p>' });
}
