var map;
var Settings = new Array();;

var editor = null;
var x      = 0;
var home_cat_actief = 0;
var sluitTimers = new Array();
var currentNumber = 4;
var totaalAantal = 0;
var l_verborgen = 1;
var r_verborgen = 0;
var huidig_nr = 1;

var nu_links = 0;

var fader = new Array();
var hash = new Array();
var lijst = new Array();

function popUp(URL, breed, hoog) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=" + breed + ",height=" + hoog + ",left=150,top=150');");
}

function popUpcontent(name, inhoud, breed, hoog) {
  var generator=window.open(name,'popup','height=' + hoog + ',width=' + breed + 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,left=150,top=150');
  generator.document.write('<html><head><title>' + name + '</title><link rel="stylesheet" href="/css/site_popup.css" type="text/css"/></head><body>');
  generator.document.write(inhoud);
  generator.document.write('</body></html>');
  generator.document.close();
}

function htmlarealaden () {
	if (typeof (velden) == "object") {
		for (x=0; x < velden.length; x++) { 
        var oFCKeditor = new FCKeditor( velden[x] ) ;
        oFCKeditor.BasePath = webadres + "jsf/fckeditor/" ;
        oFCKeditor.Height	= 550;
				oFCKeditor.Width = 620;
				oFCKeditor.ToolbarSet = 'Default';
        //oFCKeditor.Config['ToolbarStartExpanded'] = false ;								
        oFCKeditor.ReplaceTextarea();		
		}
	}
}

function putfocus (formInst, elementInst) {
	if (document.forms.length > 0) {
		document.forms[formInst].elements[elementInst].focus();
		document.forms[formInst].elements[elementInst].select();
	}
}

function isset(variable_name)
{
try
{
if (typeof(eval(variable_name)) != 'undefined')
if (eval(variable_name) != null)
return true;
} catch(e) { }

return false;
}



function parsepagina () {
	htmlarealaden();
	
	/*
	if (fader.length) {
	  setTimeout(function() { throb(0); }, 1000);
	}
	*/

}

window.onload = parsepagina;

function initializeGoogleMaps(type, smallMap, MapType) {
//  var lijst = new Array();
	//'9831NK', '53.2554409239027', '6.46268463797039'
//	alert(ac_postcode + ' - ' + ac_lon + ' - ' + ac_lat);
//	lijst[0] = Array(ac_titel, ac_postcode, ac_lat, ac_lon);
 
  if (GBrowserIsCompatible()) {
	// Create our "tiny" marker iconvar
	  blueIcon = new GIcon(G_DEFAULT_ICON);
	  blueIcon.image = webadres + "img/thb/google_icon.gif";
	  blueIcon.iconSize = new GSize(30, 29);

	  redIcon = new GIcon(G_DEFAULT_ICON);
	  redIcon.image = webadres + "img/thb/punaise.gif";
	  redIcon.iconSize = new GSize(42, 60);

// Set up our GMarkerOptionsobject
markerOptions = { icon:blueIcon };
markerOptions2 = { icon:redIcon };		
	
	
    map = new GMap2(document.getElementById(type));
    
	Settings.x = lijst[0][3];
	Settings.y = lijst[0][2];
	Settings.z = 9;
	typeMap = 'NORMAL';
	
	if (document.getElementById('Tab'+typeMap))
	    document.getElementById('Tab'+typeMap).id = 'CurrentTab'
    
    map.setCenter(new GLatLng(lijst[0][2], lijst[0][3]), 9);

	if (typeMap != 'NORMAL')
	{
	    if (document.getElementById('CurrentTab')) Control.KlikKaartType(document.getElementById('CurrentTab'), typeMap)
	}

		/*
		if (smallMap) {
      map.addControl(new GSmallMapControl());
    }
		
		if (MapType) {
      map.addControl(new GMapTypeControl());
    }		
		*/


    	//map.addControl(new GMapTypeControl());		
		map.addControl(new GOverviewMapControl());
		//map.addControl(new GScaleControl());
		//map.addControl(new GLargeMapControl());
	    map.enableContinuousZoom();
	    map.enableDoubleClickZoom();

		
    // Creates a marker at the given point
    // Clicking the marker will hide it
    function createMarker(latlng, number) {
		  if (lijst[number][7] == 1) {
        var marker = new GMarker(latlng, markerOptions2);
			} else {
        var marker = new GMarker(latlng, markerOptions);3
			}
			
      marker.value = number;

      GEvent.addListener(marker,"click", function() {
       // var myHtml = "<a style='cursor:pointer;display:block;text-decoration:none' href='" + webadres + "advertentie/" + lijst[number][5] + "?1" + lijst[number][6] + "'><img style='float:left;border:1px solid #D9d9d9;margin:5px;height:60px;width:90px;' src='" + webadres + "php/verwerk/thumbnail.php?code=" + lijst[number][4] + "'><div style='float:left'><span style='color: #649519;font-size:16px;font-weight:bold; margin-right:10px;'>" + lijst[number][0] + "</span><br/>" + lijst[number][1] + "<br/>" + lijst[number][8] + "</div></a>";
        var myHtml = "<div class='gmappopup'><a style='cursor:pointer;display:block;text-decoration:none' href='" + webadres + "advertentie/" + lijst[number][5] + "?1" + lijst[number][6] + "'><img style='float:left;border:1px solid #D9d9d9;margin:5px;height:60px;width:90px;' src='" + webadres + "php/verwerk/thumbnail.php?code=" + lijst[number][4] + "'><div style='float:left'><span class='adres' style='color: #649519;font-size:16px;font-weight:bold; margin-right:10px;'>" + lijst[number][0] + "</span><div class='postcode'>" + lijst[number][1] + "</div><div class='prijs'>" + lijst[number][8] + "</div></div></a></div>";
				map.openInfoWindowHtml(latlng, myHtml);
      });
      return marker;
	}

		if (lijst.length) {
      for (var i = 0; i < lijst.length; i++) {
        var latlng = new GLatLng(lijst[i][2],lijst[i][3]);
      	map.addOverlay(createMarker(latlng, i));
      }
		}
  }
}


function in_array(my_array,my_value){
	caseSensitive = in_array.arguments.length<3?0:in_array.arguments[2];

	for(i=0;i<my_array.length;i++){
		if((caseSensitive==0?my_array[i]:my_array[i].toUpperCase())==(caseSensitive==0?my_value:my_value.toUpperCase())){
			return true;
		}
	}

	return false;
}

function hasOptions(obj) {if (obj!=null && obj.options!=null) { return true; }	return false;}
function swapOptions(obj,i,j) {	var o = obj.options;	var i_selected = o[i].selected;	var j_selected = o[j].selected;	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);	o[i] = temp2;o[j] = temp;o[i].selected = j_selected;o[j].selected = i_selected;}
function moveOptionUp(obj) {if (!hasOptions(obj)) { return; }	for (i=0; i<obj.options.length; i++) {if (obj.options[i].selected) {if (i != 0 && !obj.options[i-1].selected) { swapOptions(obj,i,i-1);	obj.options[i-1].selected = true;}}} volgordeclasses ();}
function moveOptionDown(obj) {if (!hasOptions(obj)) { return; }	for (i=obj.options.length-1; i>=0; i--) {if (obj.options[i].selected) {if (i != (obj.options.length-1) && ! obj.options[i+1].selected) { swapOptions(obj,i,i+1);	obj.options[i+1].selected = true; }}} volgordeclasses ();}
function submitForm(url, veld) { var	list = document.getElementById(veld); 	var velden = '';	for (i = 0; i <= list.options.length - 1; i++) { 	velden = velden + '_SPLIT_' + list.options[i].value;}	window.location.href = url + velden; }
function volgordeclasses () {
	list		= document.getElementById('volgorde');
	var	kleur	= 'nee';

	for (i = 0; i <= list.options.length - 1; i++) {
		if (kleur == 'ja') {
			list.options[i].className = 'een';
			kleur = 'nee';
		} else {
			list.options[i].className = 'twee';
			kleur = 'ja';
		}

		if (typeof(volgordetitel) == "object") {
			for (a=0;a < volgordetitel.length;a++) {
				if (volgordetitel[a] == list.options[i].value) {
						list.options[i].style.color = 'red';
				}
			}
		}
	}
}

function agenda_kies () {
  select1 = document.getElementById('agenda_jaar');
	
	document.location.href = webadres + 'agenda/' + select1.value;
}

function agenda_kies2 () {
  select1 = document.getElementById('agenda_jaar');
	select2 = document.getElementById('agenda_maand');
	
	document.location.href = webadres + 'agenda/' + select1.value + '/' + select2.value;
}

function weergeefSWF(src, width, height, id, flashvars) {
   document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '" id="' + id + '" align="middle">');
   document.write('<param name="wmode" value="transparent"><param name="flashvars" value="' + flashvars + '"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + webadres + 'swf/' + src + '" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />');
   document.write('<embed src="' + webadres + 'swf/' + src + '" flashvars="' + flashvars + '" quality="high" bgcolor="#ffffff" width="' + width + '" height="' + height + '" name="' + id + '" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
   document.write('</object>');
}

function swfMovie (movie) {
  document.write('<object type="application/x-shockwave-flash" data="' + webadres + 'flv/flvplayer.swf" width="450" height="337"><param name="movie" value="' + webadres + 'flv/flvplayer.swf"><param name="flashvars" value="file=' + movie + '"></object>');
}


function scroll_down () {
  box = document.getElementById('fotothumbs');
	
	box.scrollTop = box.scrollTop + 2;
}

function scroll_up () {
  box = document.getElementById('fotothumbs');
	
	box.scrollTop = box.scrollTop - 2;
}

function set_scroll_down (type) {
  if (type) {
	 down_timer = setInterval('scroll_down()', 5); 
	} else {
	 clearInterval(down_timer);
	}
}

function set_scroll_up (type) {
  if (type) {
	 up_timer = setInterval('scroll_up()', 5); 
	} else {
	 clearInterval(up_timer);
	}
}

function selecteerSubCategorieVan(id, checked) {
  box = document.getElementById('cat' + id);
	
	if (checked) {
	  box.checked = false;
	}
}

function customSelectieOpenen(id) {
  box = document.getElementById(id + '_list');

	
	if (box.style.display == 'block') {
	  //box.style.display = 'none';
    //Effect.Fade(id + '_list', { duration: 0.2 });
	  box.style.display = 'none';
	} else {
	  box.style.display = 'block';
    //Effect.Fade(id + '_list', { duration: 0.2 });
	}


}

function customSelectieSluiten(id) {
  box = document.getElementById(id + '_list');
	
	box.style.display = 'none';
  //Effect.Fade(id + '_list', { duration: 0.2 });
}

function customSelectieKeuze(id, waarde, bedrag) {
  customSelectieWaarde(id, waarde, bedrag);
  customSelectieSluiten(id);
}

function customSelectieWaarde(id, waarde, bedrag) {
  box1 = document.getElementById(id + '_content');
  box2 = document.getElementById(id + '_field');
	
	if (bedrag) {
	  box1.innerHTML = '&euro; ' + waarde;
	} else {
	  box1.innerHTML = waarde;
	}
	
	box2.value = waarde;
}

function customSelectieSluitenTimer(id) {
  sluitTimers[id] = setTimeout("customSelectieSluiten('" + id + "')", 300);
}

function customSelectieVerwijderTimer(id) {
	clearTimeout(sluitTimers[id]);
}


function plaatsFoto(foto) {
  box = document.getElementById('fotoContentbox');
	
	box.innerHTML = '<img src="' + webadres + 'php/verwerk/bestanden.php?code=' + foto + '">';
}


function fadeObject(id, c1, c2, s1, s2) {
  var self = this;
  this.id      = id;
  this.elem    = false;
  this.colour  = {
    stt: [parseInt(c1.substr(0, 2), 16), parseInt(c1.substr(2, 2), 16), parseInt(c1.substr(4, 2), 16)],
    end: [parseInt(c2.substr(0, 2), 16), parseInt(c2.substr(2, 2), 16), parseInt(c2.substr(4, 2), 16)],
    now: [parseInt(c1.substr(0, 2), 16), parseInt(c1.substr(2, 2), 16), parseInt(c1.substr(4, 2), 16)]
  };
  this.steps   = [s1, s2];
  this.dir     = false;
  this.active  = false;
  this.queue   = [];
  this.msg     = [];
  this.message = 0;
  function d2h(num) {
    num = Math.round(num);
    return ((num < 16) ? "0" : "") + num.toString(16);
  }
  this.fade = function(message, direction) {
    this.elem = this.elem || document.getElementById(this.id);
    this.queue.push([message, direction]);
    for (var x = 0; x < this.queue.length; x++) {
      for (var y = x + 1; y < this.queue.length; y++) {
        if (this.queue[x][0] == this.queue[y][0] && this.queue[x][1] != this.queue[y][1]) {
          this.queue.splice(x, 1);
          this.queue.splice(y - 1, 1);
        }
      }
    }
    if (!this.active) setTimeout(function() { self.fadeLoop(); }, 10);
  };
  this.fadeLoop = function() {
    if (!this.active && this.queue.length) {
      if (this.dir && this.message != this.queue[0][0]) this.queue.unshift([this.message, false]);
      var msg = this.queue.shift();
      if (this.msg[msg[0]]) {
        this.active = true;
        this.elem.innerHTML = this.msg[this.message = msg[0]];
        this.dir = msg[1];
      }
    }
    if (this.dir) {
      var c1 = this.colour.stt, c2 = this.colour.end, s = this.steps[0];
    } else var c1 = this.colour.end, c2 = this.colour.stt, s = this.steps[1];
    for (var x = 0, cnow = "", inc = 0; x < 3; x++) {
      this.colour.now[x] += inc = (c2[x] - c1[x]) / s;
      cnow += this.colour.now[x] = (inc < 0) ? Math.max(this.colour.now[x], c2[x]) : Math.min(this.colour.now[x], c2[x]);
    } this.elem.style.color = "#" + d2h(this.colour.now[0]) + d2h(this.colour.now[1]) + d2h(this.colour.now[2]);
    if (cnow == c2.join("")) {
      this.active = false;
      if (!this.queue.length) {
        if (!this.dir) {
          if (this.msg[0]) {
            this.queue.push([0, true]);
            setTimeout(function() { self.fadeLoop(); }, 10);
          } else this.elem.innerHTML = "&nbsp;";
        }
      } else setTimeout(function() { self.fadeLoop(); }, 10);
    } else setTimeout(function() { self.fadeLoop(); }, 10);
  };
  if (window.addEventListener) {
    window.addEventListener('load', function() { self.fade(0, true); }, false); 
  } else if (window.attachEvent)
    window.attachEvent('onload', function() { self.fade(0, true); });
}


function throb(item) {

  // If the hash array does not have an entry for this item, initialise it at 2
  if (!hash[item]) hash[item] = 2;

  // Send a fade command using the hash array to tell us what parameters we should use
  fader[item].fade(Math.floor(hash[item] / 2), !(hash[item] % 2));

  // Call this function again for this same item after a certain amount of time
  setTimeout(function() { throb(item); }, (hash[item] % 2) ? 100 : 5000);

  // If we have exceeded the number of messages in this fader, start over again at 2
  if (++hash[item] > fader[item].msg.length * 2 - 1) hash[item] = 2;
}

function showContent(nr) {
	var aantal = nr * 184 - 184;
	var $paneTarget = $('#show_contents');			
 	$paneTarget.stop().scrollTo( {top:aantal, left:0}, 400 )
}

function contentMin(maxi) {
  huidig_nr = huidig_nr + 1;
	
	if (huidig_nr <= maxi) {
    showContent(huidig_nr);
	} else {
	  huidig_nr = huidig_nr - 1;
	}
}

function contentPlus() {
  huidig_nr = huidig_nr - 1;
	
	if (huidig_nr >= 1) {
    showContent(huidig_nr);
	} else {
	  huidig_nr = 1;
	}
}

function vergrootFoto(pagina, foto) {
  box1 = document.getElementById('container1');
  box2 = document.getElementById('container2');
	box3 = document.getElementById('container3');
	
	box1.style.display = 'block';
	box1.style.height = height();
	box2.style.display = 'block';
	
	//box2.innerHTML = '<iframe src="' + webadres + 'php/verwerk/gallerij.php?pagina=' + pagina + '&foto=' + foto + '" width="612" height="540"></iframe>';
	box3.src = webadres + 'php/verwerk/gallerij.php?pagina=' + pagina + '&foto=' + foto;
}

function vergrootProjectFoto(project, foto) {
  box1 = document.getElementById('container1');
  box2 = document.getElementById('container2');
	box3 = document.getElementById('container3');
	
	box1.style.display = 'block';
	box1.style.height = height();
	box2.style.display = 'block';
	
	//box2.innerHTML = '<iframe src="' + webadres + 'php/verwerk/gallerij.php?pagina=' + pagina + '&foto=' + foto + '" width="612" height="540"></iframe>';
	box3.src = webadres + 'php/verwerk/gallerij.php?project=' + project + '&foto=' + foto;
}

function containerSluiten() {
  box1 = document.getElementById('container1');
  box2 = document.getElementById('container2');
	box3 = document.getElementById('container3');
	
	box1.style.display = 'none';
	box2.style.display = 'none';
}

function height() {
  //  if (document.all) 
  //      return document.body.offsetHeight;
  //  else if (document.layers)
  //      return document.body.document.height;
	return document.body.clientHeight;
}

function height() {
var theHeight;

if (window.innerHeight) {
theHeight=window.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight) {
theHeight=document.documentElement.clientHeight;
}
else if (document.body) {
theHeight=document.body.clientHeight;
}

return theHeight;
}



function displayBlock(id)
{
	if (document.getElementById)
	{ // DOM3 = IE5, NS6
		document.getElementById(id).style.visibility = 'visible';
		document.getElementById(id).style.display = 'block';
	}
}

function hideBlock(id)
{
	if (document.getElementById)
	{ // DOM3 = IE5, NS6
		document.getElementById('id').style.visibility = 'hidden';
	}
}




function block_go_down (IdNaam)
{
	box = document.getElementById('gastenboekHolder');
	box.scrollTop = box.scrollTop + 1;
}

function block_go_up (IdNaam)
{
	box = document.getElementById('gastenboekHolder');
	box.scrollTop = box.scrollTop - 1;
}


function block_scroll_down (type)
{
	if (type)
	{
		down_timer = setInterval('block_go_down()', 5); 
	}
	else
	{
		clearInterval(down_timer);
	}
}

function block_scroll_up (type)
{
	if (type)
	{
		up_timer = setInterval('block_go_up()', 5);

	}
	else
	{
		clearInterval(up_timer);
	}
}
