// Settings
var hhDownloadExtensions = "avi,bmp,bz2,doc,docx,dwg,dxf,emf,eps,exe,gz,jpg,mov,mp3,mpg,msi,odg,odp,ods,odt,pdf,png,pps,ppsx,ppt,pptx,rar,rss,rtf,svg,tar,tif,txt,wav,wmf,wmv,xls,xlsx,xml,zip";
var hhSiteDomains = "nordic-modular.com,nordicmodular.com,www.nordic-modular.com,www.nordicmodular.com";

/* Google Analytics setup */

var _gaq = _gaq || [];
function hhSetupGA() {
    _gaq.push(['_setAccount', 'UA-17038484-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';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
    })();
}
hhSetupGA();
hhReplaceEvent(window, function() { hhSetupEvents("_gaq", null, null); }, null, 'load');

/*
 * Setup standard onclick events with optional hooks
 * Version 1.5a
 */
function hhSetupEvents(t, h1, h2) {
    var a = document.getElementsByTagName("A");
    if (a != null) {
        var b, d, e;
        var domainList = null;
        if ((b = /^https?:\/\/([^:\/]*)/i.exec(document.URL)) != null && b.length == 2)
            domainList = "," + b[1].toLowerCase() + "," + (hhSiteDomains != null ? hhSiteDomains + "," : "");
        for (var i = 0; i < a.length; i++) {
            if (a[i].href == null)
                continue;
            d = e = null;
            if (h1 != null && typeof (h1) == "function") {
                h1(a[i]);
            }
            if (domainList != null && (b = /^https?:\/\/([^:\/]*)[^\/]*(.*)$/i.exec(a[i].href)) != null && b.length == 3 && b[1].length > 0 && domainList.indexOf("," + b[1].toLowerCase() + ",") < 0) {
                d = "Exit: " + b[1].toLowerCase() + b[2].replace(/^\/$/, "");
                e = b[0];
            } else if ((b = /^mailto:(.*)$/i.exec(a[i].href)) != null && b.length == 2 && b[1].length > 0) {
                d = "Mail: " + b[1].toLowerCase();
                e = b[0].toLowerCase();
            } else if ((b = /^https?:\/\/[^\/]*(\/.*)\.([^.]*)$/i.exec(a[i].href)) != null && b.length == 3 && b[1].length > 0 && ("," + hhDownloadExtensions + ",").indexOf("," + b[2].toLowerCase() + ",") >= 0) {
                d = "File: " + b[1] + "." + b[2];
                e = b[1] + "." + b[2];
            } else if ((b = /^https?:\/\/[^\/]*(\/.*)([?&])([a-z][a-z]*)(=1.*)$/i.exec(a[i].href)) != null && b.length == 5 && b[3].length > 0 && ("," + hhDownloadExtensions + ",").indexOf("," + b[3].toLowerCase() + ",") >= 0) {
                d = "File: " + b[1] + b[2] + b[3] + b[4];
                e = b[1] + b[2] + b[3] + b[4];
            } else if (a[i].href.match(/^ *javascript:.*print.*\( *\) *;? *$/i) && hhGaPath != null && hhGaPath != "") {
                d = "Print: " + document.title;
                e = hhGaPath.replace(/\?.*$/, "") + "?print";
            }
            if (e != null && h2 != null && typeof (h2) == "function") {
                e = h2(e);
            }
            if (d != null) {
                //hhOnClick(a[i], "var t = document.title; document.title = '" + d.replace(/([\'\\])/g, "\\$1") + "'; " + t + ".push(['_trackPageview', '" + e.replace(/([\'\\])/g, "\\$1") + "']); document.title = t;");
                hhOnClick(a[i], "var t = document.title; document.title = '" + d.replace(/([\'\\])/g, "\\$1") + "'; " + t + "._getAsyncTracker()._trackPageview('" + e.replace(/([\'\\])/g, "\\$1") + "'); document.title = t;");
            }
        }
    }
}

/*
 * Add a query-string parameter
 * Version 1.1
 */
function hhAddParameter(u, n, v) {
    if (n == null || n == "" || v == null || v == "")
        return u;
    return u + (u.indexOf("?") == -1 ? "?" : "&") + encodeURIComponent(n) + "=" + encodeURIComponent(v);
}

/*
 * Add or replace an onclick event to an element
 * Version 2.0
 */
var hhExistingClickHandlers = new Object();
function hhOnClick(e, g) {
    hhReplaceOnClick(e, g, null);
}
function hhReplaceExistingOnClick(e, g) {
    var r;
    if ( ! (r = hhExistingClickHandlers[e]) )
        r = null;
    hhExistingClickHandlers[e] = g;
    hhReplaceOnClick(e, g, r);
}
function hhReplaceOnClick(e, g, r) {
    hhReplaceEvent(e, g, r, "click");
}
function hhReplaceEvent(e, g, r, n) {
    if ( typeof(e) != "object" || n == null )
        return;
    var f = (typeof(g) == "function" ? g : hhGetEventHandler(g));
    var q = (typeof(r) == "function" ? r : hhGetEventHandler(r));
    if ( typeof(e.addEventListener) == "function" || typeof(e.addEventListener) == "object" ) {
        if ( q != null ) {
            e.removeEventListener(n, q, false);
        }
        if ( f != null ) {
            e.removeEventListener(n, f, false);
            e.addEventListener(n, f, false);
        }
    } else if ( typeof(e.attachEvent) == "function" || typeof(e.attachEvent) == "object" ) {
        if ( q != null ) {
            e.detachEvent('on' + n, q);
        }
        if ( f != null ) {
            e.detachEvent('on' + n, f);
            e.attachEvent('on' + n, f);
        }
    }
}

/*
 * Create or get an event handler from a code string
 * Version 1.2
 */
var hhLiteralEventHandlers = new Object();
function hhGetEventHandler(t) {
    var f;
    if ( t == null )
        return null;
    if ( (f = hhLiteralEventHandlers[t]) != null )
        return f;
    f = hhLiteralEventHandlers[t] = new Function("e", t);
    return f;
}

