/* ------------------------------------------------------------ */
/*                                                              */
/*                       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-min.js"></script> \
<script type="text/javascript" src="/_common/js/lib/jquery.socialbutton.js"></script> \
<script type="text/javascript" src="/_common/js/lib/jquery.flatheights.js"></script> \
');






/* ------------------------------------------------------------ */
/*                                                              */
/*                       image onmaouse                         */
/*                                                              */
/* ------------------------------------------------------------ */

function smartRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");

		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("_off."))
			{
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
				}
			}
		}
	}
}

if(window.addEventListener) {
	window.addEventListener("load", smartRollover, false);
}
else if(window.attachEvent) {
	window.attachEvent("onload", smartRollover);
}



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

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

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

  // tab --------------------------------------------------------
  $('.cmn_tab').tab();
  $('#contents').tab2();

  // 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(){$('embed,object').show();}});
  $('.nav_main .contlist').colorbox({transition:'none', width:'815px', inline:true, scrolling:false, href:function(){return '#'+$(this).attr('rel')}});
  
  // flatheight ------------------------------------------------------------
  $(window).load(function() {
    $('.flatheight').each(function(i) {
      $(this).children('li:not(.append), section').flatHeights();
      $(this).find('.flatheight_target').flatHeights();
    });
  });
  
  // socialbutton ------------------------------------------------------------
  $('#social_facebook').socialbutton('facebook_like', {button: 'button_count'});
  $('#social_twitter').socialbutton('twitter', {button: 'horizontal'});
  $('#social_google').socialbutton('google_plusone', {size: 'medium'});
});










/* ------------------------------------------------------------ */
/*                                                              */
/*                       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},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);





