function init() {
	gm.init();
	initChange();
	initSelect();
};


(function() {

	gm = {
		map: 'google-map',
		center: new google.maps.LatLng(52.285562, 4.476242),
		routedisplay: 'google-route',
		directions: new google.maps.DirectionsService(),
		display: new google.maps.DirectionsRenderer(),
		loader: 'google-loader'
	}
	
	gm.init = function() {
		var location1 = new google.maps.LatLng(52.21108, 4.403501);
		var location2 = new google.maps.LatLng(52.366951, 4.52125);
		
		var options = {
			zoom: 11,
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			center: gm.center,
			scrollwheel: false
		}
		
		gm.map = new google.maps.Map(document.getElementById(gm.map), options);
		gm.display.setMap(gm.map);
		gm.display.setPanel(document.getElementById(gm.routedisplay));
		
		new google.maps.Marker({ map: gm.map, position: location1 }); 
		new google.maps.Marker({ map: gm.map, position: location2 }); 
	}
	
	gm.route = function() {
		var from = document.getElementById('from').value;
		var to = document.getElementById('to').value;
		
		var request = {
			origin: from,
			destination: to,
			travelMode: google.maps.DirectionsTravelMode.DRIVING
		};
		
		gm.directions.route(request, function(response, status) {
			if (status == google.maps.DirectionsStatus.OK) {
				gm.display.setDirections(response);
			}
			
			document.getElementById(gm.loader).style.display = 'none';
		});
	}

})();


(function() {

	initChange = function() {
	
		var v = document.getElementById('google-panel').getElementsByTagName('input');
		var a = [];
		
		for(var i=0; i<v.length; i++) {
			if(v[i].type == "text") a.push(v[i]);
		}
		
		for(var i=0; i<a.length; i++) {
			a[i].onfocus = function() {
				if(this.value == this.defaultValue) this.value = "";
			}
			
			a[i].onblur = function() {
				if(this.value == "") this.value = this.defaultValue;
			}
			
			a[i].onkeypress = function() {
				document.getElementById(gm.loader).style.display = 'block';
				
				if(typeof timer != "undefined") clearTimeout(timer);
				timer = setTimeout(function() {
				
					var s = "";
					for(var n=0; n<a.length; n++) {
						if(a[n].value == a[n].defaultValue || a[n].value == "") continue;
						
						if(s) s += ",";
						s += a[n].value;
					}
					
					document.getElementById('from').value = s;
					
					gm.route();
				}, 1000);
			}
		}
	
	}
	
	initSelect = function() {
	
		var a = document.getElementsByName('option');
		
		for(var i=0; i<a.length; i++) {
			a[i].onclick = function() {
				document.getElementById(gm.loader).style.display = 'block';
				
				document.getElementById('to').value = this.value;
				
				gm.route();
			}
		}
	
	}
	
	removeSelect = function(a) {
	
		for(var i=0; i<a.length; i++) {
			var c = a[i].className.split(' ');
			
			for(var n=0; n<c.length; n++) {
				if (c[n] == 'active') {
					c.splice(n, 1);
					n--;
				}
			}
			
			a[i].className = c.join(' ');
		}
	
	}

})();
