function init() {
	if ($("#myGoogleMap").length > 0) 
	{
		initMCRadar();
		setLooping(true);
	}
	
	$("#search_go").bind("click", function(e){
		if($("#search").val() != 'enter city or postcode') {
			var searchval = $("#search").val();
      		$("div.citySearch").hide();
			$("div.citySearchLoader").fadeIn();			
			$.post("/search", { search: searchval },
			  function(data){
			    $("#citySearchDiv").html(data);
			  }
			);
		}
		else {
			alert("Please enter full postcode or city name, then press Go.");
		}
	});
	$("#search").focus(function() {
	if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
	
	$("#resetlocation").bind("click", function(e){
		$.cookie('statid', null);
		$.cookie('locid', null);
		$.cookie('override_location_name', null);
		$.cookie('override_latitude', null);
		$.cookie('override_longitude', null);
		$.cookie('override_icon', null);
		$.cookie('override_header_logo', null);
		$.cookie('ppp_statid', null);
		location.reload();
	});
	
	$("img#radar_refresh").bind("click" , function(e){
		loadDtgs();
	});
	
	if ($("#myGoogleMap").length > 0) 
	{
		$(window).unload(function(){
			GUnload();
		});
	}
        
    loadLatestPrecipTiming();

	/* End of startup init */
}
var minZoom = 5;
var maxZoom = 10;
var transparency=40;		
var initZoom= 6;
var initLatLng = new GLatLng(54.425,-3.925);
var	swPoint = null;
var	nePoint = null;
var mapBounds = new GLatLngBounds(new GLatLng(46.34124,-14.5607),new GLatLng(60.261089,6.883241));		
var placeMark = null;

function fixTiles(){
        var tiles = document.getElementsByTagName('IMG');
        for (var n = 0 ; n < tiles.length ; n++ ) {
                if (tiles[n].src.match(/&src=api/)) {
                        tiles[n].src = tiles[n].src.replace(/&src=api/,'');
                }
        }
        window.setTimeout("fixTiles()",500);
}

/** loads a timestamp to check whether the dataset must be updated*/
function loadLatestPrecipTiming() {
	xmlhttpGet("/updateLatestPrecipTypeTiming?nc=" + (new Date()).getTime(),processLatestPrecipTiming);
}

/** 
 * Is called while loading the XML, after ready, it will get the timestamp.
 * If the timestamp changes, the dtgs are reloaded.
 * */
function processLatestPrecipTiming(xmlHttpReq) {
	var timing		= xmlHttpReq.responseText;
	$("p#latest_precip_update_timing").html(timing);
	/* Free memory */
	window.setTimeout("loadLatestPrecipTiming()",60000);
	timing = null;
}