var bgURLHome = "";
var currentImagePath = "";
var curNavItem = new Array(2);
var oldNavItem = new Array(2);
var currentPage = new Array();
var isRestore=false;
oldNavItem = ["",0];

function setNavBackground(img){
    document.getElementById('navigation').style.backgroundImage = 'url(' + img + ')';
}

function showHome(bgURL) {
    bgURLHome = bgURL;
    /*document.getElementById('navigation').style.backgroundImage = 'url(' + bgURLHome + ')';*/
}


function showNav2(area){
	if ( (typeof divInnerNav[area[0]]) != 'undefined' ) {
        /*document.getElementById('navigation').style.backgroundImage = 'url(' + area[1] + ')';*/
        document.getElementById('navB').style.visibility = 'visible';
        document.getElementById('navB').innerHTML = divInnerNav[area[0]];
        document.getElementById('checkDiv').style.left = -136;
        if ( navigator.appName.indexOf("Microsoft") != -1 ) {
            document.getElementById('bgNavBforIE').style.visibility = "visible";
        }
   }else {
       hideNav2();
   }
    if(!isRestore){
        handleHigh(area[0], 2);
    }
}

function showNav3(areaPath){
	//wird von 2 aufgerufen

    if ( (typeof divInnerNav[areaPath]) != 'undefined' ) {
        //alert("drin");
        document.getElementById('navC').style.visibility = 'visible';
        document.getElementById('navC').innerHTML = divInnerNav[areaPath];
        document.getElementById('checkDiv').style.left = 0;
        if ( navigator.appName.indexOf("Microsoft") != -1 ) {
            document.getElementById('bgNavCforIE').style.visibility = "visible";
        }
    } else {
        //hat keine dritte ebene, also 'hideNav'
        hideNav3();
    }
	if(!isRestore){
	    handleHigh(areaPath, 3);
	}
}

function hideNav2(){
    document.getElementById('navB').style.visibility = 'hidden';
    /*document.getElementById('navigation').style.backgroundImage = 'url(' + bgURLHome + ')';*/
    document.getElementById('bgNavBforIE').style.visibility = "hidden";
}


function hideNav3(){
    document.getElementById('navC').style.visibility = 'hidden';
    document.getElementById('bgNavCforIE').style.visibility = "hidden";
}

function restore() {
	isRestore = true;
	var handle = "";
    var arr = new Array();

    if (currentPage[2] == 1) {
        hideNav2();
        hideNav3();
       /* if(oldNavItem!='undefined' && oldNavItem[1]==3){
            btnLo([oldNavItem[0].substring(0, oldNavItem[0].lastIndexOf("/")),2]);
        }*/

    } else if (currentPage[2] == 2) {
        showNav2(currentPage);
        hideNav3();
    } else if (currentPage[2] == 3) {

        showNav3(currentPage[0]);
        handle = currentPage[0].substring(0, currentPage[0].lastIndexOf("/"));
        //handle = handle.substring(0, handle.lastIndexOf("/"));
        showNav2([handle,currentImagePath]);
		//document.getElementById('info').innerHTML = currentPage[0] +"<br>"+handle;

    }else if (currentPage[2] == 4) {
        handle = currentPage[0].substring(0, currentPage[0].lastIndexOf("/"));
        showNav3(handle);
        handle = handle.substring(0, handle.lastIndexOf("/"));
        showNav2([handle,currentImagePath]);

    }
    //erste Navi-Ebene enthighlighten
	if(oldNavItem!='undefined'){
		if(oldNavItem[1]==2){
       		btnLo(oldNavItem);
	   	}else if(oldNavItem[1]==3){
       		btnLo([oldNavItem[0].substring(0, oldNavItem[0].lastIndexOf("/")),2]);
	   	}
    }
	isRestore = false;
	oldNavItem = ["",0];
}

//setzt Highlighting ueber Handle
function setHighlighting(area){
    currentPage = area;
    //alert(currentPage[2]);
}

/*function setCurrentImagePath(path){
    currentImagePath = path;
}*/

//
function handleHigh(areaPath, level){

    curNavItem = [areaPath,level];
	if(oldNavItem[0]!="" ){
		if(curNavItem[1] == 3 && oldNavItem[1] == 2){
            //ein Level hoeher: nichts machen

        } else if (curNavItem[1] == 2 && oldNavItem[1] == 3){
            //ein Level tiefer
            //btnLo(oldNavItem);

            //wenn anderer Bereich:
            var area = oldNavItem[0].substring(0, oldNavItem[0].lastIndexOf("/"));
            if(area != curNavItem[0]){
                //alert(area);
				btnLo([area, 2]);
            }else{
				btnLo(oldNavItem);
			}

        } else {
            //gleiches Level
            btnLo(oldNavItem);
        }

	}
	btnHi(curNavItem);
	oldNavItem = curNavItem;
}

function isActive(area){
    //var b = false;
    //wenn handle von area groesser als von currentPage, dann ist Seite nicht aktiv
    if (currentPage[2] < area[1] ) {
        return false;
    } else if (currentPage[2] == area[1]) {
        //wenn es die gleiche Seite ist, dann ist diese aktiv
        if (area[0] == currentPage[0]) {
            return true;
        }
    } else if (currentPage[2] > area[1]) {
        if(currentPage[0].length > area[0].length){
            if(currentPage[0].substring(0, area[0].length) == area[0]){
                return true;
            }else {
                return false;
            }
        }else {
            return false;
        }
    }
}

function btnHi(area){
    if(!isActive(area)){
        if(area[1]==2){
            document.getElementById(area[0]).style.backgroundPosition = '0 40px';
        }else if(area[1]==3){
            document.getElementById(area[0]).style.backgroundPosition = '0 21px';
        }
    }
}


function btnLo(area){
    if(!isActive(area)){
        document.getElementById(area[0]).style.backgroundPosition = '0 0';
    }
}

function preload(imageObj,imageSrc) {
        if (document.images) {
            eval(imageObj+' = new Image();');
            eval(imageObj+'.src = "'+imageSrc+'";');
        }
    }

	function showImage(imageObj){
		return eval(imageObj+".src");
	}

	function  setNavBackgroundZufall(path){
        if (window.location.href.indexOf(path+"/norditube/") != -1) {

        } else if (window.location.href.indexOf(path+"/kmg/") != -1 || window.location.href.indexOf(path+"/kmg.html" != -1)){
             var img1 = path+"/docroot/cpt/graphics/content/kmg_header_01.jpg";
             var img2 = path+"/docroot/cpt/graphics/content/kmg_header_02.jpg";
             var zufall = Math.round(Math.random())+1;
             setNavBackground(eval("img"+zufall));

        } else {
             var img1 = path+"/docroot/cpt/graphics/nav/corporate.jpg";
             var img2 = path+"/docroot/cpt/graphics/nav/technology.jpg";
             var img3 = path+"/docroot/cpt/graphics/nav/construction.jpg";
             var img4 = path+"/docroot/cpt/graphics/nav/sales.jpg";
             var zufall = Math.round(Math.random()*3)+1;
             setNavBackground(eval("img"+zufall));
        }

     }
