﻿var activeMarker;
var marker=[];
var arrLaatstBekeken = new Array();
var arrObjects = new Array();
    function AddToLaatstBekeken(detailhtml, html, id){
        var bFound = false;
        //array doorzoeken
        for (var a = 0; a < arrLaatstBekeken.length; a++) {
            if(id==arrLaatstBekeken[a][0]){
                bFound=true;
            }
        }
        //nog niet gevonden.
        if(!bFound){
            var arrTemp = new Array();
            arrTemp[0]=id;
            arrTemp[1]=html;
            arrTemp[2]=detailhtml;
            arrLaatstBekeken[arrLaatstBekeken.length] = arrTemp;
        }
    }

    function loadMarks(xmlDoc){
        marker=[];
        arrObjects =  new Array();
        var strResults = "";
        var pcs = xmlDoc.documentElement.getElementsByTagName("pc");
        document.getElementById("overzichtlijst").innerHTML="";
        arrLaatstBekeken = new Array();
        if(pcs.length==0){
            document.getElementById("gmnoresults").style.display="";
        }
        for (var a = 0; a < pcs.length; a++) {
            
            var id  = pcs[a].getAttribute("id");
            var markertype =  pcs[a].getAttribute("markertype");
          
            if(markertype==11 || markertype==12){
                if(markertype==11){
                    var box2omschrijving = pcs[a].getElementsByTagName("i2")[0].firstChild.nodeValue;
                }else{
                    var box2omschrijving = ""
                }
                var omschrijving = ""
                var box1omschrijving = ""
                
                var resultaat = ""
                var laatstbekeken  = ""
            }else{
                var omschrijving = pcs[a].getElementsByTagName("oms")[0].firstChild.nodeValue;
                var box1omschrijving = pcs[a].getElementsByTagName("i1")[0].firstChild.nodeValue;
                var box2omschrijving = pcs[a].getElementsByTagName("i2")[0].firstChild.nodeValue;
                var resultaat = pcs[a].getElementsByTagName("r")[0].firstChild.nodeValue;
                var laatstbekeken  = pcs[a].getElementsByTagName("l")[0].firstChild.nodeValue;
            }
            var arrObject = new Array();
            arrObject[0]=id;
            arrObject[1]=omschrijving;
            arrObject[2]=pcs[a].getAttribute("marklat");
            arrObject[3]=pcs[a].getAttribute("marklong");
            arrObject[4]=box1omschrijving;
            arrObject[5]=box2omschrijving;
            arrObject[6]=resultaat;
            arrObject[7]=laatstbekeken;
            
            
            arrObjects[a] = arrObject;
            addMarker(a,arrObject[2],arrObject[3],omschrijving,resultaat,box1omschrijving,box2omschrijving, markertype);
            strResults+= resultaat + "";
        }
        //document.getElementById("overzichtlijst").innerHTML=strResults
    }
    
    

function InfoBox(marker,divHeight, anchorOffsetX, anchorOffsetY, divHtml) 
{
    this.marker = marker;
    this.divHeight = divHeight;
    this.anchorOffsetX = anchorOffsetX;
    this.divHtml = divHtml
    if (null == this.anchorOffsetX){
        this.anchorOffsetX = 0;
    }

    this.anchorOffsetY = anchorOffsetY;

    if (null == this.anchorOffsetY){
        this.anchorOffsetY = 0;
    }

}

InfoBox.prototype = new GOverlay();

InfoBox.prototype.initialize = function(map) 
{
    var div = document.createElement("div");
    div.style.position = "absolute";
    div.innerHTML = this.divHtml
    div.style.left 	= (map.fromLatLngToDivPixel(this.marker.getPoint()).x - this.anchorOffsetX)+ 'px';
    div.style.top 	= (map.fromLatLngToDivPixel(this.marker.getPoint()).y - this.divHeight - this.anchorOffsetY) + 'px';
    map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
    this.map_ = map;
    this.div_ = div;
    this.marker.hide();
}

InfoBox.prototype.remove = function() 
{
    this.div_.parentNode.removeChild(this.div_);
}

InfoBox.prototype.redraw = function(force) 
{
    this.div_.style.left = (this.map_.fromLatLngToDivPixel(this.marker.getPoint()).x - this.anchorOffsetX)+ 'px';
    this.div_.style.top = (this.map_.fromLatLngToDivPixel(this.marker.getPoint()).y - this.divHeight - this.anchorOffsetY) + 'px';
}
function gotoBookmark(el){
    document.location='#'+el;
}

function showBox2(){
    map.removeOverlay(activeMarker.overlay);
    map.addOverlay(activeMarker.overlayBox2);
    map.setCenter(new GLatLng(parseFloat(arrObjects[activeMarker.PointId][2])+0.02, parseFloat(arrObjects[activeMarker.PointId][3])+0.045),12);
}
function closeOverlay()
{	
    if (activeMarker)
    {
        map.removeOverlay(activeMarker.overlay);
        map.removeOverlay(activeMarker.overlayBox2);
        activeMarker.show();
    }
    activeMarker = false;
    return false;
}

function addMarker(a,ilat,ilong, oms, resultaat, box1, box2, markertype){

    var icon = new GIcon();
    if(markertype==1){
        icon.image = "/img/icoon_google_1.gif";
    }
    if(markertype==2){
        icon.image = "/img/icoon_google_1.gif";
    }
    
    //21.24
    icon.iconSize = new GSize(23,27);
    icon.iconAnchor = new GPoint(17,34);

    var newmarker = new GMarker(new GLatLng(ilat,ilong), icon);
    newmarker.divBox1 = box1;
    newmarker.divBox2 = box2;
    newmarker.oms = oms;
    newmarker.resultaat = resultaat;
    newmarker.PointId = a;
    
    GEvent.addListener(newmarker, "mouseover", function() {
        if (activeMarker){
            closeOverlay();
        }
        activeMarker=this;
        activeMarker.overlay = new InfoBox(activeMarker, 31, 17, 3, box1);
        activeMarker.overlayBox2 = new InfoBox(activeMarker, 31, 17, 130, box2);
        map.addOverlay(activeMarker.overlay);
    });
    marker[a]=newmarker;
   
    map.addOverlay(newmarker);
}

