var onloadHandlers = [];
window.onload = function(){
	for(var i=0;i<onloadHandlers.length;i++){
		eval(onloadHandlers[i]);
	}
}

function xitiNavClick(section, name, url) {
    xt_med("C", section, name, "N", null, null, null, null);
    if (url){
        redirectAfterXiti(url);
    }
}

function xitiExitClick(section, clickName, url, popup) {
    if ((popup) && (popup!="'false'")) {
        xt_med("C", section, clickName, "S", url, 1, null, null);
    }
    else {
        xt_med("C", section, clickName, "S", url, null, null, null);
        redirectAfterXiti(url);
    }
}

function redirectAfterXiti(url){
    var img_is_loaded = 0;
    var redirect = function() {
        if (img_is_loaded==0){
            document.location = url;
            img_is_loaded = 1;
        }
    }
    xt_img.onload = function(){redirect;}
    self.setTimeout(redirect, 2000)
}

function setupXitiOnclicks(){
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i<anchors.length; i++) {
        var anchor = anchors[i];
        if(anchor.getAttribute("href") && anchor.getAttribute("rel") && 
            anchor.getAttribute("rel").split("-",1)[0] == "xt") {            
                var clickType = anchor.getAttribute("rel").split("-")[1];
                anchor.clickName = anchor.getAttribute("rel").split("-")[2];
                switch(clickType) {
                    case "exitclick":
                        anchor.onclick = function(){
                            xitiExitClick(xiti_level2, this.clickName, this.href, 1);
                            return false;
                        }
                        break;
                    case "navclick":
                        anchor.onclick = function(){
                            xitiNavClick(xiti_level2, this.clickName, this.href);
                            return false;
                        }
                        break;
                }
        }
    }
}onloadHandlers[onloadHandlers.length] = 'setupXitiOnclicks()';
