
function hofPageStateObj() {
	/* variables */	
	this.debug=false;	
	this.paginaguid='';
	this.detailguid='';
	this.soort='';
	this.thema='';
	
	this.activeContentMenuId='';
	this.activeContentMenuImageSelectedTxt='';
	this.activeContentMenuImageMouseOverTxt='';
	
	this.activeNavMenuId='';	
	this.activeNavMenuImageSelectedTxt='';
	this.activeNavMenuImageMouseOverTxt='';

	this.activeNavSubMenuId='';	
	
	this.pageHeaderImgId='';
	this.pageHeaderTxtId='';

	this.createHofGM=false;
	
	this.arSoort=new Array();
	this.arSoortMenuId=new Array();

	this.arThema=new Array();
	this.arThemaMenuId=new Array();
	this.arThemaMenuImg=new Array();
	this.arThemaHeaderImg= new Array();
	this.arThemaHeaderTxt= new Array();
	this.arThemaHoofdMenuId=new Array();
	this.arThemaSubMenuId= new Array();
	this.arThemaSubMenuImg= new Array();
	
	this.arPage=new Array();
	this.arPageMenuId= new Array();
	this.arPageMenuImg= new Array();
	this.arPageHeaderImg= new Array();
	this.arPageHeaderTxt= new Array();
	this.arPageHoofdMenuId= new Array();
	this.arPageSubMenuId= new Array();
	this.arPageSubMenuImg= new Array();
	
	/* functions */
	this.setPageGuid=hofSetPageGuid;
	this.addPage=hofAddPage;
	
	this.setDetailGuid=hofSetDetailGuid;
	
	this.setSoort=hofSetSoort;
	this.addSoort=hofAddSoort;

	this.setThema=hofSetThema;
	this.addThema=hofAddThema;
	
	this.setPageStates=hofSetPageStates;
	
	/* private functions */
	this.setObjectActive=hofSetObjectActive;
	this.setObjectNotActive=hofSetObjectNotActive;
	this.changeImage=hofChangeImage;
	this.changeTxt=hofChangeTxt
}

function hofSetPageGuid(guid) {
  this.paginaguid=guid;	
}

function hofAddPage(page, menuid, menuimg, headerimg, headertxt, hoofdmenuid, submenuid, submenuimg) {
// eigenlijk 'page' nog even voorzien van accolades als dat nodig blijkt!
  var i = this.arPage.length;
  this.arPage[i]=page;
  this.arPageMenuId[i]=menuid;
  this.arPageMenuImg[i]=menuimg;  
  if(headerimg)this.arPageHeaderImg[i]=headerimg;
  if(headertxt)this.arPageHeaderTxt[i]=headertxt;
  if(hoofdmenuid)this.arPageHoofdMenuId[i]=hoofdmenuid;
  if(submenuid)this.arPageSubMenuId[i]=submenuid;
  if(submenuimg)this.arPageSubMenuImg[i]=submenuimg;  
}

function hofSetDetailGuid(guid) {
  this.detailguid=guid;	
}

function hofSetSoort(soort) {
  this.soort=soort;	
}

function hofAddSoort(soort, menuid) {
  this.arSoort[this.arSoort.length]=soort;
  this.arSoortMenuId[this.arSoortMenuId.length]=menuid;
}

function hofSetThema(thema) {
  this.thema=thema;	
}

function hofAddThema(thema, menuid, menuimg, headerimg, headertxt, hoofdmenuid, submenuid, submenuimg) {
  var i = this.arThema.length;
  this.arThema[i]=thema;
  this.arThemaMenuId[i]=menuid;
  this.arThemaMenuImg[i]=menuimg;  
  if(headerimg)this.arThemaHeaderImg[i]=headerimg;
  if(headertxt)this.arThemaHeaderTxt[i]=headertxt;
  if(hoofdmenuid)this.arThemaHoofdMenuId[i]=hoofdmenuid;
  if(submenuid)this.arThemaSubMenuId[i]=submenuid;
  if(submenuimg)this.arThemaSubMenuImg[i]=submenuimg;  
}

function hofSetPageStates() {
	/* twee menu's instellen */
	var menu='';
	var menuimage='';
	var img;
	var s;
	
	/* Content Menu */
	if(this.soort!=''){
		for(i=0;i<this.arSoort.length;i++){
			if(this.arSoort[i]==this.soort){
				this.activeContentMenuId=this.arSoortMenuId[i];
			}
		}
	}
	if(this.activeContentMenuId==''){
		for(i=0;i<this.arSoortMenuId.length;i++){
			if(document.getElementById(this.arSoortMenuId[i])){
			  menu=this.arSoortMenuId[i];
			}
			if(menu!=''){
				this.activeContentMenuId=menu;
			}
		}
	}
	if(this.activeContentMenuId!='')SwitchContentMenu(this.activeContentMenuId);

	/* Navigation Menu */
	if(this.paginaguid!=''){
		for(i=0;i<this.arPage.length;i++){
			if(this.arPage[i]==this.paginaguid){
				this.activeNavMenuId=this.arPageMenuId[i];
				this.setObjectActive(this.arPageMenuImg[i], this.activeNavMenuImageSelectedTxt, '');				
				if((this.arPageHeaderImg.length>0)&&(this.arPageHeaderImg[i]!="")){				
  				this.changeImage(this.pageHeaderImgId, this.arPageHeaderImg[i]);					
				}				
				if((this.arPageHeaderTxt.length>0)&&(this.arPageHeaderTxt[i]!="")){
  				this.changeTxt(this.pageHeaderTxtId, this.arPageHeaderTxt[i]);					
				}				
				if(this.arPageHoofdMenuId.length>0){
				  this.setObjectActive(this.arPageHoofdMenuId[i], this.activeNavMenuImageSelectedTxt, '');
				}				
				if(this.arPageSubMenuId.length>0){
					this.activeNavSubMenuId=this.arPageSubMenuId[i];
					this.setObjectActive(this.arPageSubMenuImg[i], this.activeNavMenuImageSelectedTxt, '');
				}
			}
		}
	} 
	if(this.thema!=''){
		for(i=0;i<this.arThema.length;i++){
			if(this.arThema[i]==this.thema){
				this.activeNavMenuId=this.arThemaMenuId[i];
				this.setObjectActive(this.arThemaMenuImg[i], this.activeNavMenuImageSelectedTxt, '');
				if((this.arThemaHeaderImg.length>0)&&(this.arThemaHeaderImg[i]!="")){
  				this.changeImage(this.pageHeaderImgId, this.arThemaHeaderImg[i]);					
				}				
				if(this.arThemaHeaderTxt.length>0){
  				this.changeTxt(this.pageHeaderTxtId, this.arThemaHeaderTxt[i]);					
				}				
				if(this.arThemaHoofdMenuId.length>0){
					this.setObjectActive(this.arThemaHoofdMenuId[i], this.activeNavMenuImageSelectedTxt, '');
  			    }
				if(this.arThemaSubMenuId.length>0){
					this.activeNavSubMenuId=this.arThemaSubMenuId[i];
					this.setObjectActive(this.arThemaSubMenuImg[i], this.activeNavMenuImageSelectedTxt, '');
				}
			}
		}
	} 
	if(this.activeNavMenuId!='')SwitchNavMenu(this.activeNavMenuId);
	if(this.activeNavSubMenuId!='')SwitchSubNavMenu(this.activeNavSubMenuId);
	if(typeof(hofVastgoed)!='undefined')hofVastgoed.init();
//	if(hofGM&&hofGM.autoInit)hofGM.init();
}



function hofSetObjectActive(objId, selectedTxt, mouseoverTxt) {
	obj=document.getElementById(objId);
	if(obj){
  	if(obj.src){
  	  s = obj.src;
      if(s.substr(s.length-4-mouseoverTxt.length, mouseoverTxt.length)==mouseoverTxt) {
  	    obj.src=s.substr(0, s.length-4-mouseoverTxt.length)+selectedTxt+s.substr(s.length-4,5);
  	  } else {
  	    obj.src=s.substr(0, s.length-4)+selectedTxt+s.substr(s.length-4,5);
  	  }
  	} else {
  		if(obj.className!=''){
  	    s = obj.className;
  			obj.className=s+selectedTxt;
  		}
  	}
  }
}

function hofSetObjectNotActive(objId, selectedTxt, mouseoverTxt) {
	obj=document.getElementById(objId);
	if(obj){
  	if(obj.src){
  	  s = obj.src;
      if(s.substr(s.length-4-mouseoverTxt.length, mouseoverTxt.length)==mouseoverTxt) {
  	    obj.src=s.substr(0, s.length-4-mouseoverTxt.length)+selectedTxt+s.substr(s.length-4,5);
  	  } else {
  	    obj.src=s.substr(0, s.length-4-selectedTxt.length)+s.substr(s.length-4,5);
  	  }
  	} else {
  		if(obj.className!=''){
  	    s = obj.className;
  			obj.className=s.substr(0, s.length-selectedTxt.length);
  		}
  	}
  }
}

function hofChangeImage(objId, newSrc) {
	if (!newSrc) return; // geen plaatje, niet vervangen!
	
	obj=document.getElementById(objId);
	if(obj){
  	if(obj.src){
  		obj.src=newSrc;
    } else {
    	if(obj.background){
    		obj.background=newSrc;
        } else {
    		if(obj.style.backgroundImage){
    			obj.style.backgroundImage="url("+newSrc+")";
        	}
	}
    }
	}
}

function hofChangeTxt(objId, newTxt) {
	obj=document.getElementById(objId);
	if(obj){
    obj.innerHTML=newTxt; 
	}
}

function SwitchNavMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
  	if(el) {
    	if ((el.style.display=="none")||(el.style.display=="")){
    	  var ar = document.getElementById("masternavdiv").getElementsByTagName("span"); //DynamicDrive.com change
		   // if (!ar || ar.length==0)ar = document.getElementById("masternavdiv").getElementsByTagName("div");
    		if(el.style.display != "block"){ //DynamicDrive.com change
    			for (var i=0; i<ar.length; i++){
    				if (ar[i].className=="submenu") //DynamicDrive.com change
    				ar[i].style.display = "none";
    			}
    			el.style.display = "block";
    		}else{
    			el.style.display = "none";
    		}
    		
  	  }
	  }
  }
}

function SwitchSubNavMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
  	if(el) {
    	if ((el.style.display=="none")||(el.style.display=="")){
    	  var ar = document.getElementById("subnavdiv").getElementsByTagName("span"); //DynamicDrive.com change
		   // if (!ar || ar.length==0)ar = document.getElementById("masternavdiv").getElementsByTagName("div");
    		if(el.style.display != "block"){ //DynamicDrive.com change
    			for (var i=0; i<ar.length; i++){
    				if (ar[i].className=="submenu") //DynamicDrive.com change
    				ar[i].style.display = "none";
    			}
    			el.style.display = "block";
    		}else{
    			el.style.display = "none";
    		}
    		
  	  }
	  }
  }
}

function CloseNavMenu(){
	if(document.getElementById){
	  if(document.getElementById("masternavdiv")){
      var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
		// if (!ar || ar.length==0)ar = document.getElementById("masterdiv").getElementsByTagName("div");
  		for (var i=0; i<ar.length; i++){
  			if (ar[i].className=="submenu") //DynamicDrive.com change
  			ar[i].style.display = "none";
  		}
  	}
	}
}

function SwitchContentMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
    if(el) {
    	if ((el.style.display=="none")||(el.style.display==""))
		{
			var ar = document.getElementById("mastercontentdiv").getElementsByTagName("span"); //DynamicDrive.com change
			var found = false;
			for (var i=0; !found && i<ar.length; i++)
			{
    			if (ar[i].className=="submenu")
				{
					// een span voldoet aan de criteria, straks geen div's meer zoeken
					found = true;
				}
    		}
			if (!found)ar = document.getElementById("mastercontentdiv").getElementsByTagName("div");
			
    		if(el.style.display != "block"){ //DynamicDrive.com change
    			for (var i=0; i<ar.length; i++){
    				if (ar[i].className=="submenu") //DynamicDrive.com change
    				ar[i].style.display = "none";
    			}
    			el.style.display = "block";
    		}else{
    			el.style.display = "none";
    		}
        if((hofPageState.activeContentMenuId!="")&&(hofPageState.activeContentMenuId!=obj)){ 
          hofPageState.setObjectNotActive("contentMenuHd_"+hofPageState.activeContentMenuId, hofPageState.activeContentMenuImageSelectedTxt, hofPageState.activeContentMenuImageMouseOverTxt);
        }
        hofPageState.setObjectActive("contentMenuHd_"+obj, hofPageState.activeContentMenuImageSelectedTxt, hofPageState.activeContentMenuImageMouseOverTxt);

        hofPageState.activeContentMenuId=obj;
      }
    }
	}
}

function HS_swapImage(imgId) {
	var img = document.getElementById(imgId);
	var s;
	if(img) {
   	s = img.src;
   	if(s.substr(s.length-4-hofPageState.activeContentMenuImageSelectedTxt.length, hofPageState.activeContentMenuImageSelectedTxt.length)!=hofPageState.activeContentMenuImageSelectedTxt) {
      img.src=s.substr(0, s.length-4)+hofPageState.activeContentMenuImageMouseOverTxt+s.substr(s.length-4,5);
    }
	}
}

function HS_swapImgRestore(imgId) {
	var img = document.getElementById(imgId);
	var s;
	if(img) {
   	s = img.src;
   	if(s.substr(s.length-4-hofPageState.activeContentMenuImageMouseOverTxt.length, hofPageState.activeContentMenuImageMouseOverTxt.length)==hofPageState.activeContentMenuImageMouseOverTxt) {
      img.src=s.substr(0, s.length-4-hofPageState.activeContentMenuImageMouseOverTxt.length)+s.substr(s.length-4,5);
    }
	}
}

if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
document.write('</style>\n')
}

var hofPageState = new hofPageStateObj();

/***********************************************
* Google maps 
***********************************************/
function hofGMObj()
{
	this.debug=false;
	this.autoInit=true;
	this.map="";
	this.mapid="googlemap";
	this.smallmapcontrol=true;
	this.maptypecontrol=true;
	this.zoomlevel=15;
	this.currentPoint="";
	this.currentPointCoords="";

	this.geocoder = new GClientGeocoder();
	
	this.arPoints = new Array();
	this.arPointsCoords = new Array();
	this.arPointsHtml = new Array();
	
	this.addPoint=hofGmAddPoint;
	this.init=hofGmInit;
	this.createMarker=hofCreateMarker;
	this.searchAddress=hofSearchAddress;
	this.unload=this.map.GUnload;
	this.centerPoint=hofCenterPoint;
}

function hofGmAddPoint(pointCoords, html)
{
  if(pointCoords)
  {
	var i = this.arPoints.length;
	  var point = eval("new GLatLng("+pointCoords+")");
	  if(point)
	  {
		  this.arPoints[i]=point;
		  this.arPointsCoords[i]=pointCoords;
		  this.arPointsHtml[i]=html;
	  }
  }
}

function hofGmInit()
{
	var mapdiv = document.getElementById(this.mapid);
  if(mapdiv)
  {
	// width: 475px; height: 300px
	// mapdiv.style.width ="475px";
	// mapdiv.style.height ="300px";

	this.map = new GMap2(mapdiv);
	if(this.smallmapcontrol)this.map.addControl(new GSmallMapControl());
	if(this.maptypecontrol)this.map.addControl(new GMapTypeControl());
	var showhtml = true;
	if(!this.currentPointCoords)
	{ 
	  if(this.arPointsCoords[0])
	  { 
	    this.currentPointCoords=this.arPointsCoords[0];
	  }
	  else 
	  {
	    this.currentPointCoords="52.307450,5.139782";
	  }
	  showhtml = false;
	}
	this.currentPoint = eval("new GLatLng("+this.currentPointCoords+")");
	this.map.setCenter(this.currentPoint, this.zoomlevel);
	
	for(i=0;i<this.arPoints.length;i++)
	{
		var m=this.createMarker(this.arPoints[i], this.arPointsHtml[i])
		this.map.addOverlay(m);
		if(showhtml && this.arPointsCoords[i]==this.currentPointCoords)m.openInfoWindowHtml(this.arPointsHtml[i]);
	}
  }
}

function hofSearchAddress(address) {
  var a = address.toLowerCase();
  if((a.indexOf(", nl")==-1)&&(a.indexOf(",nl")==-1))address=address+", NL";
  var o = this;
  this.geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        alert(address + " niet gevonden!");
      } else {
        o.map.setCenter(point, 13);
        var marker = new GMarker(point);
        o.map.addOverlay(marker);
        marker.openInfoWindowHtml(address);
      }
    }
  );
}

function hofCreateMarker(point, html) {
  var marker = new GMarker(point);
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(html);
  });
  return marker;
}

function hofCenterPoint(coords)
{
	if (coords)
	{
		this.currentPointCoords = coords;
		this.currentPoint = eval("new GLatLng("+this.currentPointCoords+")");
		this.map.setCenter(this.currentPoint, this.zoomlevel);
	}
}
