﻿var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-215450-2']);
//_gaq.push(['_setAccount', 'UA-999999-9']);
_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 () {
    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|epub|mobi)$/i;
    jQuery('a').each(function () {
        //if ($(this).attr('href')) {
        // alert(($(this).attr('href')));
        // }
        if (!(jQuery(this).attr('name'))) {
            var href = jQuery(this).attr('href');
            //alert(href);
            if (href != undefined) {
                if ((href.match(/^https?\:/i)) && (!href.match(document.domain))) {
                    jQuery(this).click(function () {
                        var extLink = href.replace(/^https?\:\/\//i, '');
                        // pageTracker._trackPageview('/outgoing-link/' + extLink);
                        // _gaq.push(['_setAccount', 'UA-4468083-3']);
                        _gaq.push(['_trackPageview', '/outgoing-link/' + currHref + '/' + extLink]);
                        //alert('/outgoing-link' + currHref + extLink);
                    });
                }
                else if (href.match(/^mailto\:/i)) {
                    jQuery(this).click(function () {
                        var mailLink = href.replace(/^mailto\:/i, '');
                        //pageTracker._trackPageview ('/mail-link/' + mailLink);
                        // _gaq.push(['_setAccount', 'UA-4468083-3']);
                        _gaq.push(['_trackPageview', '/mail-link/' + currHref + mailLink]);
                        //alert('/mail-link/' + currHref + mailLink);
                    });
                }
                else if (href.match(filetypes)) {
                    jQuery(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-4468083-3']);
                        _gaq.push(['_trackPageview', '/file-link-page:' + currHref + '/file-type:' + extension + '//file-downloaded:' + filePath]);
                        //alert('/file-link' + currHref + 'DownloadFrom/' + extension + filePath);
                    });
                }
            }
        }
    });

});
