﻿/* ------------------------------------------------------------ */
/*                                                              */
/*                         global param                         */
/*                                                              */
/* ------------------------------------------------------------ */

var _loc      = location.pathname;
var _pathName = _loc.substring(0,_loc.lastIndexOf('/')+1);
var _fileName = _loc.substring(_loc.lastIndexOf('/')+1);
var _swfAry   = new Array();

function _(p,q) {q=new Image;q.src=p;p=q.src;q.src='#';return p}
var _absPath  = (_(document.getElementsByTagName('script')[0].src.split('_global')[0]));

var isIE6 = /*@cc_on!@*/0 && !window.XMLHttpRequest;
var $j = jQuery.noConflict();





/* ------------------------------------------------------------ */
/*                                                              */
/*                       import libraries                       */
/*                                                              */
/* ------------------------------------------------------------ */

document.write('<script type="text/javascript" src="'+_absPath+'_global/js/core/swfobject.js"></script>');
document.write('<script type="text/javascript" src="'+_absPath+'_global/js/lib/jquery.cookie2.js"></script>');
document.write('<script type="text/javascript" src="'+_absPath+'_global/js/lib/jquery.innerfade2.js"></script>');
document.write('<script type="text/javascript" src="'+_absPath+'_global/js/lib/jquery.validate.min.js"></script>');
document.write('<script type="text/javascript" src="'+_absPath+'_global/js/lib/jquery.cluetip.js"></script>');
document.write('<script type="text/javascript" src="'+_absPath+'_global/js/lib/jquery.bgiframe.min.js"></script>');
document.write('<script type="text/javascript" src="'+_absPath+'_global/js/lib/jquery.hoverIntent.js"></script>');
document.write('<script type="text/javascript" src="'+_absPath+'_global/js/lib/jquery.socialbutton.js"></script>');
document.write('<script type="text/javascript" src="'+_absPath+'_global/js/lib/iepngfix/iepngfix_tilebg.js"></script>');
document.write('<script type="text/javascript" src="'+_absPath+'_global/js/lib/thickbox/thickbox.js"></script>');
document.write('<link rel="stylesheet" type="text/css" href="'+_absPath+'_global/js/lib/thickbox/thickbox.css" media="screen" />');





/* ------------------------------------------------------------ */
/*                                                              */
/*                           IEPNGFix                           */
/*                                                              */
/* ------------------------------------------------------------ */

document.write('<style type="text/css">.transparent { behavior:url('+_absPath+'_global/js/lib/iepngfix/iepngfix.htc) }</style>');





/* ------------------------------------------------------------ */
/*                                                              */
/*                          initialize                          */
/*                                                              */
/* ------------------------------------------------------------ */

try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}  // ie6 background-image reload issue

$j(function($){

  // fontsize switcher ------------------------------------------------------------
  $.fn.setFontsize(($.fn.cookie('fsize')) ? $.fn.cookie('fsize'):'fs-small');
  $('#fontsize a').click(function(){$.fn.setFontsize(this.id)});
  
  // _blank window -----------------------------------------------------
  $('a.blank, area.blank, a.popup').click(function(){ window.open(this.href, '_blank'); return false; });

  // PDF -----------------------------------------------------
  $('a[href$=".pdf"]:contains(".pdf")').addClass('pdf');

  // img hover -------------------------------------------
  $('.imghover').imghover();
  $('.imgtoggle').imgtoggle();

  // list -------------------------------------------
  $('li:first-child').addClass('first');
  $('li:last-child').addClass('last');
  $('.stripe').each(function(j) {
    $('li:even,tr:even',this).addClass('even');
    $('li:odd,tr:odd',this).addClass('odd');
  });

  // Search Text Label -------------------------------------------
  swapValues = [];
  $('.swap_value').each(function(i){
    swapValues[i] = $(this).val();
    $(this).focus(function(){
      if ($(this).val() == swapValues[i]) $(this).val("");
    }).blur(function(){
      if ($.trim($(this).val()) == "") $(this).val(swapValues[i]);
    });
  });

  // current menu -------------------------------------------
  $('div#nav-main li#nm-' + _pathName.split('/')[1]+' a').addClass('active');

  // centered ------------------------------------------------------------
  $('.centered').each(function(j){
    var marginL = ($(this).parent().width() - $(this).width())/2;
    $(this).css({'margin-left':marginL+'px'});
  });

  // dl-column ------------------------------------------------------------
  $('dl.dt-left,dl.dt-right').each(function(j) {
    $(this).each(function() {
      var maxW = 0;
      $(this).children('dt').each(function(i) {
        maxW = ($(this).width() > maxW) ? $(this).width() : maxW;
      });
      maxW+=10;
      if($(this).attr('class').indexOf('dt-left')>-1) $(this).children('dd').css({'margin-left':maxW+'px'});
      if($(this).attr('class').indexOf('dt-right')>-1) $(this).children('dd').css({'margin-right':maxW+'px'});
    });
  });

  // flash player ------------------------------------------------------------
  $('.flvplayer').click(function(){
    _swf({type:'flvplayer',flv:this.rel});
    tb_show(null,'#TB_inline?height=380&width=620&inlineId=flvPlayerHolder',false);
    this.blur();
    return false;
  });

  // validate form ------------------------------------------------------------
/*
  $('#comments-form').validate({
    rules: {
      author: 'required',
      text: 'required'
    },
    messages: {
      author: '<span class="red">※ニックネームが入力されていません</span>',
      text: '<span class="red">※コメントが入力されていません</span>'
    }
  });
*/

  // hover tip ------------------------------------------------------------
  $('#m_map area.tip').cluetip({
    titleAttribute: '',
    closeText: '',
    positionBy: 'auto',
    topOffset: 1,
    leftOffset: 1,
    local: true,
    hideLocal: true,
    dropShadow: false, 
    sticky: true,
    mouseOutClose: true
  });
  $('.logos a.tip').cluetip({
    splitTitle: '|',
    closeText: '',
    positionBy: 'fixed',
    width: 200,
    topOffset: 15,
    leftOffset: -80,
    sticky: true,
    mouseOutClose: true
  });
  
  
  // socialbutton ------------------------------------------------------------
  $('.social_facebook').socialbutton('facebook_like', {button: 'button_count'});
  $('.social_twitter').socialbutton('twitter', {button: 'horizontal'});
  $('.social_mixi').socialbutton('mixi_check', {key: '[1234567]'});
});





/* ------------------------------------------------------------ */
/*                                                              */
/*                       jQuery Functions                       */
/*                                                              */
/* ------------------------------------------------------------ */

(function($){

  // ------------------------------------------------------------
  // [ tab ] .cmn_tab > .nav_tab > .cmn_tab_[n] 
  // ------------------------------------------------------------
  $.fn.tab = function() {
    return this.each(function(nav) {
      var node=$(this), nav=$('.nav_tab ol',node), targ='*[class*="cmn_tab_"]';
      $(targ,node).hide();
      $('li',nav).click(function() {
        node.find(targ+':eq('+$(this).index()+')').show().siblings(targ).hide();
        $(this).addClass('on').siblings('.on').removeClass('on');
        return false;
      });
      $('li.on',nav).click();
    });
  }
  $.fn.tab2 = function() {
    return this.each(function(nav) {
      var node=$(this), nav=$('.nav_sub ul',node), targ='*[class*="cmn_tab2"]';
      $(targ,node).hide();
      $('li',nav).click(function() {
        node.find(targ+':eq('+$(this).index()+')').show().siblings(targ).hide();
        $(this).addClass('on').siblings('.on').removeClass('on');
        return false;
      });
      $('li.on',nav).click();
    });
  }


  // ------------------------------------------------------------
  // [ doScroll ] 
  // ------------------------------------------------------------
  $.fn.extend({
    doScroll: function() { $('html,body').animate({scrollTop:$(this).offset().top},200); }
  });


  // ------------------------------------------------------------
  // [ imghover | imgtoggle ]  filename.EXT <-> filename_on.EXT
  // ------------------------------------------------------------
  $.fn.extend({
    imghover: function() {
      return this.each(function() {
        var node = $(this);
        if (!node.is('img')&&!node.is(':image')){
          node.find('img,:image').imghover();
          return;
        }
        node.hover(function() {
          node.addClass('hover');
          if (!node.hasClass('on')) $.fn.imgOn(node);
        },function() {
          node.removeClass('hover');
          if (!node.hasClass('on')) $.fn.imgOff(node);
        });
      });
    },
    imgtoggle: function() {
      return this.each(function() {
        var node = $(this);
        if (!node.is('img')&&!node.is(':image')){
          node.find('img,:image').imgtoggle();
          return;
        }
        node.click(function() {
          if (node.hasClass('on')) {
            $.fn.imgOff(node);
          } else {
            if (!node.hasClass('hover')) $.fn.imgOn(node);
          }
          node.toggleClass('on');
        });
      });
    },
    imgOn: function(node) {
      if(node.attr('src').match(/^(.+)_on(\.[a-z]+)$/)) return;
      if(isIE6 && node.context.style.filter) {
        node.context.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+node.context.style.filter.split('"')[1].replace(/^(.+)(\.[a-z]+)$/,'$1_on$2')+'",sizingMethod="scale")';
      } else {
        node.attr('src',node.attr('src').replace(/^(.+)(\.[a-z]+)$/,'$1_on$2'));
      }
    },
    imgOff: function(node) {
      if(isIE6 && node.context.style.filter) {
        node.context.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+node.context.style.filter.split('"')[1].replace(/^(.+)_on(\.[a-z]+)$/,'$1$2')+'",sizingMethod="scale")';
      } else {
        node.attr('src',node.attr('src').replace(/^(.+)_on(\.[a-z]+)$/,'$1$2'));
      }
    }
  });


})(jQuery);





/* ------------------------------------------------------------ */
/*                                                              */
/*                     fontsize switcher                        */
/*                                                              */
/* ------------------------------------------------------------ */
(function($){
  $.fn.extend({
    setFontsize: function(fsize) {
      $('#fontsize a').removeClass('active');
      switch (fsize) {
        case 'fs-large' : fsize_val='90%'; $('#fontsize a#fs-large').addClass('active'); break;
        case 'fs-medium': fsize_val='90%';  $('#fontsize a#fs-medium').addClass('active'); break;
        default         : fsize_val='78%';  $('#fontsize a#fs-small').addClass('active');
      }
      $('body').css('font-size',fsize_val);
      $.fn.cookie('fsize',fsize,{expires:30,path:'/'});
    }
  });
})(jQuery);





/* ------------------------------------------------------------ */
/*                                                              */
/*                 doShuffle : ( randomize [li] )               */
/*                                                              */
/* ------------------------------------------------------------ */
(function($){
  $.fn.extend({
    doShuffle: function() {
      var shuffled = this.find('li').get().sort(function(){
        return Math.round(Math.random())-0.5; //just a random number between -0.5 and 0.5
      });
      $(shuffled).appendTo(this);
      return this;
    }
  });
})(jQuery);





/* ------------------------------------------------------------ */
/*                                                              */
/*         delay  : ( delay a jQuery animation or func.)        */
/*                                                              */
/* ------------------------------------------------------------ */
(function($){
  $.fn.extend({
    delay: function(time, callback){
      // Empty function:
      jQuery.fx.step.delay = function(){};
      // Return meaningless animation, (will be added to queue)
      return this.animate({delay:1}, time, callback);
    }
  });
})(jQuery);





/* ------------------------------------------------------------ */
/*                                                              */
/*                           Utility                            */
/*                                                              */
/* ------------------------------------------------------------ */
Array.prototype.max = function(){
    return Math.max.apply(null,this);
}
Array.prototype.min = function(){
    return Math.min.apply(null,this);
}
Array.prototype.shuffle = function(){
    var i   = this.length;
    var ary = this.concat();
    var ret = [];
    while(i) ret.push(ary.splice(Math.floor(Math.random()*i--),1));
    return ret
}





/* ------------------------------------------------------------ */
/*                                                              */
/*                      Flash  -  SWFObject                     */
/*                                                              */
/* ------------------------------------------------------------ */
// <div id="swf1Holder"></div>
// <script type="text/javascript">_swf({type:'promo'});</script>
// <script type="text/javascript">_swf({w:'940',h:'210',id:'swf2',swf:_absPath+'_global/swf/feature.swf',param:'_v=Fp&flag=1',bgcolor:'#990000'});</script>

function _swf(obj) {
  if (typeof obj == 'undefined') return null;
  if (_swfAry.toString().indexOf(obj.type)>-1) return null;

  var expressInstall = _absPath+'_global/swf/expressInstall.swf';
  var flvars = {};
  var params = {};
  var attrib = {};

  switch (obj.type) {
    case 'flvplayer':
      prm    = {w:575,h:332,id:'flvPlayer',swf:_absPath+'_global/swf/fp.swf'};
      params = {wmode:'transparent'};
      break;
    case 'feature':
      prm    = {w:570,h:100,id:'swf1',swf:_absPath+'_global/swf/feature.swf'};
      flvars = {_a:_absPath,_f:_fileName};
      params = {bgcolor:'#009900'};
      break;
    default:
      prm    = obj;
      if (prm.param) { var pAry=prm.param.split('&'); for (var i=0;i<pAry.length;i++) {var a=pAry[i].split('='); flvars[a[0]] = a[1];} };
      params = {bgcolor:obj.bgcolor,scale:obj.scale,salign:obj.salign};
  }
  if (typeof prm == 'undefined') return null;

  /* --- [4] swf version --- */
  prm.v = (obj.v) ? obj.v : '9.0.28';

  /* --- [6] flvars --- */
  flvars._p = _pathName;
  if (location.search) { var sAry=location.search.substr(1).split('&'); for (var i=0;i<sAry.length;i++) {var a=sAry[i].split('='); flvars[a[0]] = a[1];} };

  /* --- [7] params --- */
  params.bgcolor = (params.bgcolor) ? params.bgcolor : '#ffffff';
  params.scale   = (params.scale)   ? params.scale :   'noScale';
  params.salign  = (params.salign)  ? params.salign :  'TL';

  /* --- [8] attrib --- */
  attrib.id = prm.id;

  swfobject.embedSWF(prm.swf, prm.id+'Holder', prm.w, prm.h, prm.v, expressInstall, flvars, params, attrib);
}

