﻿/* Google Analytics */

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2565858-1']);
_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);
})();


function trackIt(qstring, ignoredir) {
	if (_gaq) {
        if (ignoredir) {
            if (qstring.length == 0) {
                _gaq.push(['_trackPageview']);
            }else{
                _gaq.push(['_trackPageview', '/' + qstring]);
            }
        }else{
            if (qstring.length == 0){
                /* get page URL, hash and QueryString for pass-through */
                qs = location.search;
                hash = location.hash;
                path = location.pathname;
                if (path.length < 2){
                    path = '';
                }else{
                    /* removes starting slash */
                    path = path.substring(1);
                }
				
                /* combine */
                fullpath = path + qs + hash;

                _gaq.push(['_trackPageview', '/' + fullpath]);
            }else{
                _gaq.push(['_trackPageview', '/' + qstring]);
            }
        }
    }
}

function setLinkAnalytics() {
    /* Add click event for Google Analtyics */
    $("a:pdf, a:zip").live("click", function () {
        var thisHref = $(this).attr('href');
        var lp = location.pathname;
        var lastSlash = location.pathname.lastIndexOf('/');
        if (thisHref.substr(0, 1) != '/') {
            /* is a relative link */
            thisHref = location.pathname.substr(1, lastSlash) + thisHref;
        }
        trackIt(thisHref, false);
    });
    $("a:external").live("click", function () {
        trackIt('linkout/' + this.href.replace('http://', '').replace('https://', ''), true);
    });
    $("a:mailto").live("click", function () {
        trackIt('mailto/' + this.href.replace('mailto:', ''), true);
    });
}

