﻿$(document).ready(function () {
        var currHref = window.location.pathname.toLowerCase().replace("default.aspx", "");
        //var currHref = window.location.pathname.toLowerCase().replace("default.aspx", "") + '//';

        //Track external links and downloads
        var filetypes = /\.(zip|exe|pdf|doc*|xls*|ppt*|mp3|mov|avi|wmv)$/i;
        $('a').each(function () {
            //if ($(this).attr('href')) {
            // alert(($(this).attr('href')));
            // }
            if (!($(this).attr('name'))) {
                var href = $(this).attr('href');
               // alert(href);

                if ((href.match(/^https?\:/i)) && (!href.match(document.domain))) {
                    $(this).click(function () {
                        var extLink = href.replace(/^https?\:\/\//i, '');
                        // pageTracker._trackPageview('/outgoing-link/' + extLink);
                        // _gaq.push(['_setAccount', 'UA-3913786-1']);
                        _gaq.push(['_trackPageview', '/outgoing-link//' + currHref + '//' + extLink]);
                      //  alert('/outgoing-link//' + currHref + '//' + extLink);
                    });
                }
                else if (href.match(/^mailto\:/i)) {
                    $(this).click(function () {
                        var mailLink = href.replace(/^mailto\:/i, '');
                        //pageTracker._trackPageview ('/mail-link/' + mailLink);
                        // _gaq.push(['_setAccount', 'UA-3913786-1']);
                        _gaq.push(['_trackPageview', '/mail-link//' + currHref + '//' + mailLink]);
                    //    alert('/mail-link/' + currHref + mailLink);
                    });
                }
                else if (href.match(filetypes)) {
                    $(this).click(function () {
                        var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
                        var filePath = href.replace(/^https?\:\/\/(www.)mydomain\.com\//i, '');
                        //alert ('/file-link/' + extension  + filePath);
                        //pageTracker._trackPageview ('/file-link/' + extension  + filePath);
                        //  _gaq.push(['_setAccount', 'UA-3913786-1']);
                        _gaq.push(['_trackPageview', '/file-link/' + currHref + '//DownloadFrom/' + filePath]);
                     //   alert('/file-link/' + currHref + '//DownloadFrom/' + filePath);
                    });
                }
            }
        });
    });
