// ***** Google Analytics Click Count *****


var _gaq = _gaq || [];
_gaq.push(
['_setAccount', 'UA-12917591-2'],
['_trackPageview'],
['b._setAccount', 'UA-12917591-2'],
['b._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);
})();



var start_time = new Date().getTime();



jQuery(function() {
/* GA click count */
    function addCC(data) {
        /*if (data.clear_event == true) {
            data.obj.unbind('click');
        }*/
        data.obj.unbind('click');
        data.obj.click(function() {
            if (data.label == null) {
                data.label = document.location.pathname;
            }
            var value = Math.round(((new Date()).getTime() - start_time)/1000);
            
            if (data.action == '/search/') {
                data.action += $('input#q').val();
            }
            
            /*
            var debugData = 'Category : ' + data.category + "\n";
            debugData    += 'Action : ' + data.action + "\n";
            debugData    += 'Label : ' + data.label + "\n";
            debugData    += 'Value : ' + value + "sec";
            alert(debugData);
            */
            
            _gaq.push(['b._trackEvent', data.category, data.action, data.label, value]);
        });
    }
    
    /* トップ
    ----------------------------------- */
    $('body#index div#news a, body#index div#topics_body a, body#index div#pickup_body a, body#index div#information_body a, body#index a.clickevent').each(function () {
        var click_place = $(this).attr('href');
        addCC({
            obj         : $(this),
            category    : 'Top',
            action      : $(this).attr('href'),
            label       : document.location.pathname
        });
    });
    
    /* 関連情報
    ----------------------------------- */
    $('body#info div#info_body a, body#info a.clickevent').each(function () {
        var click_place = $(this).attr('href');
        addCC({
            obj         : $(this),
            category    : 'Topics',
            action      : $(this).attr('href'),
            label       : document.location.pathname
        });
    });
    
    /* ピックアップ
    ----------------------------------- */
    $('body#pickup div#pickup_body a, body#pickup a.clickevent').each(function () {
        var click_place = $(this).attr('href');
        addCC({
            obj         : $(this),
            category    : 'Pick up',
            action      : $(this).attr('href'),
            label       : document.location.pathname
        });
    });
    
    /* その他
    ----------------------------------- */
    $('body:not(#index, #info, #pickup) a.clickevent').each(function () {
        var click_place = $(this).attr('href');
        addCC({
            obj         : $(this),
            category    : 'The others',
            action      : $(this).attr('href'),
            label       : document.location.pathname
        });
    });
    
});

