/* ------------------------------------------------------------ */
/*                                                              */
/*                       import libraries                       */
/*                                                              */
/* ------------------------------------------------------------ */

document.write('\
<link rel="stylesheet" type="text/css" href="/_common/js/lib/colorbox/colorbox.css" media="screen" /> \
<script type="text/javascript" src="/_common/js/lib/colorbox/jquery.colorbox.js"></script> \
<script type="text/javascript" src="/_common/js/lib/jquery.flatheights.js"></script> \
');










/* ------------------------------------------------------------ */
/*                                                              */
/*                      jQuery Initialize                       */
/*                                                              */
/* ------------------------------------------------------------ */

$(function($){

  // bigBtn ------------------------------------------------------------
  $('.cmn_banner').click(function(){
    var url = $(this).find('.cmn_unit_title a, .cmn_banner_title a').attr('href');
    if (typeof url == 'undefined') return null;
     window.location = url; return false;
  });

  // open in new window ------------------------------------------------------------
  $('a[rel=external]').attr('target','_blank');

  // tab --------------------------------------------------------
  $('.cmn_tab').tab();

  // gotop smooth scroll ------------------------------------------------------------
  $('a[href="#top"], .nav_anchor a[href*="#"], .nav_anchor_v a[href*="#"]').mousedown(function(){
    $($(this).attr('href')).doScroll();
    return false;
  });

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

  // colorbox ------------------------------------------------------------
  $('.colorbox').colorbox({onOpen:function(){$('embed,object').hide();},onClosed:function(){$('embed,object').show();}});
  $('.colorbox_iframe').colorbox({iframe:true, width:"90%", height:"90%",onOpen:function(){$('embed,object').hide();},onClosed:function(){$('xembed,object').show();}});

  // flatheight ------------------------------------------------------------
  $(window).load(function() {
    $('.flatHeights').each(function(i) {
      $(this).children('li:not(.append), section, .cmn_unit').flatHeights();
      $(this).find('.flatHeightsTarget').flatHeights();
    });
  });
  
});










/* ------------------------------------------------------------ */
/*                                                              */
/*                       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='div[class*="cmn_tab_"]';
      node.find(targ+':gt(0)').hide();
      $('li',nav).click(function() {
        node.find(targ+':eq('+$(this).index()+')').show().siblings(targ).hide();
        $(this).addClass('on').siblings('.on').removeClass('on');
        return false;
      });
    });
  }


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


  // ------------------------------------------------------------
  // [ 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);

