		window.addEvent('domready', function(){
		
			/*fl = new Swiff('googleDrive.swf', {
				id: 'freeDriveSWF',
				width: 512,
				height: 512,
				container: $('googleDriveFlash'),
				params: {wmode:'opaque'}
			});*/
			createObject().injectInside($('googleDriveContainer'));
			
			
			$('myform').addEvent('submit',function(e){
				e.stop();
				getArea();
			});
			
			$('area').addEvent('focus',function(){
				this.value = '';
			});
			
			$('area').addEvent('blur',function(){
				if(this.value == ''){
					this.value = 'Enter location';
				}
			});
			
			getArea();
			
			document.body.onkeydown = function(e){
				e = new Event(e);
				if(e.key == 'up' || e.key == 'down'){
					e.preventDefault();
				}
			}
			
		});
		
		function createObject(coords){
			var obj = new Element('div').setProperties({id: 'googleDriveFlash'});
			var str = '<object id="gdobject" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" '
			str += 'width="512" ';
			str += 'height="512" ';
			str += 'title="googleDrive">';
  			str += '<param name="movie" value="googleDrive.swf?coords='+coords+'" />'
  			str += '<param name="quality" value="high" />';
  			str += '<embed id="gdobject" src="googleDrive.swf?coords='+coords+'" ';
  			str += 'quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" ';
  			str += 'width="512" ';
  			str += 'height="512"></embed>';
			str += '</object>';
			obj.setHTML(str);
			return obj;
		}
		
	
	    
		function getArea(){
			var area = $('area').value;
			
			if(area == '' || area == 'Enter location'){
				alert('Please enter a location');
			}else{
			
			var geo = new GClientGeocoder();
				geo.setBaseCountryCode('.co.uk');
				geo.getLatLng(area, function(code){
				
				if(code == null){
					alert('Sorry, this location has not be found');
				}else{
				
					var lat = new GLatLng(code.y, code.x);
    				arr = getXYfromLatLon(lat.lat(), lat.lng(), 1);
    				createObject(arr.toString()).replaces($('googleDriveFlash'));
				
					//var lat = new GLatLng(code.x, code.y);
					//arr = getXYfromLatLon(lat.x, lat.y, 1);
					/*
					fl = new Swiff('googleDrive.swf', {
						id: 'googleDriveSWF',
						width: 512,
						height: 512,
						container: $('googleDriveFlash'),
						events: {
						     onLoad: function() {
						         
								this.loadMap(arr.toString());
								this.focus();
								
						     }
						 }
					});*/
					//createObject(arr.toString()).replaces($('googleDriveFlash'));
					
				}
				});
			}
		}
		
		function getXYfromLatLon(lat, lon, zoomLevel) {
			var lon = 180.0 + lon;
			var x = Math.floor( (lon / 360.0) * 131072 ); /* 2^17 = 131072 */
			x >>= zoomLevel;

			var lat = lat / 180.0 * 3.1415926
			var y = Math.PI - 0.5 * Math.log((1+Math.sin(lat))/(1-Math.sin(lat)))
		 	y = Math.floor( (y / 2 / Math.PI) * 131072 );
		  	y >>= zoomLevel;
		  	return new Array(x,y);
		}
