/* ------------------------------------------------------------ */
/*                                                              */
/*                         global param                         */
/*                                                              */
/* ------------------------------------------------------------ */

var isIE  = /*@cc_on!@*/0;
var isIE6 = isIE && !window.XMLHttpRequest;
var $j = jQuery.noConflict();





/* ------------------------------------------------------------ */
/*                                                              */
/*                       import libraries                       */
/*                                                              */
/* ------------------------------------------------------------ */
document.write('<script type="text/javascript" src="/_common/js/lib/jquery.easing.js"></script>');
document.write('<script type="text/javascript" src="/_common/js/lib/jquery.cookie.js"></script>');
document.write('<script type="text/javascript" src="/_common/js/lib/jquery.flatheights.js"></script>');
document.write('<script type="text/javascript" src="/_common/js/lib/jquery.jcarousellite.min.js"></script>');





/* ------------------------------------------------------------ */
/*                                                              */
/*                      jQuery initialize                       */
/*                                                              */
/* ------------------------------------------------------------ */

$j(function($){

  // img hover : toggle -------------------------------------------
  $('.imghover').imghover();
  $('.imgtoggle').imgtoggle();

  // .first,.last --------------------------------------------------------
  $('li:first-child, dt:first-child, dd:first-child, div > .column:first').addClass('first');
  $('li:last-child, dt:last-child, dd:last-child, div > .column:last').addClass('last');
  $('#content ul,#content ol,.stripe,.item').each(function(i) {
    $('>li:even,>tbody>tr:even',this).addClass('even');
    $('>li:odd,>tbody>tr:odd',this).addClass('odd');
  });

  // current menu -------------------------------------------
  var title = $('title').html().split('|')[0];
  $('#nav-sub dd a').each(function(){
    if ($(this).text()==$.trim(title)) $(this).parent('dd').addClass('on');
    if ($(this).attr('title')==$.trim(title)) $(this).parent('dd').addClass('on');
  });

  // dl.column ------------------------------------------------------------
  $('dl.column,dl.columnR').each(function(i) {
    var dtWidth = [];
    $(this).children('dt').each(function(j) {
      dtWidth.push($(this).width()+5);
    });
    var max = Math.max.apply(null,dtWidth);
    $(this).children('dt').width(max);
    var marginLR = ($(this).hasClass('columnR')) ? 'marginRight' : 'marginLeft';
    $(this).children('dd').css(marginLR,max+10);
  });

  // fontsize switcher ------------------------------------------------------------
//  $.fn.setFontsize(($.cookie('fsize')) ? $.cookie('fsize'):'fs-normal');
//  $('#fontsize a').click(function(){$.fn.setFontsize(this.id)});
  
  // window -----------------------------------------------------
  $('a.blank, area.blank, a.pdf, a.rss').click(function(){ window.open(this.href, null,'scrollbars=yes,resizable=yes,status=yes,directories=yes,menubar=yes,toolbar=yes'); return false; });
  $('.close a, a.close').click(function(){ window.close(); return false; });
  
  // gotop smooth scroll ------------------------------------------------------------
  $('.gotop a[href="#header"], .nav-anchor a').click(function(){
    $($(this).attr('href')).doScroll();
  });
});






/* ------------------------------------------------------------ */
/*                                                              */
/*                     fontsize switcher                        */
/*                                                              */
/* ------------------------------------------------------------ */
(function($){
  $.fn.extend({
    setFontsize: function(fsize) {
      $('#fontsize a').removeClass('on');
      switch (fsize) {
        case 'fs-large' : fsize_val='90%'; $('#fontsize a#fs-large').addClass('on'); break;
        default         : fsize_val='78%';  $('#fontsize a#fs-normal').addClass('on');
      }
      $('body').css('font-size',fsize_val);
      $.cookie('fsize',fsize,{expires:30,path:'/'});
    }
  });
})(jQuery);





/* ------------------------------------------------------------ */
/*                                                              */
/*                          doScroll                            */
/*                                                              */
/* ------------------------------------------------------------ */
(function($){
  $.fn.extend({
    doScroll: function() {
      $('html,body').animate({scrollTop: $(this).offset().top}, 500);
    }
  });
})(jQuery);





/* ------------------------------------------------------------ */
/*                                                              */
/*                       image switcher                         */
/*            [ filename.ext <-> filename_on.ext ]              */
/*                                                              */
/* ------------------------------------------------------------ */
(function($){
  $.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);

