var _gaq = _gaq || [];
_gaq.push(['corp._setAccount', 'UA-13240430-3']);
_gaq.push(['corp._setDomainName','.businessliv.dk']);
_gaq.push(['corp._setAllowHash',false]);
_gaq.push(['corp._setAllowLinker',true]);
_gaq.push(['corp._trackPageview']);
_gaq.push(['lidtmere._setAccount', 'UA-13240430-9']);
_gaq.push(['lidtmere._setDomainName','.businessliv.dk']);
_gaq.push(['lidtmere._setAllowHash',false]);
_gaq.push(['lidtmere._setAllowLinker',true]);
_gaq.push(['lidtmere._trackPageview']);
_gaq.push(['lidtmere2._setAccount', 'UA-8677821-1']);
_gaq.push(['lidtmere2._setDomainName','.businessliv.dk']);
_gaq.push(['lidtmere2._setAllowHash',false]);
_gaq.push(['lidtmere2._setAllowLinker',true]);
_gaq.push(['lidtmere2._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);
})();

/***
* This script will add tracking for Google Analytics, when a user clicks on a link to an external site
* or a link to an e-mail (mailto)
* The virtual pageview will register as: "/out/[url]" where [url] is the destination url of the link
* The virtual pageview of mailto-links will register as: "/mailto/[email]" where [email] is the target e-mail-address of the mailto link
* To exclude this tracking on a link, set the "rel" tag to "notoutbound" like this <a href="http://domain.com" rel="notoutbound">Link</a>
* To exclude all tracking to certain domains, use the array below
*
* Guava Online Marketing - www.guava.dk
***/

var virtualpage_add_ref = true;
var virtualpage_path_out = "/vpv/out/";
var virtualpage_path_mail = "/vpv/mailto/";
var notoutbound_list = new Array();
notoutbound_list.push('boghuset.dk');
notoutbound_list.push('lidtmere.dk');
notoutbound_list.push('businessliv.dk');
notoutbound_list.push('muvio.dk');

trackOutboundLinks = function () {
    var pageTracker = _gat._getTracker("UA-13240430-9");
    if (pageTracker) { /* Expression to check for absolute internal links. */
        var isAbsolute = new RegExp("^(https?):\/\/", "i");
        var isMailto = new RegExp("^mailto:", "i");
        var isInternal = new RegExp("^(https?):\/\/www.businessliv.dk/", "i");

        /* Find all A tags on page and evaluate them for outbound links when they are clicked */
        var links = document.getElementsByTagName("a");
        for (var i = 0; i < links.length; i++) {
            links[i].onclick = function () {
                var href = this.getAttribute("href");
                var rel = this.getAttribute("rel"); /* Go through list of domains to exclude and match the current link href */
                var isInExclList = false;
                if (notoutbound_list.length) {
                    for (var i = 0; i < notoutbound_list.length; i++) {

                        if (new RegExp(notoutbound_list[i], "i").test(href)) {
                            isInExclList = true;
                        }
                    }
                }

                if (href && !(rel && rel.match(/notoutbound/i)) && !isInExclList) {
                    var virtualpage = "";

                    /* If the link is a link to an e-mail */
                    if (isMailto.test(href)) {
                        var email = href.split(":").pop();
                        virtualpage = virtualpage_path_mail + email;
                    } /* If the link has absolute address which is not the current domain (an outbound link) */
                    if (isAbsolute.test(href) && !isInternal.test(href)) {
                        virtualpage = virtualpage_path_out + href;
                    }
                    if (virtualpage) {
                        if (virtualpage_add_ref) {
                            // Add location as parameter on the virtual page
                            virtualpage += "?ref=" + location.href;
                        }
                        pageTracker._trackPageview(virtualpage);
                       // alert(virtualpage); return false; // Use this for debugging
                    }
                }
            }
        }
    }
}
//window.onload = trackOutboundLinks;
$(document).ready(function () { 
  setTimeout(trackOutboundLinks, 1000);
});

