/**
 * 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;
};


$(document).ready(function(){

  //トップページチェックボックスのイベントをGoogleAnalyticsに送信する
  $('.company-action input[type=checkbox]').change(function(event){
    el          = $(event.target);
    companyName = el.parents('div.company:first').find('div.company-name').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]);
    }
  });

  //日経BPコラボ
  hash = window.location.hash;
  if(hash == '#bp'){
    $.cookie('collab', 'bp');
  }
  else if(hash == '#c'){
    $.cookie('collab', '');
  }
  
  if($.cookie('collab')=='bp'){
    $('#header img').attr('src', 'images/header-logo-bp.jpg');
    if(window.location.pathname=='' || window.location.pathname=='/' || window.location.pathname=='/index.php'){
      $('#contents-inner').prepend('<div style="margin-bottom:30px;"><img src="images/bp-collab-contents.jpg"></div>');
    }
  }
  
  //詳細ページ お客様の声部分
  $('.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(''));
  });

  //ウインドウポップアップ
  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});
  }
  
});


var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-3363894-19']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setCustomVar', 1, 'site', 'オフィスデザインナビ', 2]);
_gaq.push(['_setCustomVar', 2, 'design', 'ino1-red', 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', 'ino1-red', 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);
})();
