$(document).ready(function(){
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    $.getScript(gaJsHost + "google-analytics.com/ga.js", function(){

    	try {
            var pageTracker = _gat._getTracker("UA-5982037-2");
            pageTracker._trackPageview();
        } catch(err) {}

        var filetypes = /\.(zip|exe|pdf|doc|docx|xls|xlsx|ppt|pptx|pps|ppsx|eps|tif|mp3|download)$/i;

        $('a').each(function(){
            var href = $(this).attr('href');
            var title = $(this).attr('title');
            if ((href.match(/^https?\:/i)) && (!href.match(document.domain)) ){
                $(this).click(function() {
                    var extLink = href.replace(/^https?\:\/\//i, '');
                    pageTracker._trackEvent('External', 'Click', extLink);
                });
            }
            else if (href.match(/^mailto\:/i)){
                $(this).click(function() {
                    var mailLink = href.replace(/^mailto\:/i, '');
                    pageTracker._trackEvent('Email', 'Click', mailLink);
                });
            }        
            else if (href.match(filetypes)){
            	$(this).click(function() {
                    var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
                    var filePath = href.replace(/^https?\:\/\/www\.svensktnaringsliv\.se\//i, '');
                    var mediaID = href.match(/([0-9]+)a\.[a-z0-9]+$/i);
                    if (title == ''){
                    	var trackTitle = filePath;
                    }
                    else{
                    	var trackTitle = title + ' [' + mediaID[1] +']';
                    }
                    pageTracker._trackEvent('Downloads', ga_prop13, trackTitle);
                });
            }
        });
    });
});

