var lP = new Array(); var pHash = new Array(); var map; var overlap = removed = 0; var mks = new Array(); var mn = 0; var haveProperties = new Array(); var propertyId = ""; var properties = new Array(); var offices = new Array(); var trains = new Array(); var schools = new Array(); var locations = new Array(); var searchType = url_parameters("type"); if (!searchType) searchType="b"; var properties_keep = new Array(); var icons = new Array(); var pt; var on_map; var on_map_nos= new Array(); var dis= new Array(); var lyrs = new Array(); var mouseX=0; var mouseY=0; var firstpass=true; dis["rollover"] = dis["legend"]=dis["help"]=dis["info"]=dis["advanced"]=dis["locationchoices"]="hidden"; on_map_nos["schools"]=on_map_nos["trains"]=on_map_nos["offices"]=on_map_nos["houses"]=on_map_nos["flats"]=0; var schools = new Array(); var offices = new Array(); var show_houses = show_flats = true; var map_size = 0; var cl = 0; var ol = 0; var lhs_text = ""; var od = ""; var sfv=true; var filters = new Array("searchtext","added","garden","parking","doorman","schools","offices","new_homes","trains"); var alterForms = new Array ("searchtext","added","garden","parking","schools","offices","trains"); alterForms.push("houses"); alterForms.push("flats"); alterForms.push("minprice"); alterForms.push("maxprice"); alterForms.push("minbaths"); alterForms.push("units"); alterForms.push("minbeds"); var basic = new Array ("houses","flats","schools","offices","trains"); var fV = new Array(); var rA = false; var tabalign=0; var inbox=new Array(); bm=new Array(); var bString=""; var pid=""; var roh = new Array(); var greyv=false;
document.write ("<div id=recordstat style='height:1px; width:1px; top:0px; left:0px; position:absolute'></div>");

var rB = restrictedBoundaries;

var roto = null

if (typeof (labels["enterplace"])=="undefined") labels["enterplace"] = "[enter place]";

if (typeof(below_options)=="undefined") var below_options="";
if (typeof(hasSearchFrame)=="undefined") var hasSearchFrame=false;
if (typeof(officesTrueFalse)=="undefined") var officesTrueFalse="false";
if (typeof(flash_sliders)=="undefined") var flash_sliders=false;
if (typeof(satellite)=="undefined") var satellite=false;
if (typeof(traffic)=="undefined") var traffic=false;
if (typeof(streetmap)=="undefined") var streetmap=false;
if (typeof(singular_label)=="undefined") var singular_label="property";
if (typeof(storecurrentlocation)=="undefined") var storecurrentlocation=false;
if (typeof(alternate_view_list)=="undefined") var alternate_view_list=false;
if (typeof(properties_url_external)=="undefined") var properties_url_external="false";
if (typeof(iconsasonecookie)=="undefined") var iconsasonecookie=false;

if (typeof(plural_label)=="undefined") var plural_label="properties";
if (typeof(hideGrey)=="undefined") var hideGrey=false;

if (typeof(show_logo)=="undefined") var show_logo=true;
if (typeof(property_iframe)=="undefined") var property_iframe="mainpropertyiframe";
if (typeof(property_external_frameset)=="undefined") var property_external_frameset=false;
if (typeof(show_lhs)=="undefined") var show_lhs=true;
if (typeof(lhs_extra_text)=="undefined") var lhs_extra_text="";
if (typeof(jump_level)=="undefined") var jump_level=0;
if (typeof(show_prices)=="undefined") var show_prices=true;
if (typeof(show_minbeds)=="undefined") var show_minbeds=true;
if (typeof(page_width)=="undefined") var page_width=10000;
if (typeof(hybrid)=="undefined") var hybrid=false;
if (typeof(smallzoom)=="undefined") var smallzoom=false;
if (typeof(show_zoom)=="undefined") var show_zoom=true;
if (typeof(large_hybrid)=="undefined") var large_hybrid=false;
if (typeof(zm)=="undefined") var zm=false;
if (typeof(show_agencies)=="undefined") var show_agencies=false;
if (typeof(show_map_ov)=="undefined") var show_map_ov=false;
if (typeof(other_icons)=="undefined") var other_icons=0;
if (typeof(show_bathrooms)=="undefined") var show_bathrooms=false;
if (typeof(on_map_cutoff)=="undefined") var on_map_cutoff=8000;
if (typeof(grey_icon)=="undefined") var grey_icon="";
if (typeof(officeDefault)=="undefined") var officeDefault=true;
if (typeof(single_rollover)=="undefined") var single_rollover=false;
if (typeof(currency)=="undefined") var currency="£";
if (typeof(rolloverTime)=="undefined") var rolloverTime=rolloverTime;
if (typeof(separatorStart)=="undefined") var separatorStart="";
if (typeof(separatorEnd)=="undefined") var separatorEnd="";
if (typeof(max_price_default)=="undefined") var max_price_default=price_to[searchType][price_to[searchType].length-1];

var b=navigator.userAgent.toLowerCase();
var ie = ((b.indexOf("msie") != -1));

if (typeof(show_furnished)=="undefined") var show_furnished=false;
if (typeof(show_doorman)=="undefined") var show_doorman=false;
if (typeof(redirect)=="undefined") var redirect=false;
if (typeof(min_level)=="undefined") var min_level=1;
if (typeof(show_units)=="undefined") var show_units=false;
if (typeof(show_goto)=="undefined") var show_goto=true;
if (typeof(property_var)=="undefined") var property_var="property";
if (typeof(office_var)=="undefined") var office_var="office";
if (typeof(labels["options_top"])=="undefined") labels["options_top"]="";
if (typeof(checkbox_divider)=="undefined") var checkbox_divider="";

var onetofive = new Array();
for (i=0; i<=5; i++) eval ("onetofive["+i+"]=" + i);

function alpha(id, src) { if (!document.getElementById(id)) return; if ( ie ) { if (id!="cred") { document.getElementById(id).height=icon_height; document.getElementById(id).width=icon_width; } document.getElementById(id).style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='scale')"; } else { document.getElementById( id ).src = src; document.getElementById( id ).onload = ""; } }

function formRequest (url,func) {

if (url_parameters("test")=="true") window.open(url,'db');

//if (document.location.href.match("domvs.")) window.open(url);

//if (document.location.href.match("lanes.")) alert(url);
//if (document.location.href.match("uktv")) top.frames.debugframe.location=url;
//if (document.location.href.match("uktvfood")) alert(url);

var r= GXmlHttp.create(); r.open("GET", url, true); eval ("r.onreadystatechange = function () { "+func+"(r); }"); r.send(null); }

function checklocation() { var sf = document.getElementById("searchfor").value; if (sf) formRequest(location_url+"?location=" + escape(sf) + "&type=" + searchType, "llr"); }

function createBString() { for (var b=0; b<rB.length; b++) { var blevel = rB[b][0]; bString += "&bminX" + b +"=" + rB[b][1] + "&bmaxX" + b +"=" + rB[b][3] + "&bminY" + b +"=" + rB[b][4] + "&bmaxY" + b +"=" + rB[b][2] + "&blevel" + b +"=" + rB[b][0]; } bString+= "&nBound=" + rB.length; }

function im() { if (!GBrowserIsCompatible()) { alert ("You aren't using a compatible browser!"); return; } createBString(); var lng = url_parameters("lng"); var lat = url_parameters("lat"); propertyId = url_parameters("panelist") ? url_parameters("panelist") : url_parameters("id"); cl = 17 - url_parameters("zoom"); if (!lat) lat = 51.4699; if (!lng) lng = -0.2099; if (!cl) cl = 15; var affected = load_cookies(); im_itself(lat, lng, map_width, map_height); if (affected>0) { setTimeout('showHide("advanced")',1000); } showSearchFrame(); if (propertyId) showPropertyFrame(propertyId, url_parameters('current'));} // changemaxminprice("minprice"); }

function im_itself(lat, lng, width, height) { map = new GMap2(document.getElementById("map"));
if (traffic==true)    
{
	map.addControl(new ExtMapTypeControl({showTraffic: true, showTrafficKey: false}));
}
else
{
if (large_hybrid) map.addControl(new GMapTypeControl());
if (smallzoom) map.addControl(new GSmallMapControl());
}
//if (satellite) map.addControl(new GMapTypeControl());

map.setCenter(new GLatLng(lat,lng), cl); if (show_map_ov) { map.addControl(new GOverviewMapControl(new GSize(150, 150))); var omap=document.getElementById("map_overview"); var mapdiv =document.getElementById("map"); omap.style.position = "relative"; omap.style.right = "0px"; omap.style.bottom = "8px"; mapdiv.appendChild(omap);} var top = top2 = 0; if (ie) { width-=90; top = top2 = -1 * (height + 39); } else { width+=90; top = -1 * (height + 59); top2 = -1 * (height + 29); } top = -1 * (height+39); cmb(); if (show_zoom) csb(); suis(); add_listeners(); pB(); lp(); }

function csb () { var scaleGraphics=''; var graphic = ""; var temp_height = scale_icon_height; var vspace=0; var md = 17-max_level; for (i=17-min_level; i>=md; i--) { graphic = cl==i ? scale_on_icon : scale_off_icon; scaleGraphics += "<A href='javascript:void(dZ(\"" + (i-1) + "\"))'><IMG src='" + images_directory + graphic +"' alt='change map scale' width='" + scale_icon_width +"' border='0' height='"+ temp_height +"' vspace='"+vspace+"'></A>"; temp_height-=2; vspace+=1; } var previous = cl; if (od!=md || cl!=ol) slb ("scale","<A href='javascript:void(dZ(\""+previous+"\"))'><IMG alt='zoom into map' src='"+ images_directory + scale_plus_icon +"' border='0' ></A> " + scaleGraphics + "<A href='javascript:void(dZ(\"" + (cl-2) + "\"))'><IMG src='"+ images_directory + scale_minus_icon +"' border='0' alt='zoom out of map'></A>"); od = md; ol = cl; }

function cmb() { var a="true"; var b="inc"; if (map_size!=0) { a="";b="dec"; } slb ("mapsize","<a href='javascript:void(resizeMap(\""+a+"\"))' class="+aroundmaplinksclass+">"+labels[b+"rease_map"]+"</a>"); }

function resizeMap (large) { var c= map.getCenter(); var lng = c.x; var lat = c.y; if (typeof(current_url)=="string") c = current_url; else c = "street_level_map.php"; document.location = c  + guv(0,0,0,0) + "&lng=" + lng + "&lat=" + lat + "&large=" + large + "&zoom=" + (17-cl) + "&id=" + pid; }

function sui(name,prefix) { icons[name] = new GIcon(); if (prefix) eval ("icons['" + name + "'].image = '" + icon_directory + "'+icon_" +  name+";"); else eval ("icons['" + name + "'].image = '" + icon_directory + "'+" +  name + "_icon;"); icons[name].iconSize = new GSize(icon_width, icon_height); icons[name].iconAnchor = new GPoint(icon_width/2, icon_height/2); icons[name].infoWindowAnchor = new GPoint(icon_width, 1);  }

function suis() { sui ("house"); sui ("houses"); sui ("flat"); sui ("flats"); sui ("mixed"); sui ("school"); sui ("train"); sui ("office"); for (var i=1; i<=other_icons; i++) { var t = eval("icon_"+i); if (typeof(t)!="undefined") sui (i,true); } }

function debugWindow(text) { if (document.location.href.match("_f2.php")) document.getElementById("debugging").innerHTML = "<font size=-2 color=red>DEBUG:" + text + "</font>"; }

function overlaps (lat, lng, id) { if (pHash[id]) return false; var times = cl>=11 ?  0.9701 : 0.77162458338772; var cLng = (icon_width-0) / (Math.pow(2, (cl)) * times); var cLat = (icon_height-0) / (Math.pow(2, (cl))); for (var p=0; p<lP.length; p++) { var dLng = Math.abs (lng - lP[p]["lng"]); var dLat = Math.abs (lat - lP[p]["lat"]); if ( dLng < cLng && dLat < cLat && lP[p]["id"]!=id ) { overlap++; return true; } } return false; }

function rp()
{
	var bounds = map.getBounds();
	var keepProperties = new Array();
	haveProperties = new Array();

	var added = kept = 0;
	overlap = removed = 0;
	for (var p=0; p<properties.length; p++)
	{
		if (oob (properties[p]["lng"], properties[p]["lat"], bounds) || overlaps (properties[p]["lat"], properties[p]["lng"], properties[p]["id"]) || !pHash[properties[p]["id"]] || rA)
		{
		rmal (properties[p]);
		removed++;
		}
		else
		{
			kept++;
			keepProperties[keepProperties.length]=properties[p];
			haveProperties[properties[p]["id"]]=true;
		}
	}

	for (var p=0; p<lP.length; p++)
	{
		if (!haveProperties[lP[p]["id"]])
		{
			keepProperties[keepProperties.length] = lP[p];
			added++;
		}
	}
	properties = keepProperties;

	debugWindow ("added=" + added + ", kept=" + kept + ", removed=" + removed + ", overlap=" + overlap);
}

function changemaxminprice (name)
{

if (document.getElementById("mapform").maxprice.selectedIndex==-1 || document.getElementById("mapform").maxprice.value==0 && 0)
{
document.getElementById("mapform").maxprice.selectedIndex= document.getElementById("mapform").maxprice.options.length-1;
fV["maxprice"] = document.getElementById('mapform').maxprice.value;
return;
}

while (document.getElementById("mapform").minprice.value*1>=document.getElementById("mapform").maxprice.value*1 && name=="minprice")
{
	document.getElementById("mapform").maxprice.selectedIndex++;
	fV["maxprice"] = document.getElementById('mapform').maxprice.value;
}
while (document.getElementById("mapform").minprice.value*1>=document.getElementById("mapform").maxprice.value*1 && name=="maxprice")
{
	document.getElementById("mapform").minprice.selectedIndex--;
	fV["minprice"] = document.getElementById('mapform').minprice.value;
}
}

function uf(obj) { name = obj.name; if (obj.value=="true") fV[name]= ""+obj.checked+""; else fV[name]=obj.value; changemaxminprice(name); lp(); return false; }

function sc()
{
	var string='saving: ';
	var longcookie="";
	var comma="";

	for (i=0; i<alterForms.length; i++)
	{
		setcookie(alterForms[i],fV[alterForms[i]],365);
		string +="\n" + alterForms[i] +"=" + fV[alterForms[i]];
	}


	for (var i=1; i<=other_icons; i++)
	{
	if (!fV["icon"+i]) fV["icon"+i]="false";
	if (iconsasonecookie)
	{
	longcookie+=comma+fV["icon"+i];
	comma=":";
	}
	else
	setcookie("icon"+i,fV["icon"+i],365);
	}

	if (iconsasonecookie)
	{
	setcookie("icons",longcookie,365);
	//alert (longcookie);
	}
}

function load_cookies()
{
	if (!getcookie("minbeds"))
	return;
	var affected=0;

	if (getcookie("mapWidth")) mapWidth = getcookie("mapWidth");
	if (getcookie("mapHeight")) mapHeight = getcookie("mapHeight");

	var string='loading: ';
	for (i=0; i<alterForms.length; i++)
	{
		if (alterForms[i]=="houses" || alterForms[i]=="flats" || (alterForms[i]=="offices" && officeDefault==false));
		else
		{
			fV[alterForms[i]]= getcookie(alterForms[i]).replace (";","");
			if ((alterForms[i]=="added" || alterForms[i]=="parking" || alterForms[i]=="garden" || alterForms[i]=="new_homes" || alterForms[i]=="searchtext") && fV[alterForms[i]]) affected++;

			if (fV[alterForms[i]]=="on")
			fV[alterForms[i]]="";
		}
		string +="\n" + alterForms[i] +"=" + fV[alterForms[i]];
	}

	if (iconsasonecookie)
	{
		var ticons = getcookie("icons");
		var ticonsarray = new Array();
		if (ticons)
		ticonsarray = ticons.split(":");
		//alert ("icons="+ticons + "," + ticonsarray.length);

		for (tn=0; tn<ticonsarray.length; tn++)
		{
		fV["icon"+(tn+1)]=ticonsarray[tn]=="true" ? "true" : "";
//		alert ((tn+1)+"="+ fV["icon"+(tn+1)]);
		}
	}
	else
	{
	for (var i=1; i<=other_icons; i++)
	fV["icon"+i]=getcookie("icon"+i)=="true" ? "true" : "";
	}

	if (url_parameters("Minprice")) fV["minprice"] = url_parameters("Minprice");
	if (url_parameters("Maxprice") && url_parameters("Maxprice")!="0") fV["maxprice"] = url_parameters("Maxprice");

	if (url_parameters("Minbedrooms")) fV["minbeds"] = url_parameters("Minbedrooms");
	if (url_parameters("Minbathrooms")) fV["minbaths"] = url_parameters("Minbathrooms");

	return affected;
}

function cm() { var ce= map.getCenter(); var lng = ce.x; var lat = ce.y; var newcl = 17-cl; for (var b=0; b<rB.length; b++) { if (lng > rB[b][1] && lng < rB[b][3] && lat > rB[b][4] && lat < rB[b][2]) { if (rB[b][6]>0 && newcl<rB[b][6]) { greyOut("You cannot view the map at this scale for this particular area.<br>&nbsp;<br>Please click <a href='javascript:void(dZ(" + (17-rB[b][6]-1)+ "))'>here</a> to go up to the next available scale."); return true; } } } return false; }

function lp2()
{
	recordStat("pan");
	lp();
}

function lp() { if (greyv) greyOff(); if (cm()) return; if (pt) clearTimeout(pt); sc(); slb ("status","<img vspace='0' hspace='0' height='10' src='" + icon_directory + load_bar + "'>"); gptr (); }

function guv(minX, minY, maxX, maxY)
{
	if (minX=="undefined") return;
	var ce= map.getCenter();
        var nx = ce.x;
        var ny = ce.y;
	var ext = "";

	for (var i=1; i<=other_icons; i++)
	{
	if (show_lhs==false) fV["icon"+i]="true";
	ext+="&icon"+i+"=" + fV["icon"+i];
	}

	var times = cl>=11 ?  0.9701 : 0.77162458338772;
	var cLng = (icon_width-0) / (Math.pow(2, (cl)) * times);
        var cLat = (icon_height-0) / (Math.pow(2, (cl)));
	minX+= cLng; maxX-= cLng;
	minY+= cLat; maxY-= cLat;

	if (fV["maxprice"]<=0)
	{
	//alert ('Please choose a maximum price'); // like '+ max_price_default);
	//document.getElementById("mapform").maxprice.value = max_price_default;
	fV["maxprice"] = max_price_default;
	//alert ( max_price_default);
	}

	if (!fV["maxprice"]) fV["maxprice"]="1000000000";
	if (fV["minprice"]<=0|| !fV["minprice"]) fV["minprice"]=0;
	if (fV["minbeds"]<=0 || !fV["minbeds"]) fV["minbeds"]=0;

	if (fV["minbeds"]=="undefined" || typeof fV["minbeds"]=="undefined") fV["minbeds"]=0;
	if (fV["minprice"]=="undefined") fV["minprice"]=0;
	if (fV["maxprice"]=="undefined") fV["maxprice"]=999999999;

	var returnable = "?x1=" + minX + "&y1=" + minY + "&x2=" + maxX + "&y2=" + maxY + "&minbeds=" + fV["minbeds"] + "&maxbeds=99&minprice=" + fV["minprice"] + "&maxprice=" + fV["maxprice"] +
"&houses=" + fV["houses"] +
"&flats=" + fV["flats"] +
"&schools=" + fV["schools"] +
"&trains=" + fV["trains"] +
"&offices=" + fV["offices"] +
"&minbaths=" + fV["minbaths"] +
"&added=" + fV["added"] +
"&units=" + fV["units"] +
"&parking=" + fV["parking"] +
"&dman=" + fV["doorman"] +
"&agency=" + fV["agency"] +
"&oh=" + fV["oh"] +
"&ohdate=" + fV["ohdate"] +
"&letting_type=" + fV["letting_type"] +
"&furnished=" + fV["furnished"] +
"&new_homes=" + fV["new_homes"] +
"&garden=" + fV["garden"] +
"&icons=" + other_icons +
"&searchtext=" + escape(fV["searchtext"]) +
"&type=" + searchType + "&icon_width="+icon_width+"&icon_height="+icon_height+"&z=" + (17-cl) + "&cx=" +nx + "&cy=" + ny +ext;

//if (url_parameters('test')=="true") alert (returnable);

//	returnable = returnable.replace ("undefined","");

	return returnable;
}

function gptr () { var b=map.getBounds(); var sw = b.getSouthWest(); var ne = b.getNorthEast(); formRequest(properties_url+guv(sw.lng(), sw.lat(), ne.lng(), ne.lat()) + bString + "&maxprops=" + on_map_cutoff + "&swap=true" + "&map_height="+map_height+"&map_width="+map_width, "lp_request"); if (redirect) window.open(url,'xml');
}

function rmal (props) { map.removeOverlay (props["marker"]); if (props["listener"]) GEvent.removeListener(props["listener"]); if (props["listener2"]) GEvent.removeListener(props["listener2"]);}

function inBoundary(lng, lat, id) { for (var b=0; b<rB.length; b++) { if (lng > rB[b][1] && lng < rB[b][3] && lat > rB[b][4] && lat < rB[b][2] && rB[b][0]<17-cl) { inbox[b] = typeof(inbox[b])=="undefined" ? id : inbox[b]+"," + id; return true;	} } return false; }

function pxml_request(r)
{
	if (r.readyState == 4)
        {
                var rD = r.responseXML;
                if (rD.documentElement)
                {
                        var pf = rD.documentElement.getElementsByTagName("p");
			var e= roh.length;
			var te = new Array;
 			te["id"] = pf[0].getAttribute("id");
			var img = pf[0].getAttribute("img");
			for (var r=1; r<=5; r++)
			img = img.replace("AMP","&");
			var joiner = !pf[0].getAttribute("oh") ? "<br>" : "; ";

			theimage = "<img vspace=3 hspace=3 height=60 width=80 align=left src='"+img+"'> ";

			if(typeof(labels["propup"])=="undefined") labels["propup"] = '';

 			te["value"] = "<span id='ddd' onmouseover=\"sh('rollover', '','hidden')\">"+labels["propup"] + theimage + pf[0].getAttribute("name") + "<br>Price: " + currency + pf[0].getAttribute("price") + joiner + "Bedrooms: "+ pf[0].getAttribute("beds");

			if (pf[0].getAttribute("oh"))
			te["value"] += "<font size=-2 style='color:black'><br>" + pf[0].getAttribute("oh") + "</font>";

			te["value"] += "</span>";
 			//te["value"] = pf[0].getAttribute("name") + "<br>" + pf[0].getAttribute("price");
         		roh[e] = te;

			if (document.location.href.match("britainsfinest.") || document.location.href.match("uktv.") || document.location.href.match("henry-adams."))
			roh[e]["value"] = pf[0].getAttribute("name");

			if (document.location.href.match("parklane"))
                        {
                        roh[e]["value"] = theimage + pf[0].getAttribute("name") + "<br>£" + pf[0].getAttribute("price") + " " + pf[0].getAttribute("price_prefix") + "<br>"+pf[0].getAttribute("beds") + " bedrooms";
                        }


			shtime('rollover',roh[e]["value"],rolloverTime);
                        delete request;
                }
        }
}

function getRoh(id)
{
	for (var i=0; i<roh.length; i++)
	{
		if (roh[i]["id"]==id)
		return roh[i]["value"];
	}

	return "";
}

function propup(id) { var tv = getRoh(id);if (tv=="") formRequest (property_xml + "?type="+searchType+"&id="+id, "pxml_request"); else shtime('rollover',tv,rolloverTime); }

function pms (which, use_frame, use_icon, prefix, arrayName)
{
	if (use_icon=="property") inbox=new Array();

	var point = null;
	var theid = null;
	prefix="";
	//mks = new Array();
	for (var i=0; i<which.length; i++)
	{
		if (inBoundary(which[i]["lng"], which[i]["lat"], which[i]["id"]) && use_icon=="property") {}
		else if (haveProperties[which[i]["id"]] && use_icon=="property") {}
		else
		{
		point = new GLatLng(parseFloat(which[i]["lat"]), parseFloat(which[i]["lng"]));
		if (use_icon=="property")
		var marker = new GMarker (point,icons[which[i]["type"]]);
		else
		var marker = new GMarker (point,icons[use_icon]);

                eval (arrayName + "[i][\"marker\"] = marker");
		map.addOverlay(marker);

                theid = which[i]["id"];
//		alert (use_icon);

		if (use_frame=="Property" && haveProperties[which[i]["id"]]) {}
		else
		{
                //mks.push(marker);
		if (use_icon=="train")
                eval(arrayName + "[i][\"listener\"]=GEvent.addListener(" + arrayName + "[i][\"marker\"], 'mouseover', function() { show"+use_frame+"Frame('" + theid + "')}); ");
		else
		{
                eval(arrayName + "[i][\"listener\"]=GEvent.addListener(" + arrayName + "[i][\"marker\"], 'click', function() { show"+use_frame+"Frame('" + theid + "')}); ");
		}

		if (use_icon=="property")
		{
		if (numberOfCommas(which[i]["id"])>1)
                eval(arrayName + "[i][\"listener2\"]=GEvent.addListener(" + arrayName + "[i][\"marker\"], 'mouseover', function() { sh2('rollover','" + numberOfCommas(which[i]["id"]) + " " + plural_label+ "')}); ");
		else if (single_rollover)
                eval(arrayName + "[i][\"listener2\"]=GEvent.addListener(" + arrayName + "[i][\"marker\"], 'mouseover', function() { sh2('rollover',propup(\""+which[i]["id"]+"\"))}); ");
		else
                eval(arrayName + "[i][\"listener2\"]=GEvent.addListener(" + arrayName + "[i][\"marker\"], 'mouseover', function() { sh2('rollover','1 " + singular_label + "')}); ");
		}

		if (use_icon=="office" || use_icon=="school")
		{
                eval(arrayName + "[i][\"listener2\"]=GEvent.addListener(" + arrayName + "[i][\"marker\"], 'mouseover', function() { sh2('rollover',\"" + which[i]["kd"]+"\")}); ");
		}
		}
		}
	}
	if (use_icon=="property" && 1)
	{
		for (var b=0; b<rB.length; b++)
		boundaryText (b, rB[b][5], inbox[b], rB[b][1], rB[b][2], rB[b][3], rB[b][4]);
	}
	//map.addOverlays(mks);
}

function greyOut(msg)
{
	cap();
	if (hideGrey)
	return;
	if (greyv) greyOff();
	document.getElementById('grey').innerHTML= "<div style='position:absolute;top:-4px;left:0;filter:alpha(opacity=55);-moz-opacity:.55;opacity:.55;background-color:#dddddd;height:"+ map_height + "px;width:" + map_width + "px' id='g'></div><div style='position:absolute; top: 200px; left:30px; width:300px'>"+labels["warningbox"]+"<div class='"+lhsclass+"' id=warningbox name=warningbox><font color=#333333><b>"+msg+"</b></font></div></div>";
	greyv=true;
}
function greyOff()
{
	if (!greyv) return;
	document.getElementById('grey').innerHTML="";
	greyv=false;
}

function cap()
{
	map.clearOverlays();
        for (var p=0; p<properties.length; p++)
        rmal (properties[p]);
        properties=new Array();
}

function pp()
{
	if (on_map<on_map_cutoff)
	{
	rp();
	if (cl>=17-3 && schools.length>0 && show_schools) pms(schools, "School", "school", "s", "schools");
	pms(offices, "Office", "office", "o", "offices");
	if (cl>=17-4 && trains.length>0) pms(trains, "Train", "train", "t", "trains");
	pms(properties, "Property", "property", "", "properties");
	greyOff ();
	}
	else
	greyOut ("Too many properties on the map.<br>&nbsp;<br>Please <a href='javascript:void(dZ(cl))' class='BasicLink'>zoom in</a> or change the criteria to narrow your search.");

        var word = plural_label; //"properties";
        if (on_map==1)
        word = singular_label; //"property";


	set_numbers();

	var b=map.getBounds();
        var sw = b.getSouthWest();
        var ne = b.getNorthEast();
 	var thelabel = "(" + labels["listview"] + ")";
	if (!labels["listview"])
	thelabel="";
        if (on_map=="0")
        thelabel = "";

	var url = "";
	var targ = "";

	if (propertyStringType==1)
	{
		url = search_url+ guv(sw.lng(), sw.lat(), ne.lng(), ne.lat())+"&a=list_view";
	}
	else if (propertyStringType==2)
	{
		var center = map.getCenter();
        	var newx = center.x;
        	var newy = center.y;
		url = search_url+ propertyIds() + "&cx=" + newx + "&cy=" + newy + "&z=" + (17-cl) + "&type=" + searchType;
		targ = "target='_top'";
	}

	if (typeof(lvt)!="undefined") targ = lvt;

	if (alternate_view_list)
	{
	if (on_map==0)
	slb ("status",on_map + " " + word + " in selected area");
	else if (on_map>on_map_cutoff)
	slb ("status","<center>" + on_map + " " + word + " in selected area<br>zoom in to display icons</center>");
	else
	slb ("status","<center>"+on_map + " " + word + " now showing<br>click on icons to show details below</center>");
	}
	else if (!greyv)
	slb ("status","<b>" + on_map +  " " + word+" <a " + targ +" href='"+url+"' class='"+aroundmaplinksclass+"' onmouseover='sle (\"info\",labels[\"list_view\"],20)' onmouseout='hideInfo()'>" + thelabel + "</a></b>");
	else
	slb ("status","<b>" + on_map +  " " + word+"</b>");

}

function hideInfo()
{
	sle ("info","","","hidden");

	document.getElementById("info").style.display="none";
	document.getElementById("info").style.left=0;
}

function set_numbers()
{
	if (sfv)
	{
		for (i=0; i<basic.length; i++)
		if (eval("show_" + basic[i]))
		{
			if(!on_map_nos[basic[i]])
			on_map_nos[basic[i]]=0;
			if (basic[i]=="schools" && cl< 14)
			slb ("div_" + basic[i], "(0) &nbsp; <span onmouseover='sle (\"info\",labels[\"schools\"],20)' onmouseout='hideInfo()' style='cursor:hand'><font color=red face='verdana'> ! </font></span>");
			else if (document.getElementById("div_"+ basic[i]))
			slb ("div_" + basic[i], "("+on_map_nos[basic[i]]+")");
		}
	}
}

function nte()
{
	set_numbers();
	if (dis["advanced"]=="hidden" || dis["advanced"]=="false" ) return;

	var mapform = document.getElementById("mapform");
	for (i=0; i<alterForms.length; i++)
	{
		if (fV[alterForms[i]]=="true" || fV[alterForms[i]]=="false")
		eval ("mapform." + alterForms[i]+ ".checked=" + fV[alterForms[i]]);
		else if (eval ("document.getElementById('element" + alterForms[i]+ "')")!=null)
		eval ("document.getElementById('element" + alterForms[i]+ "').value=\"" + fV[alterForms[i]]+ "\"");
	}
}

function showSearchFrame()
{
	pid="";
	sfv=true;
	if (show_lhs==true)
	slb ("leftpanel",lhs_text);
	var mapform = document.getElementById("mapform");
	if (!fV["minprice"]) fV["minprice"]="0";

	if (!fV["maxprice"]) fV["maxprice"]=max_price_default;
	if(mapform != null) mapform.minbeds.value = fV["minbeds"];
	if(mapform != null) mapform.minprice.value = fV["minprice"];
	if(mapform != null) mapform.maxprice.value = fV["maxprice"];
	if (show_schools && fV["schools"]=="true" && mapform != null) mapform.schools.checked=true;
	if (show_trains && fV["trains"]=="true" && mapform != null) mapform.trains.checked=true;
	if (show_bathrooms && fV["minbaths"] && mapform != null) mapform.minbaths.value=fV["minbaths"];
	if(mapform != null) mapform.flats.checked= fV["flats"] == "true" ? true : false;
	if(mapform != null) mapform.houses.checked= fV["houses"]=="true" ? true : false;

	if (show_offices && fV["offices"]=="true")
	if(mapform != null) mapform.offices.checked= fV["offices"]=="true" ? true : false;

	if (!firstpass)
	nte();
	firstpass=false;

	if (!other_icons)
	{
	alpha("iconhouse",icon_directory + house_icon);
	alpha("iconflat",icon_directory + flat_icon);
	}
	else if (1)
	{
		for (var i=1; i<=other_icons; i++)
		alpha("iconid"+i,icon_directory + eval ("icon_"+i));
	}
	if (show_schools)
	alpha("iconschool",icon_directory + school_icon);
	if (show_offices)
	alpha("iconoffice",icon_directory + office_icon);
	if (show_trains)
	alpha("icontrain",icon_directory + train_icon);
}

function sh2(name, id) { sh(name, id,'visible');} // roto = setTimeout("sh('rollover','','hidden')",1000); }
function shtime(name, id, t) { sh(name, id,'visible',t);} // roto = setTimeout("sh('rollover','','hidden')",t); }

function sh(name, id,state,t)
{
//	if (state) dis[name]=state;
	if (!t) t=800;


	if (id=="") state='hidden';
	var extra = document.body.scrollTop;
	if (!ie) extra=0;


	var width = id ? id.length * 8 :0;
	var height = 15;

	if (state=="hidden")
	{
	document.getElementById(name).style.left=0+"px";
        document.getElementById(name).style.visibility = "hidden";
	}

	if (!id) return;
	if (id.length>30 && !id.match ("School"))
	{
		width=300;
		height=70;
	}


	if (id.match("Bedroom") && name=="rollover")
	{
		if (mouseY<map_down_from_top+100) mouseY+=140;
		document.getElementById(name).style.top=(mouseY-100) + "px";

		if (mouseX-200<lhs_panel_width)
        	document.getElementById(name).style.left=(lhs_panel_width) + "px";
		else
        	document.getElementById(name).style.left=(mouseX-200) + "px";

		if (page_width< mouseX-200)
        	document.getElementById(name).style.left=0 + "px";
	}
	else
	{
		document.getElementById(name).style.top=(mouseY-20+extra)+"px";
		if (page_width<mouseX || mouseX+width+40>page_width)
		{
        	document.getElementById(name).style.left=(mouseX-width) + "px";
        	document.getElementById(name).style.top=(mouseY+13)+ "px";
		}
		else
		document.getElementById(name).style.left=(mouseX+10)+"px";
	}



       // dis[name] = dis[name]=="hidden" ? "visible" : "hidden";
        if (document.getElementById)
	{
        document.getElementById(name).style.visibility = state;
	}
        else {
        if (document.lyrs)  // Netscape 4
        eval ("document."+name+".visibility = '"+ state+"'");
        else  // IE 4
        eval ("document.all."+name+".style.visibility = '"+ state +"'");
        }
//	if (url_parameters("test"))
//	alert (id);

	if (typeof(id)!="undefined")
	document.getElementById(name).innerHTML= "<div class='"+lhsclass+"' style='border: solid 2px;padding: 2px 2px 2px 12px; width:"+width+"px; height:"+height+"px'>"+id+"</div>";

	if (state=="visible")
	{
	if (roto) clearTimeout(roto);
	roto=setTimeout("sh('rollover','','hidden')",t);
	}
}

function showTrainFrame(id) { sh("rollover", id + " Station",'visible'); setTimeout("sh('rollover','','hidden')",1000); }

function showPropertyFrame(id, tCurrent)
{
	pid=id;
	sfv=false;

	if (show_lhs)
	{
	/*
	slb ("leftpanel","<a href='javascript:void(showSearchFrame())' class="+aroundmaplinksclass+">" + labels["tabs_property"] + "</a><img  width=1 src='"+images_directory + blank_icon+"'><iframe id="+property_iframe+" frameborder=0 width=" + lhs_panel_width + " height=" + (map_height+10) +" src='" + blank + "'></iframe>");
	*/
	slb ("leftpanel","<a href='javascript:void(showSearchFrame())' class="+aroundmaplinksclass+">" + labels["tabs_property"] + "</a><iframe id="+property_iframe+" frameborder=0 width='" + lhs_panel_width + "' height=" + (map_height+10) +" src='" + blank + "'></iframe>");
	document.getElementById("leftpanel").style.display="block";
	if (hasSearchFrame)
	document.getElementById("searchframe").style.display="none";
	}

	if (property_external_frameset)
	{
	eval (property_external_frameset + ".location = property_url+id");
	}
	else if (properties_url_external=="true")
	{
	c= map.getCenter();
	document.getElementById(property_iframe).src=property_url + id + "&zoom=" + (17-cl) + "&lng="+c.x+"&lat="+c.y + "&currentrow=1";
	}
	else
	document.getElementById(property_iframe).src=property_url + "?type="+searchType+"&current="+(tCurrent>0 ? tCurrent : 1)+"&zoom=" + cl + "&"+property_var+"="+id;
	dis["legend"]=dis["advanced"]="hidden";
}

function showOfficeFrame(id)
{
	sfv=false;
	slb ("leftpanel","<a href='javascript:void(showSearchFrame())'>" + labels["tabs_office"] + "</a><iframe frameborder=0 width=" + lhs_panel_width + " height=" + map_height +" src='" + office_url + "?"+office_var+"="+id+"&type="+searchType+"&current=1'><b>" + id +  "</b></iframe>");
}

function showSchoolFrame(id)
{
	sfv=false;
	slb ("leftpanel","<a href='javascript:void(showSearchFrame())'>" + labels["tabs_school"] + "</a><iframe frameborder=0 width=" + lhs_panel_width + " height=" + map_height +" src='" + school_url + "?school="+id+"&type="+searchType+"&current=1'><b>" + id +  "</b></iframe>");

}

function llr(r) { if (r.readyState == 4) { locations = new Array(); var rD = r.responseXML; if (rD.documentElement) { var places = rD.documentElement.getElementsByTagName("p"); for (var i=0; i<places.length; i++) { var element = locations.length; locations[element] = new Array(); locations[element]["place"] = places[i].getAttribute("place"); locations[element]["lat"] = places[i].getAttribute("lat"); locations[element]["lng"] = places[i].getAttribute("lng"); } sl(); delete r; } } }

function sl()
{
	var location_size = locations.length;
	var loc = document.getElementById("locationchoices");

	if (location_size==1)
	{
		var temp = locations[0]["lat"] + "," + locations[0]["lng"] + "), " + cl;
		if (locations[0])
		jumpto (temp);
		//loc.value = locations[0]["place"];
	dis["locationchoices"]="visible";
	sle ("locationchoices");
	}
	else
	{
	var height = (location_size+1)*16 + 50;
	loc.style.height=height;
	loc.style.width=300;
	loc.style.top=map_height + map_down_from_top - height - 50;

	if (mouseX>0)
	loc.style.left=mouseX-150;
	loc.style.visible=true;;
	//mark
	dis["locationchoices"]="hidden";
	sle ("locationchoices");

	var show_places = "";
	for (var i=0; i<location_size; i++)
	{
		show_places+="<br> " + (i+1) + ") <a href='javascript:void(jumpto(\"" + locations[i]["lat"] +  "," + locations[i]["lng"] + "), " + cl + "\"))' class="+aroundmaplinksclass+">" + locations[i]["place"] + "</a>";
	}
	var inner = "<a href='javascript:void(sle(\"locationchoices\"))'>"+labels["possiblelocations"] + "</a><br>&nbsp;<br><b><font style='font-size:11pt'>"+locations.length+" places found.</font></b><br>" + show_places + "</font>";
	loc.innerHTML=inner;
	}
}

function lp_request(request)
{
	if (request.readyState == 4)
        {
                var rD = request.responseXML;
                if (rD.documentElement)
                {
                        var pf = rD.documentElement.getElementsByTagName("total");
			for (var i=0; i<basic.length; i++)
                        on_map_nos[basic[i]] = pf[0].getAttribute(basic[i]);

			on_map = (1*on_map_nos["houses"]) + 1*(on_map_nos["flats"]);

			pHash = new Array();


			for (var p=0; p<offices.length; p++) rmal (offices[p]);
			for (var p=0; p<schools.length; p++) rmal (schools[p]);
			for (var p=0; p<trains.length; p++) rmal (trains[p]);

			loadElement (rD, "lP","p","pHash");
			loadElement (rD, "trains","t","");
			loadElement (rD, "schools","s","");
			loadElement (rD, "offices","o","");

                        pt = window.setTimeout(pp, 100);
                        delete request;
                }
        }
}

function loadElement (rD, name, element, hash) { eval (name+"=new Array()"); var te = rD.documentElement.getElementsByTagName(element); for (var i=0; i<te.length; i++) { eval ("el="+name+".length"); eval (name+"[el] = new Array()"); eval (name+"[el]['id'] = te[i].getAttribute('id')"); eval (name+"[el]['lat'] = te[i].getAttribute('lat')"); eval (name+"[el]['lng'] = te[i].getAttribute('lng')"); eval (name+"[el]['kd'] = te[i].getAttribute('k')"); eval (name+"[el]['marker'] = false"); eval (name+"[el]['listener'] = false"); eval (name+"[el]['listener2'] = false"); if (hash) { eval (hash+"["+name+"[el]['id']]=true"); eval (name+"[el]['type'] = te[i].getAttribute('type')"); } } }

function add_listeners() { GEvent.addListener(map, "moveend", lp2);
if (smallzoom)
GEvent.addListener(map, "zoomend", dZ2);
}

function pB() { var bminX = null; var bmaxX = null; var bminY = null; var bmaxY = null; for (var b=0; b<rB.length; b++) { bminX = rB[b][1]; bmaxX = rB[b][3]; bminY = rB[b][2]; bmaxY = rB[b][4]; blevel = rB[b][0]; if (blevel<(17-cl)) { var pts = new Array(new GPoint(bminX, bmaxY), new GPoint(bmaxX, bmaxY), new GPoint(bmaxX, bminY), new GPoint(bminX, bminY), new GPoint(bminX, bmaxY)); map.addOverlay(new GPolyline(pts,bT[2],bT[3],bT[4])); } } }

function noc(st) { if (typeof(st)=="undefined") return 0; return st; }

function numberOfCommas(st) { return st.split(",").length; }

function showlist(b) { var minX = rB[b][1]; var minY = rB[b][4]; var maxX = rB[b][3]; var maxY = rB[b][2]; var b= map.getBounds(); var sw = b.getSouthWest(); var ne = b.getNorthEast(); if (minX<sw.lng()) minX=sw.lng(); if (minY<sw.lat) minY=sw.lat(); if (maxX>ne.lng) maxX=ne.lng(); if (maxY>ne.lat) maxY=ne.lat(); top.document.location="../" + search_url+ guv(minX, minY, maxX, maxY)+"&a=list_view&cl="+(17-cl); }

function boundaryText (number, text, ids, bminX, bmaxY, bmaxX, bminY) { var nameTag = new GIcon(); var total=noc(ids); nameTag.image = tag_url + "?t=" + text + ": " + total + "&h=" + bT[1] + "&w=" + bT[0] + "&f=" + bT[5] + "&b=" + bT[6] + "&it=" + bT[7] + "&ib=" + bT[8] + "&s=" + bT[9] + "&fo=" + bT[10]; nameTag.iconSize = new GSize(bT[0],bT[1]); nameTag.iconAnchor = new GPoint(0,0); if (typeof(bm[number])!="undefined") map.removeOverlay(bm[number]); bm[number] = new GMarker (new GLatLng ( bminY + ((bmaxY-bminY)/2), bminX + ((bmaxX-bminX)/2) - (bT[0] / (Math.pow(2, (17-cl)) * 0.77162458338772))/2),nameTag); GEvent.addListener(bm[number], 'click', function() { showlist(number)}); if (rB[number][0]<17-cl) map.addOverlay(bm[number]); }

function hide_layer(which) { document.getElementById(which).innerHTML=""; document.getElementById(which).style.height=document.getElementById(which).style.width=0; }

function jumpto(value) {
if (jump_level!=0)
{
map.setZoom(jump_level);
dZ2();
}
eval ("map.panTo (new GLatLng (" + value + ")");
sle("locationchoices") }

function propertyIds() {var reg=/\,/g; var sep=separatorEnd+","+separatorStart; var comma=ids=""; for (var i=0; i<properties.length; i++) { var t = properties[i]["id"]; ids += comma + t.replace(reg,sep); comma=sep; } return separatorStart + ids + separatorEnd;}

function haveProperty(id) { for (var i=0; i<properties.length; i++) {if (properties[i]["id"] == id) return i; } return false; }

function movemap(d) { var dx = 0; var dy = 0; if (d.match("right")) dx="-1"; if (d.match("left")) dx="+1"; if (d.match("up")) dy="+1"; if (d.match("down")) dy="-1"; map.panDirection (dx,dy); }

function dZ2()
{
	recordStat("zoom");
	cl= map.getZoom();
	map.clearOverlays(); pB(); for (var p=0; p<properties.length; p++) rmal (properties[p]); properties=new Array(); return;
}
function dZ(level) { recordStat("zoom"); if (level>17-min_level-1) return; if (level<17-max_level-1) return; level++; cl = level; map.setZoom(level); map.clearOverlays(); pB(); for (var p=0; p<properties.length; p++) rmal (properties[p]); properties=new Array(); csb(); return; }

function url_parameters(w) { var params = location.search; if (params.length==0) return ""; params = params.substring(1, params.length); var pairs = params.split("&"); for (var i=0; i<pairs.length; i++) { var pv = pairs[i].split("="); if (pv[0] == w) return pv[1]; } return ""; }

function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else 	{ window.onload = function() { oldonload(); func(); }}}

function slb (element, text) {
if (!document.getElementById(element)) return;
document.getElementById(element).innerHTML = text;}

function oob (lng, lat, bounds) { return lng < bounds.minX || lng > bounds.maxX || lat < bounds.minY ||  lat > bounds.maxY ? true : false }

function googleMapInsertSmall(width, height, lat, lng, level, name) { level=17-level;document.write ("<div id='map' style='width:" + width +"px; font: arial; height:" + height + "px'><br>&nbsp; &nbsp;please wait... map loading</div>"); setTimeout("googleMapInsertSmall2(" + lat + "," + lng + "," + level + ",'"+ name +"',false)",800); }

function googleMapInsertSmallWithOverview(width, height, lat, lng, level, name) { level=17-level;document.write ("<div id='map' style='width:" + width +"px; font: arial; height:" + height + "px'><br>&nbsp; &nbsp;please wait... map loading</div>"); setTimeout("googleMapInsertSmall2(" + lat + "," + lng + "," + level + ",'"+ name +"',true)",800); }

function googleMapInsertSmall2(lat,lng, level, name, overview) { map = new GMap2(document.getElementById("map")); if (hybrid) map.addControl(new GMapTypeControl()); if (zm) map.addControl(new GLargeMapControl());

if (traffic==true)
{
        map.addControl(new ExtMapTypeControl({showTraffic: true, showTrafficKey: false}));
}

if (overview)
{ map.addControl(new GOverviewMapControl(new GSize(150, 150))); var omap=document.getElementById("map_overview"); var mapdiv =document.getElementById("map"); omap.style.position = "relative"; omap.style.right = "0px"; omap.style.bottom = "8px"; mapdiv.appendChild(omap);}

 map.setCenter(new GLatLng(lat,lng), level); if (!icons[name]) sui (name); map.addOverlay(new GMarker (new GLatLng(lat, lng),icons[name]));  recordStat("small"); }

function googleMapInsertRhs()
{
	tabalign=1;
	if (1)
	{
		var arrows = new Array ("up_left","up","up_right","left","right","down_left","down","down_right");
		for (var i=0; i<arrows.length; i++)
		{
		if (show_arrows)
		eval ("var " + arrows[i] + "='<a href=\\'javascript:void(movemap(\""+arrows[i]+"\"))\\'><img vspace=4 src=\\'"+ images_directory + arrows_g[i] + "\\' border=\\'0\\'>'");
		else
		eval ("var " + arrows[i] + "=''");
		}
	}
	var width = Math.floor((map_width - 15)/2);

	lhs_text = placeForm();


	document.write("<table border=0> <tr><td>"+up_left+"</td><td width='" + width + "'><img width=" + width + " border=0 height=1 src='blank.gif'></td><td align=center width=15>"+up+"</td><td width='"+width+"' align=center><div id='scale' class="+aroundmapclass+"></div> </td><td>"+up_right+"</td> <td rowspan=4 valign=top width=" + lhs_panel_width + "><img src='"+images_directory + blank_icon+"' height=1 width='"+lhs_panel_width+"' border=0><br><div id='leftpanel' class="+aroundmapclass+"></div></td></tr> <tr><td>"+left+"</td> <td colspan=3 valign=top><div id='map' style='width:" + map_width +"px; height:" + map_height + "px'></div><div id='grey' style='position: absolute; top:"+(map_down_from_top+25)+"px; height:"+map_height+"'></div>");
	document.write ("<div id='locationchoices' style='position:absolute;visibility:hidden' class="+lhsclass2+"></div>");
	document.write ("<div id='status' style='position:absolute; top:" + (map_down_from_top+3) + "px;width:200px' class='" + aroundmapclass + "'></div>");
	document.write("</td><td>"+right+"</td></tr><tr> <td>"+down_left+"</td><td><div id='mapsize' class="+aroundmapclass+"></div><div id='debugging' class="+aroundmapclass+"></div></td><td align=center>"+down+"</td> <td>");


	if (show_goto=="true")
	document.write ("<form style='display:inline' onsubmit='checklocation(); return false'><input id='searchfor' onclick='this.value=\"\"' style='width:100px' value='"+labels["enterplace"]+"' type=text name='searchfor'  class="+aroundmapinputclass+" > <input type=button onclick='checklocation()' value='"+labels["search"]+"'  onmouseover='sle (\"info\",labels[\"search_instructions\"],-300,\"\",-100)' onmouseout='hideInfo()' class="+aroundmapbuttonclass+"></form>");

	document.write("</td><td>"+down_right+"</td> </tr><tr><td colspan=2 height=50>&nbsp;</td></tr></table><div id='info' style='width:170px;position:absolute;visibility:hidden' class='" + aroundmapclass + "' ></div><div id='rollover' style='position:absolute; top:20px; left:0px; visibility:hidden; width:100' class='" + aroundmapclass + "'></div>");
}

function googleMapInsert()
{
	if (1) //show_arrows || 1)
	{
		var arrows = new Array ("up_left","up","up_right","left","right","down_left","down","down_right");
		for (var i=0; i<arrows.length; i++)
                {
                if (show_arrows)
                eval ("var " + arrows[i] + "='<a href=\\'javascript:void(movemap(\""+arrows[i]+"\"))\\'><img vspace=4 src=\\'"+ images_directory + arrows_g[i] + "\\' border=\\'0\\'>'");
                else
                eval ("var " + arrows[i] + "=''");
                }

	}
	var width = Math.floor((map_width - 15)/2);

	lhs_text = placeForm();

	var mw = map_width;
	var mh = map_height;
	if (url_parameters("large")=="true")
	{
		mw= map_width = map_width_large;
		mh= map_height = map_height_large;
		map_size=1;
		//slb ("mapsize","<a href='javascript:void(mapSmall())' class="+aroundmaplinksclass+">"+labels["decrease_map"]+"</a>");
	}

	document.write("<table border=0> <tr><td rowspan=4 valign=top width=" + lhs_panel_width + "><img src='"+images_directory + blank_icon+"' height=1 width='"+lhs_panel_width+"' border=0><br><div id='leftpanel' class="+aroundmapclass+"></div></td><td>"+up_left+"</td><td width='" + width + "'><img width=" + width + " border=0 height=1 src='blank.gif'></td><td align=center width=15>"+up+"</td><td width='"+width+"' align=center><div id='scale' class="+aroundmapclass+"></div> </td><td>"+up_right+"</td> </tr> <tr><td>"+left+"</td> <td colspan=3 valign=top><div id='map' style='width:" + mw +"px; height:" + mh + "px'></div><div id='grey' style='position: absolute; top:"+(map_down_from_top+25)+"px; height:"+map_height+"'></div>");
	document.write ("<div id='locationchoices' style='position:absolute;visibility:hidden' class="+lhsclass2+"></div>");
	document.write ("<div id='status' style='position:absolute; top:" + (map_down_from_top+3) + "px; width:200px' class='" + aroundmapclass + "'></div>");
	document.write("</td><td>"+right+"</td></tr><tr> <td>"+down_left+"</td><td><div id='mapsize' class="+aroundmapclass+"></div><div id='debugging' class="+aroundmapclass+"></div></td><td align=center>"+down+"</td><td>");

	if (show_goto)
	document.write("<div id='locationdiv'><form style='display:inline' onsubmit='checklocation(); return false'><input id='searchfor' onclick='this.value=\"\"' value='"+labels["enterplace"]+"' type=text name='searchfor' style='width:100px' class="+aroundmapinputclass+" > <input type=button onclick='checklocation()' value='"+labels["search"]+"'  onmouseover='sle (\"info\",labels[\"search_instructions\"],-100,\"\",-100)' onmouseout='hideInfo()' class="+aroundmapbuttonclass+"></form> &nbsp;</div>");

	document.write("</td><td>"+down_right+"</td> </tr><tr><td colspan=3 height=50>&nbsp;</td></tr></table><div id='info' style='width:170px;position:absolute;visibility:hidden' class='" + aroundmapclass + "' ></div><div id='rollover' style='position:absolute; top:40px; left:0px; visibility:hidden; width:100px' class='" + aroundmapclass + "'>...</div>");
}

var blank = "http://rocketmap.worldarcstudio.com/images/blank.gif";

function optionsType()
{
	var toReturn="";
	if (!other_icons)
        {
	toReturn+="<input type='checkbox' name='houses' onclick='uf(this)' value='true' checked><img id='iconhouse' class=trans src='"+blank+"'> House <div id=\"div_houses\" style='display:inline' class='"+aroundmapclass+"'></div>";
	fV["houses"] = fV["flats"] = "true";
	toReturn+="<br><input type='checkbox' name='flats' onclick='uf(this)' value='true' checked><img id='iconflat' class=trans src='"+blank+"'> Flat <div id=\"div_flats\" style='display:inline' class='"+aroundmapclass+"'></div>";
	}
	else
	{
		toReturn+="<input type='hidden' name='flats' value='false'>";
		toReturn+="<input type='hidden' name='houses' value='false'>";

		for (var i=1; i<=other_icons; i++)
		{
		if (i>1) toReturn+="<br>";

		var chk = getcookie("icon"+i)=="true" ||  (!getcookie("icon"+i)) ? "checked" : "";
		if(getcookie("icon"+i)=="true") chk="checked";
		//if(document.location.href.match("uktvfood")) alert('cookie'+i+'='+getcookie("icon"+i));
		//abc
		//if (document.location.href.match("uktvfood")) alert('icon'+i+': \''+chk+'\'');
		toReturn+="<input type='checkbox' value='true' name='icon"+i+"' onclick='uf(this)' "+chk+"><img id='iconid"+i+"' class=trans src='"+blank+"'> "+eval ("label_"+i)+" "; //<div id=\"div_"+i+"\" style='display:inline' class='"+aroundmapclass+"'></div>";
		if(i<other_icons && checkbox_divider) toReturn+=checkbox_divider;
		fV["icon"+i] = "true";
		}
	}

	if (show_schools)
	{
		toReturn+="<br><input type='checkbox' name='schools' onclick='uf(this)' value='true'><img id='iconschool' class=trans src='"+blank+"'> Schools <div id=\"div_schools\" style='display:inline' class='"+aroundmapclass+"'></div>";
		fV["schools"] = "true";
	}
	else
	{
		toReturn+="<input type='hidden' name='schools' value=true>";
		fV["schools"] = "false";
	}

	if (show_trains)
	{
		toReturn+="<br><input type='checkbox' name='trains' onclick='uf(this)' value='true'><img id='icontrain' class=trans src='"+blank+"'> Train Stations <div id=\"div_trains\" style='display:inline' class='"+aroundmapclass+"'></div>";
		fV["schools"] = "true";
	}
	else
	{
		toReturn+="<input type='hidden' name='trains' value=true>";
		fV["trains"] = "false";
	}

	if (show_offices)
	{
		toReturn+="<br><input type='checkbox' name='offices' value='true' onclick='uf(this)'><img id='iconoffice' class=trans src='"+blank+"'> Offices <div id=\"div_offices\" style='display:inline' class='"+aroundmapclass+"'></div>";
		fV["offices"] = officesTrueFalse;

	}
	else
	{
		toReturn+="<input type='hidden' name='offices' value=false>";
		fV["offices"] = "false";
	}

	return toReturn;
}

function dP(p) { if (p>=10000) { p/=1000; return p>=1000 ? "" + (p/1000) + "m" : p+ "k"; } return p; }

function optionsPrice()
{
	if (!show_prices || flash_sliders)
	return "<input type=hidden name='minprice' id=elementminprice value=0><input type=hidden name='maxprice' id=elementmaxprice value=1000000000>";

	var toReturn = "<br><b>Minimum Price: " + prefix[searchType] + "</b><br><select name='minprice' id=elementminprice onchange='uf(this)' class='"+aroundmapdropdownclass+"'>";
	var select;

	for (var i=0; i<price_from[searchType].length;i++)
	toReturn += "<option value='" + price_from[searchType][i] + "'>" + dP(price_from[searchType][i]) + "</option>";
	toReturn +="</select>&nbsp;<br>Maximum Price: " + prefix[searchType] + "<br><select name='maxprice' id=elementmaxprice onchange='uf(this)' class='"+aroundmapdropdownclass+"'>";
	for (var i=0; i<price_to[searchType].length;i++)
	{
		selected = i==price_to[searchType].length-1 ? "selected" : "";
		toReturn += "<option value='" + price_to[searchType][i] + "' " + selected + ">" + dP(price_to[searchType][i]) + "</option>";
	}
	toReturn+="</select>";
	fV["minprice"] = "0";

	fV["maxprice"] = max_price_default; //price_to[searchType][price_to[searchType].length-1];


	fV["minbeds"] = "0";
	fV["minbaths"] = "0";

	if (show_letting_type && searchType=='r')
	toReturn+=optionsLettings();
	else
	toReturn+="<input type=hidden name='letting_type' value='' id=elementletting_type>";

	if (show_furnished && searchType=='r')
	toReturn+=optionsFurnished();
	else
	toReturn+="<input type=hidden name='furnished' value='' id=elementfurnished>";
	return toReturn;
}

function optionsGeneric (show, name, id, vars) { if (!show) return ""; var tR ="<br><b>"+name+":</b><br><select id=element"+id+" class='"+aroundmapdropdownclass+"' onchange='uf(this)' name='"+id+"'>"; for (var i=0;i<vars.length;i++) tR+= "<option value='"+i+"'>"+i+"</option>"; tR+="</select>"; return tR; }


function optionsBaths()
{
	if (!show_bathrooms) return "";
	return "<br><b>Minimum Bathrooms:</b><br><select id=elementminbaths class='"+aroundmapdropdownclass+"' onchange='uf(this)' name='minbaths'> <option value='0'>0</option> <option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option> <option value='4'>4</option> <option value='5'>5</option> </select>";
}

function optionsUnits()
{
	if (!show_units) return "";
	return "<br><b>Minimum Units<br>(<font color=red>Multi-Family Only</font>):</b><br><select id=elementunits class='"+aroundmapdropdownclass+"' onchange='uf(this)' name='units'> <option value='0'>0</option> <option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option> <option value='4'>4</option> <option value='5'>5</option> </select>";
}

function optionsBeds()
{
	if (!show_minbeds || flash_sliders)
	return "<input  id=elementminbeds type=hidden name='minbeds' value='0'>";

	return "<br><b>Minimum Bedrooms:</b><br><select id=elementminbeds class='"+aroundmapdropdownclass+"' onchange='uf(this)' name='minbeds'> <option value='0'>0 (studio)</option> <option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option> <option value='4'>4</option> <option value='5'>5</option> </select>";
}

function optionsSearchText()
{
	fV["searchtext"] = "";
	if (show_searchtext)
	return "<br>Keyword Text: <br><input type=text onclick='this.value=\"\";uf(this); return false' name=searchtext id=elementsearchtext onblur='uf(this)' style='width:100px' class="+textclass+" onsubmit='return false'> <input type=button value='go' class="+aroundmapbuttonclass+" style='width:25px'><br>&nbsp;";
	else
	return "<input type=hidden name=searchtext id=elementsearchtext>";
}

function otherFilters()
{
	var toreturn="<font class='" + aroundmapclass+ "'>";
	for (var i=0; i<filters.length; i++)
	{
		if (filters[i]!="schools" && filters[i]!="offices" && filters[i]!="searchtext")
		{
			if (!eval ("show_" + filters[i]))
			{
				toreturn+= "<input type=hidden name=" + filters[i] +" value='on'>";
				fV[filters[i]] = "on";
			}
			else if (filters[i]=="added")
			{
				toreturn+="<b>Properties Added:</b> <select class='"+aroundmapdropdownclass+"' onchange='uf(this)' id=elementadded name=" + filters[i] +"><option value='' selected>All</option><option value='1'>Last 24 Hours</option><option value='3'>Last 3 Days</option><option value='7'>Last Week</option></select>";
				fV[filters[i]] = "";
			}
			else if (filters[i]=="new_homes")
			{
				toreturn+="<br><b>Property Age:</b> <select class='"+aroundmapdropdownclass+"' onchange='uf(this)' id=elementnew_homes name=" + filters[i] +"><option value=''>All</option><option value='new'>New Homes</option><option value='resale'>Resale homes</option></select>";
				fV[filters[i]] = "";
			}
			else
			{
				var name = labels[filters[i]] ? labels[filters[i]] : filters[i];
				toreturn+="<br><b>"+name+":</b><br><select class='"+aroundmapdropdownclass+"' onchange='uf(this)' id=element" + filters[i] +" name=" + filters[i] +"><option value='' selected>All</option><option value='yes'>With</option><option value='no'>Without</option></select>";
				fV[filters[i]] = "";
			}
		}
	}

	toreturn+=optionsSearchText();

	lyrs["advanced"]=toreturn;
	if (toreturn && labels["advanced"])
	toreturn= "<br>&nbsp;<br><a href='javascript:showHide(\"advanced\")'><font class="+aroundmapheadlineclass+">"+labels["advanced"] + "</a>";

	toreturn+="<br><div id='advanced'><br></div>";


	return toreturn;
}

function optionsLettings()
{
        fV["letting_type"] = "";
	return "<br><b>Type of Lettings:</b> <select class='"+aroundmapdropdownclass+"' id=elementletting_type onchange='uf(this)' name='letting_type'><option value=''>All</option><option value='short'>short let</option><option value='long'>long let (> 6 months)</option></select>";
}


function optionsFurnished()
{
        fV["furnished"] = "";
	return "<br><b>Furnished:</b> <select class='"+aroundmapdropdownclass+"' id=elementfurnished onchange='uf(this)' name='furnished'><option value=''>All</option><option value='furnished'>furnished</option><option value='unfurnished'>unfurnished</option></select>";
}

function optionsAgencyClick(obj)
{
	uf (obj);

	var t = document.getElementById('ohbox').style.display;
	if (t=='block')
	document.getElementById('ohbox').style.display='none';
	else
	document.getElementById('ohbox').style.display='block';
}

function optionsAgency()
{
	if (!show_agencies) return "";
	else
	return "<br><input type=checkbox id=agency name=agency onclick='uf(this)' value=true>MLS listings only<br><input type=checkbox id=oh name=oh onclick='optionsAgencyClick(this)' value=true>Open House listings only<div name=ohbox id=ohbox style='display:none'>&nbsp; &nbsp; &nbsp;<select name='ohdate' id=ohdate onchange='uf(this)' class='"+aroundmapdropdownclass+"'><option value=''>All<option value='today'>today<option value='tomorrow'>tomorrow<option value='this week'>this week<option value='this month'>this month<option value='next month'>next month</select></div>";
}

function showCredit()
{
	if (!show_logo) return "";
	return "<a target='wai' href='http://www.rocketmap.com'><img border=0 src='http://rocketmap.worldarcstudio.com/images/blank.gif' id=\"cred\" height=32 width=130 onload='alpha(\"cred\",\"http://rocketmap.worldarcstudio.com/images/credit.png\")'></a>";
}

function placeForm()
{
	if (show_lhs==false)
	return "<form id=mapform><input id=minbeds type=hidden><input id=maxprice type=hidden><input id=minprice type=hidden><input id=houses type=hidden><input id=flats type=hidden></form>" + lhs_extra_text;
	return labels["tabs_options"] + "<div class='"+lhsclass+"'>"+labels["options_top"]+"<a href='javascript:void(sle(\"help\"))'>" + labels["help"] + "</a><div id='help' style='z-index:200;position:absolute;top:100px;visibility:hidden; left:-10000px; width:400px'>"+labels["instructions_top"] +"<div class='"+lhsclass+"'>"+helpText+ "</div></div><form id='mapform' onsubmit='return false' style='padding-bottom:0; margin-bottom:0'>" + optionsType() + divider  + optionsSliders() +optionsPrice() + optionsBeds() + optionsGeneric (show_bathrooms, "Minimum Bathrooms", "minbaths", onetofive) + optionsUnits() + optionsAgency() + otherFilters() + legend()+ lhs_extra_text + "</form>"  + showCredit() + below_options;
}

function optionsSliders()
{ return "";}

function sle(name, content,left, status,above)
{
	if (content=="" && dis[name]=="hidden") return;
	var extra = document.body.scrollTop;
	if (!ie) extra=0;
	dis[name] = dis[name]=="hidden" ? "visible" : "hidden";

	if (status)
	dis[name]=status;
	if (above) extra+=above;

	if (document.getElementById) { // DOM3 = IE5, NS6
	{
	if (dis[name]=="visible")
	document.getElementById(name).style.display = "block";
	document.getElementById(name).style.visibility = dis[name];
	if (name!="locationchoices")
	{
		if (tabalign==1)
		document.getElementById(name).style.left=20;
		else if (mouseX>0 && !left)
		document.getElementById(name).style.left=mouseX+120;
		else if (mouseX>0)
		document.getElementById(name).style.left=mouseX+left;

		if (mouseY>0)
		document.getElementById(name).style.top=mouseY + extra;
		if (content)
		document.getElementById(name).innerHTML=labels["instructions_top"] + "<div class='"+lhsclass+"'>"+content+"</span>";
	}
	}
	}
	else {
	if (document.lyrs) { // Netscape 4
	eval ("document."+name+".visibility = '"+ dis[name]+"'");
	}
	else { // IE 4
	eval ("document.all."+name+".style.visibility = '+ dis[name]+'");
	}
	}
	return false;
}

function showHide (name) { dis[name] = dis[name] ? false : true; if (!dis[name]) { document.getElementById(name).innerHTML = lyrs[name]; nte(); } else document.getElementById(name).innerHTML = "<br>"; }

function legendH (id, icon, name)
{
	return "<img id='"+id+"' class=trans src='"+blank+"' onload=\"alpha('"+id+"', icon_directory + " + icon+")\">"+name;
}

function legend()
{
	if (!show_legend) return "";

	var c = "<a href='javascript:showHide(\"legend\")'><font class="+aroundmapheadlineclass+">"+labels["legend"]+"</font></a><div id='legend'></div>";
	lyrs["legend"] = "<font class='"+aroundmapclass+"'>";
	lyrs["legend"] += legendH('iconhouse2', 'house_icon', 'House');
	lyrs["legend"] += "<br>" + legendH('iconhouses2', 'houses_icon', 'Multiple Houses');
	lyrs["legend"] += "<br>" + legendH('iconflat2', 'flat_icon', 'Flat');
	lyrs["legend"] += "<br>" + legendH('iconflats2', 'flats_icon', 'Multiple Flats');
	lyrs["legend"] += "<br>" + legendH('iconmixed2', 'mixed_icon', 'House and Flats');
	if (show_schools)
	lyrs["legend"] += "<br>" + legendH('iconschool2', 'school_icon', 'Schools');

	if (show_offices)
	lyrs["legend"] += "<br>" + legendH('iconoffice2', 'office_icon', 'Offices');
	if (show_trains)
	lyrs["legend"] += "<br>" + legendH('icontrain2', 'train_icon', 'Train Stations');

	return c;
}

function getexpirydate( nodays){ var UTCstring; Today = new Date(); nomilli=Date.parse(Today); Today.setTime(nomilli+nodays*24*60*60*1000); UTCstring = Today.toUTCString(); return UTCstring; }

function getcookie(cN) { cN = searchType + cN;

if (iconsasonecookie)
{
	if (cN.match("bicon") && !cN.match("bicons"))
	{
	var num = cN.replace ("bicon","");
	var wholevalue  = getcookie ("icons");

	if (wholevalue)
	{
		var wvs = wholevalue.split(":");
	//alert ("look at " + num + " = " + wvs[num-1] + " from " + wholevalue);
		return wvs[num-1];
	}
	}
}

var cS=""+document.cookie; var i1=cS.lastIndexOf(cN); if (i1==-1 || cN=="") return ""; var i2=cS.indexOf(';',i1); if (i2==-1) i2=cS.length; return unescape(cS.substring(i1+cN.length+1,i2)); }

function setcookie(n,v,d){ if (document.location.href.match(/roea/)) return; n = searchType + n; var cS=n+"="+escape(v)+";EXPIRES="+getexpirydate(d); document.cookie=cS; if(!getcookie(n)){ return false; } else{ return true; } }

window.onload = init;
function init() { recordStat("init");if (window.Event) { document.captureEvents(Event.MOUSEMOVE); } document.onclick = getXY; document.onmousemove = getXY; }

function getXY(e) { mouseX = (window.Event) ? e.pageX : event.clientX; mouseY = (window.Event) ? e.pageY : event.clientY; }

GMap2.prototype.addOverlays=function(a){ var b=this; for (i=0;i<a.length;i++) { try { this.overlays.push(a[i]); a[i].initialize(this); a[i].redraw(true); } catch(ex) { alert('err: ' + i + ', ' + ex.toString()); } } this.reOrderOverlays(); };

for (var i=0; i<filters.length; i++)
eval ("if (typeof(show_"+ filters[i] + ")==\"undefined\") var show_"+ filters[i] +"=false;");

if (!smallMap)
addLoadEvent (im);

function recordStat(action)
{
	document.getElementById("recordstat").innerHTML = "<img src='http://rocketmap.worldarcstudio.com/gmap_js2/stats.php?action="+action+"&url="+document.location.href+"' height=1 width=1>";


}

/*
* ExtMapTypeControl Class v1.2 
*  Copyright (c) 2007, Google 
*  Author: Pamela Fox, others
* 
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 
*       http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This class lets you add a control to the map which mimics GMapTypeControl
*  and allows for the addition of a traffic button/traffic key.
*/

/*
 * Constructor for ExtMapTypeControl, which uses an option hash
 * to decide what elements to put in the control.
 * @param {opt_opts} Named optional arguments:
 *   opt_opts.showTraffic {Boolean} Controls whether traffic button is shown
 *   opt_opts.showTrafficKey {Boolean} Controls whether traffic key is shown
 */
function ExtMapTypeControl(opt_opts) {
  this.options = opt_opts || {};
}


ExtMapTypeControl.prototype = new GControl();

/**
 * Is called by GMap2's addOverlay method. Creates the button 
 *  and appends to the map div.
 * @param {GMap2} map The map that has had this ExtMapTypeControl added to it.
 * @return {DOM Object} Div that holds the control
 */ 
ExtMapTypeControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  var me = this;

  var mapTypes = map.getMapTypes();
  var mapTypeDivs = me.addMapTypeButtons_(map);

  GEvent.addListener(map, "addmaptype", function() {
    var newMapTypes = map.getMapTypes();
    var newMapType = newMapTypes.pop();
    var newMapTypeDiv = me.createButton_(newMapType.getName());
    mapTypes.push(newMapType);
    mapTypeDivs.push(newMapTypeDiv);
    me.resetButtonEvents_(map, mapTypeDivs);
    container.appendChild(newMapTypeDiv);
  });
  GEvent.addListener(map, "removemaptype", function() {
    for (var i = 0; i < mapTypeDivs.length; i++) {
      GEvent.clearListeners(mapTypeDivs[i], "click");
      container.removeChild(mapTypeDivs[i]);
    }
    mapTypeDivs = me.addMapTypeButtons_(map);
    me.resetButtonEvents_(map, mapTypeDivs);
    for (var i = 0; i < mapTypeDivs.length; i++ ) {
      container.appendChild(mapTypeDivs[i]);
    }
  });

  if (me.options.showTraffic) {
    var trafficDiv = me.createButton_("Traffic");
    trafficDiv.style.marginRight = "8px";
    trafficDiv.style.visibility = 'hidden';
    trafficDiv.firstChild.style.cssFloat = "left";
    trafficDiv.firstChild.style.styleFloat = "left";
    // Sending true makes overlay hidden by default
    me.trafficInfo = new GTrafficOverlay(true);
    me.trafficInfo.hidden = true;
    // We have to do this so that we can sense if traffic is in view
    GEvent.addListener(me.trafficInfo, "changed", function(hasTrafficInView) {
      if (hasTrafficInView) {
        trafficDiv.style.visibility = 'visible';
      } else {
        trafficDiv.style.visibility = 'hidden';
      }
    });
    map.addOverlay(me.trafficInfo);

    GEvent.addDomListener(trafficDiv.firstChild, "click", function() {
      if (me.trafficInfo.hidden) {
        me.trafficInfo.hidden = false;
        me.trafficInfo.show();
      } else {
        me.trafficInfo.hidden = true;
        me.trafficInfo.hide();
      }
      me.toggleButton_(trafficDiv.firstChild, !me.trafficInfo.hidden);
    });

    if (me.options.showTrafficKey) {
      keyDiv = document.createElement("div");
      keyDiv.style.cssFloat = "left";
      keyDiv.style.styleFloat = "left";
      keyDiv.innerHTML = "&nbsp;?&nbsp;";
  
      var keyExpandedDiv = document.createElement("div");
      keyExpandedDiv.style.clear = "both";
      keyExpandedDiv.style.padding = "2px";
      var keyInfo = [{"color": "#30ac3e", "text": "&gt; 50 MPH"},
                     {"color": "#ffcf00", "text": "25-50 MPH"},
                     {"color": "#ff0000", "text": "&lt; 25 MPH"},
                     {"color": "#c0c0c0", "text": "No data"}];
      for (var i = 0; i < keyInfo.length; i++) {
        keyExpandedDiv.innerHTML += "<div style='text-align: left'><span style='background-color: " + keyInfo[i].color + "'>&nbsp;&nbsp</span>"
            +  "<span style='color: " + keyInfo[i].color + "'> " + keyInfo[i].text + " </span>" + "</div>"; 
      }
      keyExpandedDiv.style.display = "none";

      GEvent.addDomListener(keyDiv, "click", function() {
        if (me.keyExpanded) {
          me.keyExpanded = false;
          keyExpandedDiv.style.display = "none";
        } else {
          me.keyExpanded = true;
          keyExpandedDiv.style.display = "block";
        }
        me.toggleButton_(keyDiv, me.keyExpanded);
      });

      me.toggleButton_(keyDiv, me.keyExpanded);
    }

    var separatorDiv = document.createElement("div");
    separatorDiv.style.clear = "both";

    if (me.options.showTrafficKey) trafficDiv.appendChild(keyDiv);
    trafficDiv.appendChild(separatorDiv);
    if (me.options.showTrafficKey) trafficDiv.appendChild(keyExpandedDiv);
    me.toggleButton_(trafficDiv.firstChild, false);

    container.appendChild(trafficDiv);
  }

  for (var i = 0; i < mapTypeDivs.length; i++ ) {
    container.appendChild(mapTypeDivs[i]);
  }

  map.getContainer().appendChild(container);

  return container;
}

/*
 * Creates buttons for map types.
 * @param {GMap2} Map object for which to create buttons.
 * @return {Array} Divs containing the buttons.
 */
ExtMapTypeControl.prototype.addMapTypeButtons_ = function(map) {
  var me = this;
  var mapTypes = map.getMapTypes();
  var mapTypeDivs = new Array();
  for (var i = 0; i < mapTypes.length; i++) {
    mapTypeDivs[i] = me.createButton_(mapTypes[i].getName());
  }
  me.resetButtonEvents_(map, mapTypeDivs);
  return mapTypeDivs;
}

/*
 * Ensures that map type button events are assigned correctly.
 * @param {GMap2} Map object for which to reset events.
 * @param {Array} mapTypeDivs Divs containing map type buttons.
 */
ExtMapTypeControl.prototype.resetButtonEvents_ = function(map, mapTypeDivs) {
  var me = this;
  var mapTypes = map.getMapTypes();
  for (var i = 0; i < mapTypeDivs.length; i++) {
    var otherDivs = new Array;
    for (var j = 0; j < mapTypes.length; j++ ) {
      if (j != i) {
        otherDivs.push(mapTypeDivs[j]);
      }
    }
    me.assignButtonEvent_(mapTypeDivs[i], map, mapTypes[i], otherDivs);
  }
  GEvent.addListener(map, "maptypechanged", function() {
    var divIndex = 0;
    var mapType = map.getCurrentMapType();
    for (var i = 0; i < mapTypes.length; i++) {
      if (mapTypes[i] == mapType) {
        divIndex = i;
      }
    }
    GEvent.trigger(mapTypeDivs[divIndex], "click");
  });
}

/*
 * Creates simple buttons with text nodes. 
 * @param {String} text Text to display in button
 * @return {DOM Object} The div for the button.
 */
ExtMapTypeControl.prototype.createButton_ = function(text) {
  var buttonDiv = document.createElement("div");
  this.setButtonStyle_(buttonDiv);
  buttonDiv.style.cssFloat = "left";
  buttonDiv.style.styleFloat = "left";
  var textDiv = document.createElement("div");
  textDiv.appendChild(document.createTextNode(text));
  textDiv.style.width = "6em";
  buttonDiv.appendChild(textDiv);
  return buttonDiv;
}

/*
 * Assigns events to MapType buttons to change maptype
 *  and toggle button styles correctly for all buttons
 *  when button is clicked.
 *  @param {DOM Object} div Button's div to assign click to
 *  @param {GMap2} Map object to change maptype of.
 *  @param {Object} mapType GMapType to change map to when clicked
 *  @param {Array} otherDivs Array of other button divs to toggle off
 */  
ExtMapTypeControl.prototype.assignButtonEvent_ = function(div, map, mapType, otherDivs) {
  var me = this;

  GEvent.addDomListener(div, "click", function() {
    for (var i = 0; i < otherDivs.length; i++) {
      me.toggleButton_(otherDivs[i].firstChild, false);
    }
    me.toggleButton_(div.firstChild, true);
    map.setMapType(mapType);
  });
}

/*
 * Changes style of button to appear on/off depending on boolean passed in.
 * @param {DOM Object} div  Button div to change style of
 * @param {Boolean} boolCheck Used to decide to use on style or off style
 */
ExtMapTypeControl.prototype.toggleButton_ = function(div, boolCheck) {
   div.style.fontWeight = boolCheck ? "bold" : "";
   div.style.border = "1px solid white";
   var shadows = boolCheck ? ["Top", "Left"] : ["Bottom", "Right"];
   for (var j = 0; j < shadows.length; j++) {
     div.style["border" + shadows[j]] = "1px solid #b0b0b0";
  } 
   }

/*
 * Required by GMaps API for controls. 
 * @return {GControlPosition} Default location for control
 */
ExtMapTypeControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 7));
}

/*
 * Sets the proper CSS for the given button element.
 * @param {DOM Object} button Button div to set style for
 */
ExtMapTypeControl.prototype.setButtonStyle_ = function(button) {
  button.style.color = "#000000";
  button.style.backgroundColor = "white";
  button.style.font = "small Arial";
  button.style.border = "1px solid black";
  button.style.padding = "0px";
  button.style.margin= "0px";
  button.style.textAlign = "center";
  button.style.fontSize = "12px"; 
  button.style.cursor = "pointer";
}

document.onunload=GUnload();
