/*jQuery ga Event tracking 2011-12-15 Mikael Blomqvist slash x */
$(document).ready(function(){
	if ($('body').hasClass('ForexSE') && $('body').hasClass('lang-sv')) {
		$('a[href]').each(function(){	
			var curLink = $(this);
			var extTitle = curLink.attr('title');
			var href = $(this).attr('href');
			var filetypes = /\.(zip|exe|pdf|docx?|xlsx?|vcf|pptx?|mp3)$/i;
			//check for links starting with http or https, making sure that links to our own domain are excluded
			if ((href.match(/^https?\:/i)) && (!href.match(document.domain))){
				$(this).click(function() {
					var extLink = href.replace(/^https?\:\/\//i, '');
					if (extTitle != undefined && extTitle.length > 0) {
						_gaq.push(['_trackEvent', 'Utlänk', 'HTML', extLink+'_'+extTitle]);
						} else {
							_gaq.push(['_trackEvent', 'Utlänk', 'HTML', extLink]);
							}
				});
			}
			else if (href.match(/^mailto\:/i)){
				$(this).click(function() {
					var mailLink = href.replace(/^mailto\:/i, '');
					if (extTitle != undefined && extTitle.length > 0) {
						_gaq.push(['_trackEvent', 'Kontakt', 'Email', mailLink+"_"+extTitle]);
						} else {
							_gaq.push(['_trackEvent', 'Kontakt', 'Email', mailLink]);
							}
				});
			}
			else if (href.match(filetypes)){
				$(this).click(function() {
					var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
					var filePath = href.replace(/^https?\:\/\/www\.forex\.se\//i, '');
					var filename = filePath.replace(/^.*(\\|\/|\:)/, '');
					if (extTitle != undefined && extTitle.length > 0) {				
						_gaq.push(['_trackEvent', 'Dokument', 'Nedladdning av .' + extension, extTitle+"_"+decodeURI(filename)]);
						} else {
							_gaq.push(['_trackEvent', 'Dokument', 'Nedladdning av .' + extension, decodeURI(filename)]);
							}
				});
			}
			});
		
		}
});
