﻿var GA_ThisURL = window.location.href;
var GA_StrippedURL = GA_ThisURL.replace(/^https?:\/\//, "");

var TFGaUtils = {
    init: function () {
        TFGaUtils.MarkSpotLinks();
        TFGaUtils.MarkOutboundLinks();
        TFGaUtils.MarkDownloadLinks();
        TFGaUtils.MarkProjectApp();
    },
    MarkSpotLinks: function () {

        jQuery('.spot').each(function () {
            var spotTitle = jQuery("h2", this).text();
            jQuery("a", this).click(function () {
                try {
                    _gaq.push(['_trackEvent', 'Spots', 'Click', spotTitle + " - " + GA_StrippedURL]);
                } catch (err) { }
            });
        });

    },
    MarkOutboundLinks: function () {
        jQuery('a:not([href*="' + document.domain + '"]),a:not([href^="javascript"]),a:not([href="#"])').click(function () {
            try {
                _gaq.push(['_trackEvent', 'Outgoing links', 'Click', jQuery(this).attr('href') + ' - "' + GA_StrippedURL]);
            } catch (err) { }
        });
    },
    MarkProjectApp: function () {
        jQuery('#search-app').click(function () {
            try {
                _gaq.push(['_trackEvent', 'Projektsoeger', 'Click', 'Klik paa soger tab']);
            } catch (err) { }
        });

        jQuery('#project-search-app-tab').click(function () {
            try {
                _gaq.push(['_trackEvent', 'Projektsoeger', 'Click', 'Klik paa soger options']);
            } catch (err) { }
        });

 jQuery('#projects-tab-nav li a').click(function () {
            
            try {
                var tabName = jQuery(this).text();
                _gaq.push(['_trackEvent', 'Projektsoeger', 'Click', 'Projekt tab: ' + tabName]);
            } catch (err) {
              
            }
        });



    },
    MarkDownloadLinks: function () {

        jQuery("a[href$='.ashx']").click(function () {
            var $adl = jQuery(this);
            var hrefdl = $adl.attr('href');
            try {
                _gaq.push(['_trackEvent', 'Downloads', 'Click', hrefdl + ' - ' + GA_StrippedURL]);
            } catch (err) { }
        });

    }
};
