/* cn.ca - Google Analytics integration
2012-01-06 Modifie les clic events du banner rotator
2011-11-14 - Tracker les clics sur les bannieres du carrousel sur page d'accueil
2011-09-01 - Modifications to mailto tracking and RSS subscriptions
2011-08-31 - store QueryString arguments, internal campaigns tracking
2011-08-30 - New version for deeper analysis
v1.1 2011-08-23 - bug fix for addthis
v1.0 2011-08-16 - initial version
Created by SHamel@CardinalPath.com for Revolver3.com
*/



jQuery(document).ready(function ($) {
    // helper function
    jQuery.expr[':'].regex = function(e, i, m) {
        var mP = m[3].split(','),
            l = /^(data|css):/,
            a = {
                method: mP[0].match(l) ? mP[0].split(':')[0] : 'attr',
                property: mP.shift().replace(l, '')
            },
            r = new RegExp(mP.join('').replace(/^\s+|\s+$/g, ''), 'ig');
        return r.test(jQuery(e)[a.method](a.property));
    };

    // store QueryString arguments in object
    var qs = {};
    location.search.replace(/([^?=&]+)(=([^&]*))?/g, function ($0, $1, $2, $3) {
        qs[$1] = $3;
    });

    // internal campaigns tracking
    if (qs.s_icid) {
        _gaq.push(['_trackEvent', 'icid', qs.s_icid, document.referrer.match(/\/\/[^/]+(\/.*)/)[1]]);
    }


    // media download tracking
    jQuery('a:regex(href,.(pdf|jpe*g|png|gif|tif+)$)').live('mouseup', function(e) {
        _gaq.push(['_trackEvent', 'download', 'click', this.href.replace(/^.*\/\//, '')]);
    });

    // outbound tracking (except addthis)
    jQuery('a[href^="http"]:not([href*="addthis.com"]):not([href*="//' + location.host + '"])').live('click', function(e) {
        _gaq.push(['_trackEvent', 'outbound', 'click', this.href.match(/\/\/(.+)/)[1]]);
    });

    // mailto tracking
    jQuery('a[href^="mailto"]').live('click', function(e) {
        _gaq.push(['_trackSocial', 'email', 'send', this.href.replace(/^mailto:/i, '')]);
    });

    // addThis Track Social
    typeof addthis != "undefined" && addthis.addEventListener('addthis.menu.share', function (e) {
        _gaq.push(['_trackSocial', 'addthis', e.data.service]);
    });

    // RSS subscriptions
    jQuery('a.rss,a.rss_icon').click(function(e) {
        _gaq.push(['_trackSocial', 'rss', 'subscribe', this.href.match(/([^/]+\.xml)/)[1]]);
    });
	
	
     // banner rotator 
     jQuery('#banner_container a').live('click', function(){ 
     _gaq.push(['_trackEvent', 'InternalBanner', 'Clicks', 'Banner ' + (jQuery('#banner_container a').index(jQuery(this)) + 1)]); 
     });



	
});
