var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-3973508-1']);
_gaq.push(['_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)
})();
jQuery(document).ready(function () {
	if( jQuery('a[data-gatrack]').length != 0 ){ jQuery('a[data-gatrack]').GAnalytics(); }
    var hrefa, url1, url2, pathname;
    filetypes = /\.doc$|\.xls$|\.exe$|\.zip$|\.pdf$|\.mp3$|\.psd$/i;
    jQuery("a").each(function () {
    		if((hrefa = jQuery(this).attr("href"))){
    			if (hrefa.match(/^mailto\:/i)) {
	            url1 = jQuery(this).attr("href").replace(/^mailto\:/i, "");
	            pathname = window.location.pathname;
	            url2 = pathname.replace(/^http\:\/\/(www\.)*/i, "");
	            jQuery(this).click(function () {
	                _gaq.push(['_trackEvent', url2, 'Email', url1])
	            })
	        } else if (location.host != this.host.replace(/\:80$/i, "")) {
	            url1 = hrefa.replace(/^http\:\/\/(www\.)*/i, "");
	            pathname = window.location.pathname;
	            url2 = pathname.replace(/^http\:\/\/(www\.)*/i, "");
	            jQuery(this).click(function () {
	                _gaq.push(['_trackEvent', url2, 'Outgoing link', url1])
	            })
	        } else if (hrefa.match(filetypes)) {
	            url1 = hrefa.replace(/^(http\:\/\/)*(www\.)*(okay\.colruytgroup\.be)*\//i, "");
	            pathname = window.location.pathname;
	            url2 = pathname.replace(/^http\:\/\/(www\.)*/i, "");
	            jQuery(this).click(function () {
	                _gaq.push(['_trackEvent', url2, 'Download', url1])
	            })
	        }
      	}
    })
});

jQuery.fn.GAnalytics = function(){
	if(window._gaq) {		
	jQuery(this).bind("click",function(){
		try {
			var gatrack = jQuery(this).attr('data-gatrack');
			gatrack = gatrack.split('-');
			_gaq.push(['_trackEvent', gatrack[0], gatrack[1], gatrack[2]]);
			
		} catch(e){}
		
	});
	}

};
