﻿function swapMapContent(areaID){
    var selectedItem = areaID.split('-')[1];
    var infoTextContainers = document.getElementById("infoTextContainer").getElementsByTagName("div");
    
    if(infoTextContainers.length > selectedItem){
        for(var itc = 0; itc < infoTextContainers.length; itc++){
            if(infoTextContainers[itc].id.split('-')[0] != "infoLinkDiv"){
                if(infoTextContainers[itc].id.split('-')[1] == selectedItem){
                    infoTextContainers[itc].style.zIndex = 1;
                }else{
                    infoTextContainers[itc].style.zIndex = 0;
                }
            }
        }
    }
}
function displayMapAreaName(areaAlt){
    /*
    if(areaAlt == ""){
        areaAlt = "Move your mouse over an area and click on it.";
    }
    */
    
    document.getElementById("displayMapAreaName").innerHTML = areaAlt;
}
function clickLocation(areaID){
    var areaNumber = areaID.split('-')[1];
    var mapXYLocations = document.getElementById("mapXYLocations").getElementsByTagName("div");
    var mapAreas = document.getElementById(areaID).parentNode.getElementsByTagName("area");
    
    for(var i = 0; i < mapXYLocations.length; i++){
        var status = mapXYLocations[i].childNodes[0].src.split('/')[mapXYLocations[i].childNodes[0].src.split('/').length - 1].split('.')[0].split('-')[1];
            
        if(areaNumber == mapXYLocations[i].id.split('-')[1]){
            mapXYLocations[i].childNodes[0].src = mapXYLocations[i].childNodes[0].src.replace(status, "Active");
        }else{
            if(status == "Active"){
                mapXYLocations[i].childNodes[0].src = mapXYLocations[i].childNodes[0].src.replace(status, "Passive");
            }
        }
    }
    swapMapContent(areaID);
    
    for(var ma = 0; ma < mapAreas.length; ma++){
        if(mapAreas[ma].id == areaID){
            mapAreas[ma].onclick = "";
            mapAreas[ma].onmouseover = new Function("displayMapAreaName(this.alt);");
            mapAreas[ma].onmouseout = new Function("displayMapAreaName('');");
        }else{
            mapAreas[ma].onclick = new Function("clickLocation(this.id);");
            mapAreas[ma].onmouseover = new Function("displayMapAreaName(this.alt); overLocation(this.id);");
            mapAreas[ma].onmouseout = new Function("displayMapAreaName(''); outLocation(this.id);");
        }
    }
}
function overLocation(areaID){
    var areaNumber = areaID.split('-')[1];
    var mapXYLocations = document.getElementById("mapXYLocations").getElementsByTagName("div");
    
    for(var i = 0; i < mapXYLocations.length; i++){
        if(areaNumber == mapXYLocations[i].id.split('-')[1]){
            var status = mapXYLocations[i].childNodes[0].src.split('/')[mapXYLocations[i].childNodes[0].src.split('/').length - 1].split('.')[0].split('-')[1];
            
            mapXYLocations[i].childNodes[0].src = mapXYLocations[i].childNodes[0].src.replace(status, "Over");
        }
    }
}
function outLocation(areaID){
    var areaNumber = areaID.split('-')[1];
    var mapXYLocations = document.getElementById("mapXYLocations").getElementsByTagName("div");
    
    for(var i = 0; i < mapXYLocations.length; i++){
        if(areaNumber == mapXYLocations[i].id.split('-')[1]){
            var status = mapXYLocations[i].childNodes[0].src.split('/')[mapXYLocations[i].childNodes[0].src.split('/').length - 1].split('.')[0].split('-')[1];
            
            mapXYLocations[i].childNodes[0].src = mapXYLocations[i].childNodes[0].src.replace(status, "Passive");
        }
    }
}