/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie = function (key, value, options) {
    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);
        if (value === null || value === undefined) {
            options.expires = -1;
        }
        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }
        value = String(value);
        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }
    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

var biz = {
  
  //指定した画像を、指定した要素を元に、垂直方向の中心に表示させる
  verticalMiddleWithMaxWidth: function(imageEl, baseEl, maxWidth){
    
    if(imageEl.height()>0){
      if(baseEl.height()>imageEl.height()){
        imageEl.parents('div:first').css('margin-top', (baseEl.height() - imageEl.height())/2 + 'px');
      }
    }
    else{
      imageEl.load({imageEl:imageEl, baseEl:baseEl}, function(event){
        imageEl = event.data.imageEl;
        baseEl  = event.data.baseEl;
        if(baseEl.height()>imageEl.height()){
          imageEl.parents('div:first').css('margin-top', (baseEl.height() - imageEl.height())/2 + 'px');
        }
      });
    }
  }
}


$(document).ready(function(){
  
  //トップページ ロゴ画像の位置調整
  $('.company').each(function(){
    companyEl = $(this);
    biz.verticalMiddleWithMaxWidth(companyEl.find('.company-logo-img:first'), companyEl.find('.company-body:first'), 130);
  });
  
  
  //チェックボックスの制御
  $('.company-body-action-order').click(function(event){
    if($(event.target).is('div')){
      el = $(event.target).children('input:first');
      if(el.attr('checked')){
        el.attr('checked', false);
      }
      else {
        el.attr('checked', true);
      }
      el.trigger('change');
    }
  });


  //トップページチェックボックスのイベントをGoogleAnalyticsに送信する
  $('.company-body-action-order input[type=checkbox]').change(function(event){
    el          = $(event.target);
    companyName = el.parents('div.company:first').find('div.company-name-inner').html().trim()
    if(el.attr('checked')){
      _gaq.push(['_trackEvent',     'top-company-chackbox', 'checked', companyName, 1]);
      _gaq.push(['all._trackEvent', 'top-company-chackbox', 'checked', companyName, 1]);
    }
    else{
      _gaq.push(['_trackEvent',     'top-company-chackbox', 'unchecked', companyName, 0]);
      _gaq.push(['all._trackEvent', 'top-company-chackbox', 'unchecked', companyName,0]);
    }
  });

  
  //詳細ページ お客様の声部分
  $('.voice').each(function(){
    el = $(this);
    personEl  = el.find('.voice-person');
    commentEl = el.find('.voice-comment');
    
    html = [];
    html.push('<div class="voice-person">');
    if(personEl.length!=0){
      html.push(personEl.html());
    }
    html.push('</div>');
    html.push('<div class="voice-frame-top">');
    html.push('  <div class="voice-comment">');
    html.push('    <div class="voice-comment-inner">');
    if(commentEl.length!=0){
      html.push(commentEl.html());
    }
    else{
      html.push(el.html());
    }
    html.push('    </div>');
    html.push('  </div>');
    html.push('  <div class="voice-frame-bottom"></div>');
    html.push('</div>');
    html.push('<div style="clear:both;"></div>');
    el.html(html.join(''));
  });
  
  
  //詳細ページ ロゴ画像を中央構えにする
  $('#navi').each(function(){
    companyEl = $(this);
    biz.verticalMiddleWithMaxWidth(companyEl.find('#navi-logo img:first'), companyEl.find('#navi-body:first'), 130);
  });

  //ウインドウポップアップ
  if(!jQuery.support.opacity && !jQuery.support.style && typeof document.documentElement.style.maxHeight == "undefined"){ //IE6
    $("div.entry-image a").css('cursor', 'default').click(function(){return false;});
  }  
  else {
    $("div.entry-image a").fancybox({autoScale:false, centerOnScroll: true});
  }
  
  //日経BPコラボ
  hash = window.location.hash;
  if(hash == '#bp'){
    $.cookie('collab', 'bp');
  }
  else if(hash == '#c'){
    $.cookie('collab', '');
  }
  
  if($.cookie('collab')=='bp'){
    $('#header-title img:first').attr('src', 'images/bp-logo.jpg');
    if(window.location.pathname=='' || window.location.pathname=='/' || window.location.pathname=='/index.php'){
      $('#about').after('<div id="bp-contents" style="background-image:url(images/bp-contents.jpg);height:170px"></div>');
    }
  }


});


var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-3363894-29']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setCustomVar', 1, 'site', '人事制度ナビ', 2]);
_gaq.push(['_setCustomVar', 2, 'design', 'oda1-blue', 2]);
_gaq.push(['_trackPageview']);
  
_gaq.push(['all._setAccount', 'UA-3363894-33']);
_gaq.push(['all._setDomainName', 'none']);
_gaq.push(['all._setAllowLinker', true]);
_gaq.push(['all._setCustomVar', 1, 'site', '人事制度ナビ', 2]);
_gaq.push(['all._setCustomVar', 2, 'design', 'oda1-blue', 2]);
_gaq.push(['all._trackPageview']);
  
(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();





