/**
 * 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]);
    }
  });
  
  //詳細ページ お客様の声部分
  $('.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(''));
  });
  
  //詳細ページの画像ホバーアップ
　　$("div.entry-image a").fancybox({autoScale:false, centerOnScroll: true});
  
});


var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-3363894-22']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setCustomVar', 1, 'site', 'ビル管理ナビ', 2]);
_gaq.push(['_setCustomVar', 2, 'design', 'ino1-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', 'ino1-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);
})();
