var xmlHttp

function hideNode(){ 
    hideNote();
}
function hideNote(){ 
    var elem = document.getElementById("VN")
    if(elem){
        elem.style.display = "none";
    }
}

function showNote(e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;

    if(targ.className == "onderschrift"){
        var myID = targ.innerHTML.split(" ").join();
        var myY;
        if(!e.pageY){
            myY = e.offsetY;
        }else{
            myY = e.pageY;
        }
        getNote(myID, myY);
    }
}


function getNote(myID, myY){
    if(myID != ""){
       var myP = 1;
       var start = 0;
       var end = 0;
       var thispage = document.location.href.substring(document.location.href.lastIndexOf("/")+1);
       thispage = thispage.toLowerCase();
       switch (thispage) {
          case "ambachtsheerlijkheid.html":
            start = 9;
            end = 1;
            break;
          case "heerlijkerechten.html":
            start = 24;
            end = 10;
            break;
          case "bestuur.html":
            start = 32;
            end = 23;
            break;
          case "uitbreiding.html":
            myP = "32a";
            start = 57;
            end = 33;
            break;
          default:
            break;
       }
       if(start > 0 && end > 0){
           for(i=start;i>=end;i--){
               if (myY > document.getElementById("h" + i).offsetTop){
                   myP = i;
                   break;
               }            
           }
       } 
       xmlHttp=getXMLHttpRequester();
       if (xmlHttp==null){
             //alert ("Your browser does not support AJAX!");
             return;
       } 
       var url = "../nofollow/getnote.aspx";
       url = url + "?id=" + myID;
       url = url + "&p=" + myP;
       url = url + "&sid=" + Math.random();
       xmlHttp.onreadystatechange = stateChanged;
       xmlHttp.open("GET",url,true);
       xmlHttp.send(null);
    }
}

function getXMLHttpRequester(){
    var xmlHttp=null;
    try{
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e){
      // Internet Explorer
      try{
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e){
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      }
    return xmlHttp;
}

function stateChanged(){ 
    if (xmlHttp.readyState==4){ 
        if (xmlHttp.status == 200) {
            var elem = document.getElementById("VN");
            if(elem){
                elem.innerHTML = xmlHttp.responseText;
                elem.style.top = mouy + 20 + "px";
                if(moux > 480){
                    elem.style.left = 480 + "px";
                }else{
                    elem.style.left = moux - 30 + "px";
                }
                elem.style.display = "block";
            }
        }
    }
}

// mouseposition
var moux, mouy
function getwindow() {
 var d = document, v = window, w, h, l, t;
 if( typeof v.innerWidth==='number' ) {
  w = v.innerWidth;
  h = v.innerHeight;
  l = v.pageXOffset;
  t = v.pageYOffset;
 } else if( ( v = d.documentElement ) &&
   typeof v.clientWidth==='number' &&
   v.clientWidth !== 0 || ( v = d.body ) ) {
  w = v.clientWidth;
  h = v.clientHeight;
  l = v.scrollLeft;
  t = v.scrollTop;
 }
 return {w: w, h: h, l: l, t: t};
}

function getmouse( e ) {
  e = e || window.event || {};
  var w = getwindow(),
   minx = w.l,
   miny = w.t,
   maxx = w.w + w.l,
   maxy = w.h + w.t;
  if( typeof e.pageX==='number' ) {
    moux = e.pageX;
    mouy = e.pageY;
  } else {
    moux = e.x + w.l;
    mouy = e.y + w.t;
  }
}

if( window.captureEvents ) { window.captureEvents( Event.MOUSEMOVE ); }
window.onscroll = getmouse;
window.onresize = getmouse;
window.document.onmousemove = getmouse;

if(document.captureEvents){
   document.captureEvents(Event.MOUSEOVER); 
   document.captureEvents(Event.MOUSEOUT); 
}
document.onmouseover = showNote;
document.onmouseout = hideNote;

