//write the proper googlemaps key
$(document).ready(delta_init);
var hTab = 1;
var hTimer =null;
var mainnav=0;
function delta_init(){	
setNewWindowLinks();
imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
 $('.openAsPrintable').click(function(){window.print();});
  if($('#homebg1').length >0){

        $('#navclienten').hover(function(){
                  if(hTimer){clearInterval(hTimer );}
                  
                   $('#homebg1').show();
			       $('#homebg2').hide();
			       $('#homebg3').hide();
                   hTab =1;
                   startHomeLoop();
                    return false;
                },
                function(){
                  return false;
                 }
                );
      $('#navbezoekers').hover(function(){
                  if(hTimer){clearInterval(hTimer );}
                   $('#homebg1').hide();
			       $('#homebg2').show();
			       $('#homebg3').hide();
                     hTab =2;
                   startHomeLoop();
                      return false;
                },
                function(){
                  return false;
                 }
                );

      $('#navprofessionals').hover(function(){
               if(hTimer){clearInterval(hTimer );}
                   $('#homebg1').hide();
			       $('#homebg2').hide();
			       $('#homebg3').show();
               hTab =3;
                   startHomeLoop();
                    return false;
                },
                function(){
                  return false;
                 }
                );
       startHomeLoop();
                 
      $('#pagevisual img').each(
         function(){
           var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$|\.swf$/;
	       var urlType = this.src.toLowerCase().match(urlString);
	        $('#pagevisual').show();
            if(urlType =='.swf'){
             // alert(this.src);
              hi= this.height;
              wi = this.width ;
             // alert(hi + " " + wi);
           //  alert(this.attributes["width"].value);
              if(hi < 80){hi=this.attributes["height"].value;}
              if(wi < 80){wi=this.attributes["width"].value;}

              var s1 = new SWFObject(this.src,"ply",wi ,hi ,"9","#FFFFFF");
		      s1.write("pagevisual");

            }
            
         }
       );         
   }else{
   //vervolg main nav hovers
if(document.location.href.toLowerCase().indexOf('.nl/familienaasten/') > 0){
mainnav = 2;
}else if(document.location.href.toLowerCase().indexOf('.nl/professionals/') > 0){
mainnav = 3;
}else if(document.location.href.toLowerCase().indexOf('.nl/clienten/') > 0){
mainnav = 1;
}

showMainNav();

      $('#navclienten').hover(function(){
                   $('#mainnav1').show();
			       $('#mainnav2').hide();
			       $('#mainnav3').hide();
                    return false;
                },
                function(){
                  showMainNav();
                   return false;
                 }
                );
                
      $('#navbezoekers').hover(function(){
                   $('#mainnav1').hide();
			       $('#mainnav2').show();
			       $('#mainnav3').hide();
                      return false;
                },
                function(){
                 showMainNav();
                    return false;
                 }
                );

      $('#navprofessionals').hover(function(){
                   $('#mainnav1').hide();
			       $('#mainnav2').hide();
			       $('#mainnav3').show();
                    return false;
                },
                function(){
                showMainNav();
				 return false;
                 }
                );
       
   }            
   if(IsAdminForm==0){
	   for(i=0;i<document.links.length;i++){
	     if(document.links[i].href.toLowerCase().indexOf(".flv")>0
	     || document.links[i].href.toLowerCase().indexOf(".wmv")>0){
	       document.links[i].onclick= function(){
					var t = this.title || this.name || null;
					var a = this.href || this.alt;
					var g = this.rel || false;
					tb_show(t,a,g);
					this.blur();
					return false;
					};
	
	     }
	   }
   }
   getFontSize();
}
function startHomeLoop(){
hTimer = setInterval("homeLoop()",5000);
}
function homeLoop(){
hTab++;
if(hTab  >3){
 hTab =1;
}
switch(hTab ){
   case 1:
     $('#homebg1').show();
     $('#homebg2').hide();
     $('#homebg3').hide();
     break;
   case 2:
     $('#homebg1').hide();
     $('#homebg2').show();
     $('#homebg3').hide();
     break;
   case 3:
     $('#homebg1').hide();
     $('#homebg2').hide();
     $('#homebg3').show();
     break;
    
}   
//alert('loop');
}
function showMainNav(){
switch(mainnav){
   case 0:
     $('#mainnav1').hide();
     $('#mainnav2').hide();
     $('#mainnav3').hide();
     break;

   case 1:
     $('#mainnav1').show();
     $('#mainnav2').hide();
     $('#mainnav3').hide();
     break;
   case 2:
     $('#mainnav1').hide();
     $('#mainnav2').show();
     $('#mainnav3').hide();
     break;
   case 3:
     $('#mainnav1').hide();
     $('#mainnav2').hide();
     $('#mainnav3').show();
     break;
    
}   
//alert('loop');
}

/* silly functions */
function setExternalTarget(){
  allHref  = document.links;
  for(i=0;i<allHref.length;i++){
     obj = allHref[i].href;
     if(obj.toLowerCase().indexOf("http://") ==0 && obj.toLowerCase().indexOf("http://"+document.location.hostname) <0){
       allHref[i].target="_blank";
     }
     ext = obj.substr(obj.lastIndexOf('.')).toLowerCase();
     if(ext =='.pdf' || ext=='.doc'){
       allHref[i].target="_blank";
     }
  }
}

var fOut = "";
function setFout(cid){

	       if(fOut != ""){
		      mobj=document.getElementById(fOut );
	          if(mobj&& mobj.style){ 
			       mobj.style.display='none';
			       if(mobj.parentNode){
			       mobj.parentNode.className="";
			       }
		           fOut ="";
	          } 
		   }
    }
function ToggleFAQ(contentid){
		   
		   setFout(contentid);
		   obj=document.getElementById(contentid);
		   if(obj && obj.style){ 
		      if(obj.style.display=='none'){
		      obj.style.display = 'block';
		       if(obj.parentNode){
			       obj.parentNode.className="sel";
			       }

		      }else{
		      if(obj.parentNode){
			       obj.parentNode.className="";
			       }
		      obj.style.display = 'none';
		      }
		      fOut = contentid;
		   }
	}

	function ToggleContent(contentid){
		   obj=document.getElementById(contentid);
		   if(obj && obj.style){
		      if(obj.style.display=='none'){
		      obj.style.display = 'block';
		      }else{
		      obj.style.display = 'none';
		      }
		   }
		}
		function getArgs(  ) {
    var args = new Object(  );
    var query = location.search.substring(1);     
      // Get query string
    var pairs = query.split(",");
     // Break at comma
    for(var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('=');
          // Look for "name=value"
        if (pos == -1) continue;
          // If not found, skip
        var argname = pairs[i].substring(0,pos);
          // Extract the name
        var value = pairs[i].substring(pos+1);
          // Extract the value
        args[argname] = unescape(value);
         // Store as a property
       // In JavaScript 1.5, use decodeURIComponent(  ) 
       // instead of escape(  )
    }
    return args;     // Return the object
}
var cindex = 0;
var notfound="";
var lastMarker=null;
var cIcon=null;
var cmsmode = 0;					 
function showAddress(setCenter) {
    
	 if(cindex <mapitems.length){
	 if(cmsmode !=undefined){
	   if( cmsmode==-1 && mapitems.length==1){
	   //alert(mapitems[0][3]);
	    document.location=mapitems[0][3];
	 }else if( cmsmode==1 && mapitems.length==1){
	  alert("Anonymous user will be redirected to: "+mapitems[0][3]);
	 }}
	          gaddress = mapitems[cindex][1];
	          geocoder.getLatLng(mapitems[cindex][0],
	                   function( point) {
	                        if (!point) {
	                          notfound+=mapitems[cindex][0] + " not found\n";
				            } else {
				              mapitems[cindex][4] = point;
				              if(setCenter==1){
				                map.setCenter(point,16);
				              }
				             if(cIcon ==null){
				              cIcon =new GIcon(G_DEFAULT_ICON);
							  cIcon.image = '/images/gcmaps.png';
							  cIcon.iconSize = new GSize(42,47);
							  cIcon.iconAnchor = new GPoint(21, 47);
							  cIcon.infoWindowAnchor = new GPoint(21, 0);
							  cIcon.imageMap = new Array(0,0, 42,0, 42,47, 0,47);
				
							 }
				               var marker = new PdMarker(point,cIcon );
							  marker.address = mapitems[cindex][0];
							  marker.pagehref = mapitems[cindex][3];
	                          var desc = mapitems[cindex][1];
	                         // alert(marker.address);
	                          lastMarker = marker;
				              map.addOverlay(marker);
	                         // GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml("<div class='mapdesc'>"+desc+"</div>");});
	                          GEvent.addListener(marker, "click", function() {document.location=this.pagehref});
	                          GEvent.addListener(marker, "mouseover", function() {marker.openInfoWindowHtml("<div class='mapdesc'>"+desc+"</div>");});
	                        }
				            cindex++;
				            setTimeout('showAddress()',0);
	                  });
	      
	  }else{
		if(notfound!=''){
		   alert(notfound);
		}else{

			map.zoomToMarkers(12,0);
		}

	  }
    }

function processRouteResult()
{
    // TODO test if any route was found
    var sm = lastMarker ;
    if (sm) {
        sm.closeInfoWindow();
    }
    // enable print-button
    //var print = document.getElementById('printroute');
    //print.className = '';
    // TODO adjust margins for route
    // TODO add 'clear route' link
}


function processRouteLoad()
{
    // this method gets called when a user submits a route request
}

function processErrorResult()
{
alert('Uw postcode of straat, plaatsnaam kan niet door Google gevonden worden');
    // this method gets called when a user submits a route request
}
var dir = null;
function submitRouteForm(form)
{
    var sm = lastMarker ;

    if (sm) {
        if(dir != null){
          dir.clear();
        }
        dir = new GDirections(window.map, document.getElementById('route'));
      
        document.getElementById('route').innerHTML='';
        GEvent.addListener(dir, "load", processRouteLoad);
        GEvent.addListener(dir, "addoverlay", processRouteResult);
        GEvent.addListener(dir, "error", processErrorResult);
      //  alert(form.departure.value+" " +sm.address);
        dir.loadFromWaypoints([form.departure.value,sm.address], {locale:"nl_NL"});
    }

    return false;
}
function KeypressedSubmitForm() {
if (window.event && window.event.keyCode == 13){


 if(document.forms[0]["searchbox"]){
    // alert(document.forms[0]["searchbox"].value+"hoi");
     url = "/search/results.aspx?k="+escape(document.forms[0]["searchbox"].value);
     //alert(url);
     document.location.href =url ;
   }
 return false;
}else{
 return false;
}
 return false;

}
function KeypressedSubmitRouteForm() {
if (window.event && window.event.keyCode == 13){
 submitRouteForm(document.forms[0]);
 return false;
}else{
 return false;
}
 return false;

}
waterM = 0;
function focusRouteBox(box){
 if(waterM ==0){
  box.value='';
  waterM =1;
 }
}
function ValidateZoekBox(){
   //alert('ValidateZoekBox validatioin not complete');
   if(document.forms[0]["searchbox"]){
     //alert(document.forms[0]["searchbox"].value);
     document.location = "/search/results.aspx?k="+escape(document.forms[0]["searchbox"].value);
   }
   //document.forms[0].submit();
   return true;
  
}
function setNewWindowLinks(){
  dlinks = document.links;
	for(i=0;i<dlinks.length;i++){
    hf=dlinks[i].href;
	if(hf.indexOf(document.location.hostname) <0 && hf.indexOf("javascript:") <0 ){
		dlinks[i].target="_blank";
	}
	if(hf.indexOf('?')>0){
	  hf=hf.substr(0,hf.indexOf('?'));
	}
	/*last4 =hf.substr(hf.length-4,4).toLowerCase();
	if(last4=='.txt' 
	   || last4=='.pdf' 
	   || last4=='.txt' 
	   || last4=='.jpg' 
	   || last4=='.gif' 
	   || last4=='.wmv' 
	   || last4=='.mp3'){
		dlinks[i].target="_blank";
	
	}*/
	//alert(last4); 
  }
}

