var subnav = 6;
var leftnav = 9;



function onPopState(event){
    state = event.state;
    if(state){
        getContent(state.adnologies.content,state.adnologies.info);
        getSideMenu(state.adnologies.subNavId);
    }/*else{
        window.location=window.location;
    }*/
}
window.onpopstate = onPopState;

function subnavMouseOver(id){
    
    for(var i = 1; i<=subnav ; ++i){
        var div = document.getElementById('subnav'+(i));
        if(div){
            if(i==id){
                div.style.display = '';
            }else{
                div.style.display = 'none';
            }
        }else{
            return;
        }
    }
}


function getContent(content,info){
    var contentPfad = '/content'+jsBase;
    //var contentPfad = 'content/';
    
    if(content){
        $('#content').load(contentPfad+content);

    }
    if(info){
        var pindex = content.lastIndexOf('.');
        var infoZiel = content.substr(0, pindex)+'_info.'+content.substr(pindex+1);
        $('#infobox').load(contentPfad+infoZiel);
        $('#infobox').css('display', '');
    }else{
        $('#infobox').css('display', 'none');
    }
    
}

function getSideMenu(id){
    for(var i = 1; i<=leftnav ; ++i){
        var div = document.getElementById('leftnav'+(i));
        if(div){
            if(i==id){
                div.style.display = '';
            }else{
                div.style.display = 'none';
            }
        }else{
            return;
        }
    }
}

function menuClick(subNavId,content,info){

    
    content = content.replace(window.location.protocol+'//'+window.location.host,'');
    
    if(window.history.pushState&&content)
        window.history.pushState({
            'adnologies':{
                'content':content,
                'info':info,
                'subNavId':subNavId
            }
        },'adnologies.com',content);
    
    //history.replaceState(link);
    index = content.match(/[a-z]+[/][-a-z0-9]+/g)
    if(typeof title!='undefined'){
        if(index.length){
            if(typeof title[index[0]]!='undefined'){
                document.title = title[index[0]];
            }
        }
    }
    getContent(content,info);
    getSideMenu(subNavId);
    setEnecto(content);

}


function ajaxCallback(responseString,responseStatus,jQueryRequest){
    
}


function setEnecto(path){
    var site = "http://www.adnologies.com";
    path = path.replace(/\/(en|de)/, '');
    var src =window.location.protocol+'//trk.enecto.com/track?cust_id=8a8484e6245ccb2f01248057e49944d8&purl='+escape(site + path)+'&ref='+escape(document.referrer)+ '&tm=' + new Date().getTime() ;
    document.getElementById('enecto_img').src = src;
}

function setHeias(){
    HEIAS_T=Math.random();
    HEIAS_T=HEIAS_T*10000000000000000000;
    var shop_id='7000';
    var HEIAS_SRC='https://ads.heias.com/x/heias.ret.px.fr/?PX=HT|' + HEIAS_T + '|n|6556|cus|6584|pb|1|shop_id|' + shop_id + '';

    document.getElementById('heias_iframe').src = HEIAS_SRC;

}
