function replace_headers() {
	var headers = document.getElementsByClassName("imageheader");
	
	for(var i=0; i<headers.length; i++) {
		var header = headers[i];
		
		var background = baseurl+'/service/image/';
		if(header.className.match(new RegExp('small$'))) {
			background += 'small/';
		}
		background += header.innerHTML+'.gif';
		if(!header.id) {
			header.style.backgroundImage = "url('"+background+"')";
		}
	}
	
}


Slideshow = Class.create();
Slideshow.prototype = {

	noeffect: false,

	interval: 4, // seconds
	duration: 1, // fade duration

	children: null,
	current: 0,

	timer: null,

	initialize: function(parent, noeffect) {
		if(noeffect) { this.noeffect = noeffect; }
		this.children = $(parent).getElementsByTagName('li');
		if(this.children.length > 1) {
			$(this.children[this.current]).setStyle({opacity: 0, display: 'block'});
			if(this.noeffect) {
				$(this.children[this.current]).setStyle({opacity: 1, display: 'block'});
			} else {
				new Effect.Opacity(this.children[this.current], {duration:this.duration, from:0, to:1});	
			}
			this.start();
		} else if(this.children.length == 1) {
			this.children[0].style.display = 'block';
		}
	},

	start: function() {
		this.timer = new PeriodicalExecuter(this.next.bind(this), this.interval);
	},

	stop: function() {
		this.timer.stop();
	},

	next: function() {
		if(this.noeffect) {
			this.children[this.current].setStyle({display: 'none'});
			if(this.children[this.current+1]) {
				this.current++;
			} else {
				this.current = 0;
			}
			this.children[this.current].setStyle({display: 'block'});
			this.setdot.bind(this);
		} else {
			new Effect.Opacity($(this.children[this.current]), {duration:this.duration, from:1, to:0, afterFinish: function() {
				$(this.children[this.current]).setStyle({display: 'none'});
				if(this.children[this.current+1]) {
					this.current++;
				} else {
					this.current = 0;
				}
				$(this.children[this.current]).setStyle({opacity: 0, display: 'block'});
				new Effect.Opacity(this.children[this.current], {duration:this.duration, from:0, to:1,beforeStart: this.setdot.bind(this)});
			}.bind(this)});
		}
	},

	setdot: function() {
		if($('dot'+(this.current+1))) {
			var i = 1;
			while(element = $('dot'+i)) {
				element.src = element.src.replace('-current','');
				if(element.id == 'dot'+(this.current+1)) {
					element.src = element.src.replace('.gif','-current.gif');
				}
				i++;
			}
		}
	}
}

function checkcontactform() {
	var error = false;
	var msg = "De volgende velden zijn niet correct ingevuld:\n";
	if($('name').value == '') {
		msg += " - Naam\n";
		error = true;
	}
	if($('email').value == '' || ($('email').value.indexOf('@') == -1 || $('email').value.indexOf('.') == -1)) {
		msg += " - E-mail adres\n";
		error = true;
	}
	if($('message').value == '') {
		msg += " - Bericht\n";
		error = true;
	}
	if(error) {
		alert(msg);
		return false;
	} else {
		return true;
	}
}

/** Google maps */
var map;
var geocoder;

function gmap_load() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		geocoder = new GClientGeocoder();
		showAddress('Zandstraat 1, Burgh-Haamstede, Netherlands');
		//map.setCenter(new GLatLng(37.4419, -122.1419), 13);
	}
}

function showAddress(address) {
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        alert(address + " not found");
      } else {
        map.setCenter(point, 13);
		var icon = new GIcon();
		icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
		icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		icon.iconSize = new GSize(12, 20);
		icon.shadowSize = new GSize(22, 20);
		icon.iconAnchor = new GPoint(6, 20);
		var marker = new GMarker(point, icon);
        map.addOverlay(marker);
        //marker.openInfoWindowHtml(address);
      }
    }
  );
}
