﻿/* ------------------------------------------------------------ */
/*                                                              */
/*                         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]));





/* ------------------------------------------------------------ */
/*                                                              */
/*                       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/ifixpng.js"></script>');

var $j = jQuery.noConflict();





/* ------------------------------------------------------------ */
/*                                                              */
/*                          initialize                          */
/*                                                              */
/* ------------------------------------------------------------ */

try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}  // ie6 background-image reload issue

$j(function($){

  // module : frame -------------------------------------------
  $('.module_head').before('<div class="frm_head_t"><div class="frm_head_tl"></div><div class="frm_head_tr"></div></div>').after('<div class="frm_head_b"><div class="frm_head_bl"></div><div class="frm_head_br"></div></div>').wrap('<div class="frm_head_l"><div class="frm_head_r"></div></div>');
  $('.module_body').before('<div class="frm_body_t"><div class="frm_body_tl"></div><div class="frm_body_tr"></div></div>').after('<div class="frm_body_b"><div class="frm_body_bl"></div><div class="frm_body_br"></div></div>').wrap('<div class="frm_body_l"><div class="frm_body_r"></div></div>');
  $('.mod_default > .frm_head_b + .frm_body_t, .mod_round > .frm_head_b + .frm_body_t').hide();

  // button : image -------------------------------------------
  $('a.button').prepend('<span>&nbsp;</span>').wrap('<div class="button centered"></div>');
  $('a.button_s').prepend('<span>&nbsp;</span>').wrap('<div class="button_s centered"></div>');

  // shadow : image -------------------------------------------
  $('.shadow').parent('a').wrap('<div class="shadowWrap"></div>').each(function(){
    $(this).parent('.shadowWrap').width($(this).width());
  });

  // anchor ------------------------------------------------------------
  $('a.more').append('<img src="'+_absPath+'_global/css/img/arrow.png" alt="" />');

  // list -------------------------------------------
  $('.list li:last-child, dl.inline dt:first-child, dl.inline > dd:first, dl.nav_subcategory dd:last').addClass('last');
  $('ol.ranking li').each(function(j){
    $(this).children('a').before('<span style="float: left; width: 14px; margin-left: -14px; text-align: center; color: #fff; font-size: 10px; font-weight: normal;">'+(j+1)+'</span>');
  });
  $('.stripe tr:even').children().addClass('even');
  $('.stripe tr:odd').children().addClass('odd');
  $('.stripe').children(':even').addClass('even');
  $('.stripe').children(':odd').addClass('odd');

  // _blank window -----------------------------------------------------
  $('a.blank, area.blank').click(function(){ window.open(this.href, '_blank'); return false; });

  // 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]);
    });
  });

  // png fix -----------------------------------------------------
  $.ifixpng(_absPath+'_global/img/blank.gif'); 
//  $('img[@src$=.png]').ifixpng();
  $('.transparent').ifixpng();

  // current menu -------------------------------------------
  $('ul.nav_category li.' + _pathName.split('/')[1]+' a').addClass('current');

  // centered ------------------------------------------------------------
  $('.centered').each(function(j){
    var marginL = ($(this).parent().width() - $(this).width())/2;
    $(this).css({'margin-left':marginL+'px'});
  });

  // multi-column -------------------------------------------
  $.fn.setColumn();
});





/* ------------------------------------------------------------ */
/*                                                              */
/*                        equalizeCols                          */
/*                                                              */
/* ------------------------------------------------------------ */
(function($) {
  $.fn.equalizeCols = function(children){
    var child = Array(0);
    if (children) child = children.split(",");
    var maxH = 0;
    this.each(function(i){
      if (this.offsetHeight>maxH) maxH = this.offsetHeight;
    }).css("height","auto").each(function(i){
        var gap = maxH-this.offsetHeight;
        if (gap > 0) {
          t = document.createElement('div');
          $(t).attr("class","fill").css("height",gap+"px");
          if (child.length > i) {   
            $(this).find(child[i]).children(':last-child').after(t);
          } else {
            $(this).children(':last-child').after(t);
          }
        }
      }
    );
  }
})(jQuery);





/* ------------------------------------------------------------ */
/*                                                              */
/*                        multi column                          */
/*                                                              */
/* ------------------------------------------------------------ */
(function($){
  $.fn.extend({
    setColumn: function() {
      $.each(['col2','col3','col4','col5','col6','col7','col8'], function(i, targ) {
        var targ  = '.' + targ;
        var N     = i+2;
        if ($(targ).size()) {
          $(targ).each(function(){
            var targW = $(this).width();
            $(this).children('li').width(Math.floor(targW/N));
            $(this).children('li:last').width(targW - (Math.floor(targW/N)*(N-1)));
            $(this).children('li.double').width(Math.floor(targW/N)*2);
          });
        }
      });
    }
  });
})(jQuery);





/* ------------------------------------------------------------ */
/*                                                              */
/*                      Flash  -  SWFObject                     */
/*                                                              */
/* ------------------------------------------------------------ */
// <div id="swf1Holder"></div>
// <script type="text/javascript">_swf({type:'promo'});</script>

function _swf(obj) {
  if (typeof obj == 'undefined') return null;

  switch (obj.type) {
    case 'feature':
      prm = {w:820,h:470,id:'swf1',bg:'#f5f5e9',swf:_absPath+'swf/feature.swf',param:'_conf='+_absPath+'swf/config.xml&_elements='+_absPath+'swf/elements.xml&_lang=ja&__l=1'}; break;
    case 'feature_en':
      prm = {w:820,h:470,id:'swf1',bg:'#f5f5e9',swf:_absPath+'swf/feature.swf',param:'_conf='+_absPath+'swf/config.xml&_elements='+_absPath+'swf/elements_en.xml&_lang=en&__l=1'}; break;
  }
  if (typeof prm == 'undefined') return null;

  /* --- case of undefined --- */
  if (!prm.v)      prm.v      = 8;
  if (!prm.bg)     prm.bg     = '#ffffff';
  if (!prm.scale)  prm.scale  = 'noscale';
  if (!prm.salign) prm.salign = 'TL';

  var so = new SWFObject(prm.swf, prm.id, prm.w, prm.h, prm.v, prm.bg);

  /* --- add param --- */
  so.addParam('scale',  prm.scale);
  so.addParam('salign', prm.salign);
  if (prm.wmode == 'transparent') {
    so.addParam('wmode', prm.wmode);  // Japanese IME & Scroll Wheel issue
  }

  /* --- add variable --- */
  if (prm.param) { var pAry=prm.param.split('&'); for (var i=0;i<pAry.length;i++) {var a=pAry[i].split('='); so.addVariable(a[0],a[1]);} };
  if (location.search) { var sAry=location.search.substr(1).split('&'); for (var i=0;i<sAry.length;i++) {var a=sAry[i].split('='); so.addVariable(a[0],a[1]);} };
  so.addVariable('_pathName', _pathName);

  /* --- marginFix & write --- */
  so.setAttribute('style', ';');
  so.write(prm.id+'Holder');
}

