var bookView=false;
var listView=false;
var keepSectionPath=false;
var pageSize=100;
var footerHeight=0;
var mapImgPath="/sys/images/ls/";
var starImgPath="/sys/images/all/tstars";

function getCookie(c)
{
	var dc=" "+document.cookie;
	var pos=dc.indexOf(" "+c+"=");
	if(pos<0) return "";
	var end=dc.indexOf(";",pos);
	if(end<0) end=dc.length;
	return unescape(dc.substring(pos+c.length+2,end));
}

function setCookie(c,v,e)
{
	if(!e) document.cookie=c+"="+escape(v)+";expires=Fri, 31-Dec-2023 00:00:00 GMT;path=/";
	else {
		var ed=new Date(); ed.setTime(ed.getTime()+(e*60000));	// minutes
		document.cookie=c+"="+escape(v)+";expires="+(ed.toGMTString())+";path=/";
	}
}

function initpage()
{
	loadingpage=null;
	resetypform();
	if(online && !bookView) createMap();
	if(!profile && !bookView) listscrolled();
	if(bookView) doscroll();
	if(online) loadRatings();
	if(profile && document.getElementById("streetview")) streetview2(0,0);
}

var ratingsProcs=[],ratingsto=null;
function showRatings(r,s){
	if(!r || !r.length) return;
	for(var i=0;i<r.length;i++) {
		if(!r[i]) continue;
 		var as=Math.floor(r[i][0]*2.0+0.5)*0.5;
		var el=document.getElementById('rateimg'+(i+s));
		if(!el) continue;
		if(as>0) el.src=starImgPath+as+".png";
		if(r[i][1]) el.title="Read "+r[i][1]+" review"+(r[i][1]>1?"s":"")+" / Write a review";
		else el.title="Write a review";
	}
	if(ratingsProcs.length) {
		var ri=ratingsProcs.pop();
		JSONrequest(ri.ur,showRatings,false,ri.st);
	}
}

function loadRatings(start)
{
	if(!ratelist || !ratelist.length) return;
	if(!start) start=0;
	if(ratingsto) clearTimeout(ratingsto);
	ratingsProcs=[]; ratingsto=null;
	var url="http://www.localscout.com/ratings/lookupratingreview.aspx?pubid="+(pubid?pubid:0)+"&callback=[CB]&p="+Math.random()+"&listings=";
	var s=0;
	ratelist=ratelist.split("|");
	var rstr="";
	for(var i=0;i<ratelist.length;i++) {
		rstr+="|"+encodeURIComponent(ratelist[i]);
		if(rstr.length>1800) {
			ratingsProcs.push({ur:url+rstr.substr(1),st:(start+s)});
			rstr="";
			s=i+1;
		}
	}
	if(rstr.length) ratingsProcs.push({ur:url+rstr.substr(1),st:(start+s)});
	if(ratingsProcs.length) {
		ratingsProcs.reverse();
		var ri=ratingsProcs.pop();
		JSONrequest(ri.ur,showRatings,false,ri.st);
		ratingsto=setTimeout("ratingsProcs=[];ratingsto=null;",5000);
	}
}

function ll(dt,iid,lnk) { window.open("pageserver.dll?b="+sec+"&f=l"+dt+"&s="+iid+"&go="+escape("http://"+lnk)); }

function reflistover(n,oel)
{
	el=document.getElementById(n);
	eli=document.getElementById(n+"i");
	if(!el.lheight) { 
		el.style.top="30px";
		el.lwidth=eli.offsetWidth;
		if(n=="rlkey") {
			for(var i=0;i<fcount;i++) {
				var fel=document.getElementById("fitem"+i);
				if(fel) fel.style.display="none";
			}
		}
		el.lheight=eli.offsetHeight;
		var maxh=getWindowHeight()-getPos(el).y-20;
		if(el.lheight>maxh) {
			eli.style.overflowY="auto";
			eli.style.position="relative";
			el.lheight=maxh;
			eli.style.width=(el.lwidth+20)+"px";
		}
		el.duration=200+Math.floor(el.lheight/3);
		eli.style.height='1px';
		el.fopen=0;
		var ow=oel.offsetWidth-1; if(isIE) ow+=2;
		if(oel.offsetLeft+oel.offsetWidth>el.offsetParent.offsetWidth-50) ow-=7;
		if(el.lwidth<ow-60) ow=120;
		if(el.lwidth<ow) { el.lwidth=ow; eli.style.width=ow+"px"; }
		el.xpos=oel.offsetLeft+oel.offsetWidth/2-el.offsetWidth/2+3;
		if(el.xpos<oel.offsetLeft-1) el.xpos=oel.offsetLeft-1;
		var pw=el.offsetParent.offsetWidth-10; if(isIE) pw++;
		if(el.xpos+el.offsetWidth>pw) el.xpos=pw-el.offsetWidth;
		if(el.xpos<10) el.xpos=10;
	}
	if(el.forceclose) return;
	el.doclose=false;
	el.doopen=true;
	setTimeout("reflistopen('"+n+"')",100);
}

function reflistopen(n)
{
	el=document.getElementById(n);
	if(!el.doopen||el.ostate==1||el.fopen==1) return;
	el.doopen=false;
	el.style.left=el.xpos+"px";
	el.otime=new Date().getTime()-el.fopen*el.duration;
	el.ostate=1;
	if(!el.otimer) el.otimer=setInterval(function(){reflistslide(n)},15);
	document.getElementById(n+"a").src="clr.gif";
}

function reflistout(n)
{
	el=document.getElementById(n);
	el.doclose=true;
	el.doopen=false;
	setTimeout("reflistclose('"+n+"')",100);
}

function reflistclose(n)
{
	el=document.getElementById(n);
	if(!el.doclose||el.ostate==2||el.fopen==0) return;
	el.doclose=false;
	el.otime=new Date().getTime()-(1-el.fopen)*el.duration;
	el.ostate=2;
	if(!el.otimer) el.otimer=setInterval(function(){reflistslide(n)},15);	
}

function reflistarrc(n)
{
	el=document.getElementById(n);
	el.forceclose=true;
	el.doclose=true;
	reflistclose(n);
}

function reflistslide(n)
{
	el=document.getElementById(n);
	eli=document.getElementById(n+"i");
	if(!el.ostate) {
		if(el.otimer) clearInterval(el.otimer);
		el.otimer=null;
		return;
	}
	if(el.ostate==1) {
		el.fopen=(new Date().getTime()-el.otime)/el.duration;
		if(el.fopen>=1) {
			el.fopen=1;
			el.ostate=0;
		}
	} else {
		el.fopen=1-(new Date().getTime()-el.otime)/el.duration;
		if(el.fopen<=0) {
			el.fopen=0;
			el.ostate=0;
			el.style.left="-2000px";
			el.forceclose=false;
			var ela=document.getElementById(n+"a");
			if(ela) ela.src="/sys/images/ls/darr4.gif";
		}
	}
	var y=(el.fopen*el.fopen*2);
	if(el.fopen>0.5) y=1-((1-el.fopen)*(1-el.fopen)*2);
	y=Math.floor(y*el.lheight+0.5); if(y<1) y=1;
    eli.style.height=y+"px";
}

var fcexpanded=[];
function fcclick(i)
{
	fcexpanded[i]=fcexpanded[i]?false:true;
	if(fcexpanded[i]) {
		document.getElementById("fcimg"+i).src="/sys/images/ls/minus.gif";
		document.getElementById("fitem"+i).style.display="";
	} else {
		document.getElementById("fcimg"+i).src="/sys/images/ls/plus.gif";
		document.getElementById("fitem"+i).style.display="none";
	}
	el=document.getElementById("rlkey");
	eli=document.getElementById("rlkeyi");
	if(!isIE) eli.style.width="auto";
	eli.style.overflowY="hidden";
	eli.style.height="auto";
	el.lheight=eli.offsetHeight;
	var maxh=getWindowHeight()-getPos(el).y-20;
	if(el.lheight>maxh) {
		eli.style.overflowY="auto";
		el.lheight=maxh;
		eli.style.width=(el.lwidth+20)+"px";
	}
	el.duration=200+Math.floor(el.lheight/3);
	eli.style.height=el.lheight+"px";
}

function setKey(k,v) {
	var str=";"+document.yp.k.value;
	i=str.indexOf(";"+k+":");
	if(i>=0) {
		var j=str.indexOf(";",i+1);
		str=str.substr(0,i)+(j>0?str.substr(j):"");
	}
	if(v&&v.toString().length) {
		if(str.substr(str.length-1)!=";") str+=";";
		str+=k+":"+v;
	}
	document.yp.k.value=str.substr(1);
}

function getKey(k) {
	var str=";"+document.yp.k.value;
	i=str.indexOf(";"+k+":");
	if(i>=0) {
		var j=str.indexOf(";",i+1);
		if(j>0) return str.substring(i+k.length+2,j);
		return str.substr(i+k.length+2);
	}
	return "";
}

function keyPath() {
	var k=document.yp.k.value;
	if(k && k.length>0) return "/k"+encodeURIComponent(k);
	return "";
}

function viewPath() {
	var s=document.yp.s.value;
	if(s==-3) return "/book";
	if(s==-7) return "/search";
	if(s==-8) return "/list";
	if(s==-12) return "/ad";
	return "";
}

function setPage(p) { document.yp.p.value=p; }

function goPage(p) { setPage(p); dogo(true); }

function sortby(v) {
	setKey("sort",v);
	setPage(0);
	dogo(true);
}

function goltr(a)
{
	setKey("alpha",a);
	setPage(0);
	dogo(true);
}

function filterby(t,i)
{
	setPage(0);
	if(filt.length) filt+="|";
	filt+=t+"="+i;
	setKey("filt",filt);
	dogo();
}

function removeFilters()
{
	setKey("filt","");
	dogo();
}

function goimp(i)
{
	setKey("imp",i);
	setKey("head","");
	setPage(0);
	dogo();
}

function gohead(h)
{
	setKey("head",h);
	setKey("imp","");
	setPage(0);
	dogo();
}

function gozoom(z)
{
	setKey("zoom",z==1000?"":z);
	dogo();
}

function gomap()
{
	document.yp.s.value=-9;
	setKey("head",""); setKey("imp",""); setKey("zoom",""); setPage(0); page=0;
	if(!keepSectionPath) sectionPath="";
	dogo();
}

function golist()
{
	document.yp.s.value=-8;
	setKey("head",""); setKey("imp",""); setKey("zoom",""); setPage(0); page=0;
	if(!keepSectionPath) sectionPath="";
	boxbounds=null;
	dogo();
}

function gobook()
{
	document.yp.s.value=-7;
	setKey("filt",""); setKey("head",""); setKey("imp",""); setKey("alpha",""); setKey("city",""); setKey("sort",""); setPage(0); page=0;
	boxbounds=null;
	dogo();
}

function goad()
{
	document.yp.s.value=-12;
	setKey("filt",""); setKey("head",""); setKey("imp",""); setKey("alpha",""); setKey("city",""); setKey("sort",""); setPage(0); page=0;
	boxbounds=null;
	dogo();
}

var sectionPath="";
function gosec(s,b,nos,v)
{
	sectionPath=s;
	if(b) document.yp.b.value=b;
	setKey("filt",""); setKey("head",""); setKey("imp",""); setKey("alpha",""); setKey("city",""); setPage(0); page=0;
	if(nos) { document.yp.go.value="-"; }
	if(v) document.yp.s.value=v;
	dogo(true);
}

function dosubmit(nochange)
{
	var where=document.yp.pa.value;
	var wherechanged=(document.vform.where.value!=vwhere)&&pwhere&&!nochange;
	if(wherechanged) {
		where=pwhere;
		document.yp.pa.value=where;
		document.yp.b.value=0;
	}
	var what=document.yp.go.value;
	var whatchanged=(document.vform.what.value!=vwhat)&&!nochange;
	if(whatchanged) {
		what=processWhat(document.vform.what.value);
		document.yp.go.value=what;
		if(document.yp.s.value==-3) document.yp.s.value=-7;
	}
	if(wherechanged||whatchanged) {
		setKey("filt",""); setKey("head",""); setKey("imp",""); setKey("alpha",""); setKey("city",""); setPage(0);
		boxbounds=null;
	}
	if(boxbounds) {
		setKey("head","");
		u="/sys/pageserver.dll?pa=latlong&s=-8&y="+latlongy+"&x="+latlongx+"&go="+encodeURIComponent(document.yp.go.value)+"&k=";
		u+=encodeURIComponent("part:results;box:"+boxbounds);
		if(userlat) u+=encodeURIComponent(";lat:"+Math.floor(userlat*1e6)+";lon:"+Math.floor(userlong*1e6));
		var k=document.yp.k.value;
		if(k && k.length>0) u+=encodeURIComponent(";"+k);
		doingBoundsSearch=true;
		//alert(u)
		document.getElementById("requestdiv").innerHTML="<iframe src=\""+u+"\" width=800 height=300></iframe>";
		document.body.style.cursor="wait";
		setTimeout("doingBoundsSearch=false;",2000);
	} else if(seourl) {
		var w=what;
		var pg=document.yp.p.value;
		if(pg==0 || document.yp.s.value==-7) pg=""; else pg="/"+pg;
		if(w.length) w="/"+encodeURIComponent(w)+pg+viewPath()+keyPath();
		else if(document.yp.s.value==-7) w=(page?"/"+page:"/-")+viewPath()+keyPath();
		else w="/-"+viewPath()+keyPath();
		location.href="/"+where+sectionPath+w;
	} else document.yp.submit();
	return false;
}

function goalt(s) { document.vform.what.value=s; dogo(); }

function spopad(q,i,w,h){
	w+=25;h+=45;sh=screen.availHeight-25;if(sh>=h) str="width="+w+",height="+h;else str="width="+(w+25)+",height="+sh+",screenY="+screen.availTop+",scrollbars";window.open("pageserver.dll?b="+q+"&f=pw"+i,"",str);
}

function resized()
{
	if(profile || bookView || listView) return;
	var wh=getWindowHeight()-footerHeight,ww=getWindowWidth();
	var lw=Math.floor(250+ww/10);
	var el=document.getElementById("listings");
	if(el) {
		el.style.height=(wh-el.offsetTop)+"px";
		el.style.width=lw+"px";
		setCookie("listht",wh-el.offsetTop);
		setCookie("listwd",lw);
	}
	var bht=0;
	var bel=document.getElementById("bannerdiv");
	if(bel) bht=bel.offsetHeight;
	el=document.getElementById("mapdiv");
	if(el) {
		el.style.height=(wh-el.offsetTop-bht)+"px";
		el.style.left=lw+"px";
		el.style.width=(ww-lw)+"px";
		setCookie("mapht",wh-el.offsetTop-bht);
		setCookie("mapwd",ww-lw);
	}
	el=document.getElementById("mleftshad");
	if(el) el.style.left=lw+"px";
	if(bel) bel.style.left=lw+"px";
}

function doscroll()
{
	if(!bookView) return;
	var g=document.getElementsByName("0");
	if(g&&g.length>0) {
	    var n=g[0];
	    var t=0;
	    if(n.style.top && n.style.top.toString().length) t=parseInt(n.style.top);
	    var y=t?t:n.offsetTop;
	    while(n.offsetParent && n.offsetParent != document.body) {
	      n=n.offsetParent;
	      t=0;
	      if(n.style.top && n.style.top.toString().length) t=parseInt(n.style.top);
	      y+=t?t:n.offsetTop;
	    }
	    var wh=window.innerHeight?window.innerHeight:(document.documentElement&&document.documentElement.clientHeight?document.documentElement.clientHeight:document.body.clientHeight);
	    y=y+600-wh; if(y<0) y=0;
	    //if(y>  -wh) y=  -wh;
	    if(y>0) window.scrollTo(0,y);
	}
}

var curlist=-1;
function listover(i)
{
	if(curlist==i) return;
	var el=document.getElementById("list"+i);
	if(el) {
		var c=el.className;
		if(c.indexOf("over")<0) {
			var s=c.indexOf(" ");
			el.className=c+" "+c.substr(s+1)+"over";
		}
	}
	if(addressData[i]) {
		var lc=addressData[i].length-1;
		for(var j=0;j<lc;j++) {
			el=document.getElementById("lmicon"+i+"_"+j);
			if(el) el.src=mapImgPath+"nopin_on.png";
		}
	}
	if(curlist!=-1) listout(curlist);
	curlist=i;
	markerHilite(i,1);
}

function listout(i)
{
	var el=document.getElementById("list"+i);
	if(el) {
		var c=el.className;
		if(c.indexOf("over")>0) {
			var s=c.lastIndexOf(" ");
			el.className=c.substr(0,s);
		}
	}
	if(addressData[i]) {
		var lc=addressData[i].length-1;
		for(var j=0;j<lc;j++) {
			el=document.getElementById("lmicon"+i+"_"+j);
			if(el) el.src=mapImgPath+"nopin.png";
		}
	}
	setTimeout("if(curlist!="+curlist+") do_out("+curlist+");",1);
	curlist=-1;
}

function do_out(i)
{
	markerHilite(i,0);
}

function locexpand(i)
{
	var el=document.getElementById("locexpd"+i);
	if(!el) return;
	if(el.style.display=="none") {
		el.style.display="block";
		document.getElementById("locexpi"+i).src="/sys/images/ls/minus.gif";
		if(isIE&&profile) setTimeout(function(){el.style.display="none";el.style.display="block";},1);
	} else {
		el.style.display="none";
		document.getElementById("locexpi"+i).src="/sys/images/ls/plus.gif";
		showListMarkers();
	}
}

function listscrolled()
{
	if(bookView||profile) return;
	if(typeof nextpage!='undefined' && nextpage) {
		var el=document.getElementById("morelist"+nextpage);
		if(el) {
			if(!el.loadmsg) el.innerHTML="<div class=moreloading>Loading more listings, please wait...</div>";
			else el.loadmsg=true;
		}
		el=document.getElementById("listings");
		if(listView) {
			var y=getPos(el).y;
			var oh=el.offsetHeight;
			var wh=getWindowHeight();
			var wy=document.body.scrollTop;
			if(wy+wh>y+oh-50) loadPage(nextpage);
		} else {
			var y=el.scrollTop;
			var oh=el.offsetHeight;
			var sh=el.scrollHeight;
			if(y+oh>sh-40) loadPage(nextpage);
		}
	}
	if(listView) {
		var el=document.getElementById("mapcol");
		y=getPos(el).y-document.body.scrollTop-10;
		mapcolbot=el.offsetHeight+getPos(el).y;
		listbot=document.getElementById("listings").offsetHeight+getPos(document.getElementById("listings")).y;
		mapcolbot=mapcolbot-parseInt(el.style.paddingTop)-y;
		if(mapcolbot>listbot) y+=mapcolbot-listbot;
		if(y<0) el.style.paddingTop=-y;
		else el.style.paddingTop=0;
	}
	showListMarkers();
}

var loadingpage=null;
var latlongx=null,latlongy=null,boxbounds=null;
function loadPage(n)
{
	if(loadingpage==n || profile) return;
	var u;
	if(boxbounds) {
		u="/sys/pageserver.dll?pa=latlong&y="+latlongy+"&x="+latlongx+"&go="+encodeURIComponent(document.yp.go.value)+"&p="+n+"&k="+encodeURIComponent("box:"+boxbounds+";");
		if(userlat) u+=encodeURIComponent("lat:"+Math.floor(userlat*1e6)+";lon:"+Math.floor(userlong*1e6))+";";
	} else if(seourl) {
		u="/"+document.yp.pa.value+sectionPath+"/"+encodeURIComponent(document.yp.go.value)+"/"+n+viewPath()+"/k";
	} else {
		u="/sys/pageserver.dll?b="+document.yp.b.value+"&pa="+document.yp.pa.value+"&go="+encodeURIComponent(document.yp.go.value)+"&s=-8&p="+n+"&k=";
	}
	u+=encodeURIComponent("part:list;mlet:"+curletter);
	var k=document.yp.k.value;
	if(k && k.length>0) u+=encodeURIComponent(";"+k);
	loadingpage=n;
	document.getElementById("requestdiv").innerHTML="<iframe src=\""+u+"\" width=800 height=300></iframe>";
	document.body.style.cursor="wait";
}

function pageLoaded(w)
{
	document.body.style.cursor="";
	if(!loadingpage || loadingpage!=nextpage) return;
	if(!w) return;
	var el=w.document.getElementById("listings");
	if(!el) return;
	var mel=document.getElementById("morelist"+(w.page));
	if(!mel) return;
	mel.innerHTML=el.innerHTML;
	curletter=w.curletter;
	nextpage=w.nextpage;
	addressData=addressData.concat(w.addressData);
	ratelist=w.ratelist;
	document.getElementById("requestdiv").innerHTML="";
	addListMarkers(loadingpage*pageSize);
	loadRatings(loadingpage*pageSize);
	loadingpage=null;
}

var weatherscript="/sys/scripts/ls/weather.htm";

function resultsLoaded(w)
{
	document.body.style.cursor="";
	if(!w) return;
	var el=w.document.getElementById("listings");
	if(!el) return;
	var lel=document.getElementById("listings");
	if(!lel) return;
	document.body.className=w.branded?"dobrand":"";
	lel.scrollTop=0;
	lel.innerHTML=el.innerHTML;
	el=document.getElementById("refbar");
	if(el) el.innerHTML=w.document.getElementById("refbar").innerHTML;
	curletter=w.curletter;
	nextpage=w.nextpage;
	pubid=w.pubid;
	vwhere=w.cities[0];
	if(!vwhere) vwhere="";
	el=document.getElementById("sres");
	if(el) el.innerHTML="Your search for&nbsp;<h1"+((vwhat+vwhere).length>60?" style='font-size:14px'":"")+">"+vwhat+" <span style='font-weight:normal;color:black;font-size:14px'>in</span> "+vwhere+"</h1>&nbsp;returned "+(w.lcount?"<b>"+w.lcount+"</b>":"no")+" listing"+(w.lcount==1?"":"s");
	el=document.getElementById("wherelabel");
	if(el) {
		el.innerHTML=vwhere;
		el.style.fontSize=vwhere.length>22?"15px":"";
	}
	document.vform.where.value=vwhere;
	latlongx=w.latlongx;
	latlongy=w.latlongy;
	boxbounds=w.boxbounds;
	document.yp.pa.value=vwhere.replace(", ",",").replace(" ","-");
	u=weatherscript+"?";
	for(i=0;i<w.cities.length;i++) {
		u+=encodeURIComponent("\""+w.cities[i]+"\""+(i<w.cities.length-1?",":""));
	}
	el=document.getElementById("weather");
	if(el) el.src=u;
	listMap.clearOverlays();
	listMap.addOverlay(umarker);
	delete addressData;
	addressData=w.addressData;
	ratelist=w.ratelist;
	if(typeof w.fcount=="undefined") fcount=0; else fcount=w.fcount;
	if(typeof w.fitemct=="undefined") fitemct=0; else fitemct=w.fitemct;
	el=w.document.getElementById("bannerdiv");
	lel=document.getElementById("bannerdiv");
	if(el) {
		if(lel) lel.innerHTML=el.innerHTML;
		else {
			lel=document.createElement("div");
			lel.setAttribute("id","bannerdiv");
			lel.innerHTML=el.innerHTML;
			document.body.appendChild(lel);
		}
	} else {
		if(lel) lel.parentNode.removeChild(lel);
	}
	if(el||lel) setTimeout(resized,10);
	document.getElementById("requestdiv").innerHTML="";
	showingStart=10000,showingEnd=0;
	addListMarkers(0);
	loadRatings();
}

var listMap=null;
var micon=[0,0],mdot=0,hicon=0;
var umarker=null;
var mlaboff=null;
var movebounds=null;
var geocoder=null;
var profileMapAlways=false;
function createMap()
{
	if(listMap || (profile && !addressData.length && !profileMapAlways)) return;
	listMap=new GMap2(document.getElementById("mapdiv"));
	listMap.addControl(profile?new GSmallMapControl():new GLargeMapControl(),new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(6,6)));
	listMap.addControl(new GScaleControl());
	if(!profile) listMap.addControl(new GMapTypeControl());
	if(!profile && !listView) listMap.addControl(new GOverviewMapControl(new GSize(140,100)));	
	//listMap.setCenter(new GLatLng(0,-30),10);

	var clat=(latN+latS)/2,clong=(longE+longW)/2;
	var slat=(latN-latS)/2,slong=(longE-longW)/2;
	slat*=0.8; slong*=0.8;

	var bounds=new GLatLngBounds();
	var centerloc=null;
	var cornerdist=0;
	if(clat) {
		centerloc=new GLatLng(clat,clong);
		var cloc=new GLatLng(clat-slat,clong-slong)
		cornerdist=cloc.distanceFrom(centerloc);
		bounds.extend(cloc);
		bounds.extend(new GLatLng(clat+slat,clong+slong));
	}
	var userloc=null;
	if(userlat) {
		userloc=new GLatLng(userlat,userlong);
		var udist=0;
		if(centerloc) udist=userloc.distanceFrom(centerloc);
		if(!cornerdist || udist<cornerdist*1.5 || udist<2000) bounds.extend(userloc);
	}
	
	if(!bounds.isEmpty()) {
		var lev=listMap.getBoundsZoomLevel(bounds);
		if(lev>14) lev=14;
		listMap.setCenter(bounds.getCenter(),lev);
		listMap.savePosition();
		setMoveBounds();
	}
	else listMap.setCenter(new GLatLng(0,-30),10);
	
	for(var i=0;i<2;i++) {
		micon[i] = new GIcon();
		micon[i].image = mapImgPath+"pin"+(["","_on"][i])+".png";
		micon[i].iconSize = new GSize(34, 21);
		micon[i].iconAnchor = new GPoint(0, 20);
		micon[i].infoWindowAnchor = new GPoint(27, 8);
		micon[i].shadow = mapImgPath+"pin_shadow.png";
		micon[i].shadowSize = new GSize(40,28);
	}

	mdot = new GIcon();
	mdot.image = mapImgPath+"mdot10.png";
	mdot.iconSize = new GSize(10, 10);
	mdot.iconAnchor = new GPoint(4, 5);
	mdot.infoWindowAnchor = new GPoint(6, 6);
	mdot.shadow = mapImgPath+"mdot10_shadow.png";
	mdot.shadowSize = new GSize(13,14);
	
	hicon = new GIcon();
	hicon.image = mapImgPath+"nopin_home.png";
	hicon.iconSize = new GSize(32, 21);
	hicon.iconAnchor = new GPoint(15, 10);
	hicon.infoWindowAnchor = new GPoint(25, 8);
	hicon.shadow = mapImgPath+"nopin_shadow.png";
	hicon.shadowSize = new GSize(38,28);

	umarker=new GMarker(userloc,{"icon":hicon,"zIndexProcess":markerZIndex,"draggable":true});
	GEvent.bind(umarker,"click",null,umarkerClick);
	GEvent.bind(umarker,"dragend",null,userDragged);
	listMap.addOverlay(umarker);

	mlaboff=new GSize(2,-17);

	addListMarkers(0);
	
	GEvent.bind(listMap,"moveend",null,mapmoved);
	GEvent.bind(listMap,"zoomend",null,mapzoomed);
}

function setMoveBounds()
{
	var f=0.25;
	movebounds=listMap.getBounds();
	var nlat=movebounds.getNorthEast().lat(),slat=movebounds.getSouthWest().lat();
	var elong=movebounds.getNorthEast().lng(),wlong=movebounds.getSouthWest().lng();
	movebounds=new GLatLngBounds(new GLatLng(nlat*f+slat*(1-f),elong*f+wlong*(1-f)),new GLatLng(nlat*(1-f)+slat*f,elong*(1-f)+wlong*f));
}

var mapPanSearch=true;

function mapmoved()
{
	if(!mapPanSearch || profile || listView) return;
	if(!listMap.getBounds().containsBounds(movebounds)) setTimeout(boundsSearch,10);
}

function mapzoomed(z1,z2)
{
	if(profile || listView) return;
	if(z1!=z2) setTimeout(boundsSearch,10);
	else mapmoved();
}

var rgto=null;
function userDragged(pos)
{
	userlat=pos.lat();
	userlong=pos.lng();
	setCookie("useraddr",vwhere);
	setCookie("userlat",Math.floor(userlat*1e6));
	setCookie("userlon",Math.floor(userlong*1e6));
	if(!geocoder) geocoder=new GClientGeocoder();
	rgto=setTimeout(rgTimeOut,1000);
	geocoder.getLocations(pos,rgGeoCallback);
}

function rgGeoCallback(r)
{
	if(!rgto) return;
	clearTimeout(rgto);
	rgto=null;
	if(r.Status.code==200) {
		var a=r.Placemark[0].address;
		if(a.substr(a.length-5)==", USA") a=a.substr(0,a.length-5);
		setCookie("useraddr",a);
	}
	boundsSearch();
}

function rgTimeOut()
{
	rgto=null;
	boundsSearch();
}

var doingBoundsSearch=false;
function boundsSearch()
{
	if(profile || listView || doingBoundsSearch) return;
	setKey("filt",""); setKey("head",""); setKey("alpha",""); setKey("city",""); setKey("asec",""); setPage(0);
	var b=listMap.getBounds();
	var nlat=b.getNorthEast().lat(),slat=b.getSouthWest().lat();
	var elong=b.getNorthEast().lng(),wlong=b.getSouthWest().lng();
	u="/sys/pageserver.dll?pa=latlong&s=-8&y="+Math.floor((nlat+slat)*500000)+"&x="+Math.floor((elong+wlong)*500000)+"&go="+encodeURIComponent(document.yp.go.value)+"&k=";
	u+=encodeURIComponent("part:results;box:"+Math.floor(slat*1e6)+","+Math.floor(wlong*1e6)+","+Math.floor(nlat*1e6)+","+Math.floor(elong*1e6));
	if(userlat) u+=encodeURIComponent(";lat:"+Math.floor(userlat*1e6)+";lon:"+Math.floor(userlong*1e6));
	var k=document.yp.k.value;
	if(k && k.length>0) u+=encodeURIComponent(";"+k);
	doingBoundsSearch=true;
	//alert(u)
	document.getElementById("requestdiv").innerHTML="<iframe src=\""+u+"\" width=800 height=300></iframe>";
	document.body.style.cursor="wait";
	setTimeout("doingBoundsSearch=false;",2000);
	setMoveBounds();
}

function addListMarkers(n)
{
	var setBounds=(getKey("asec")=="1" && !n);
	var bounds=setBounds?new GLatLngBounds():0;
	var userloc=(setBounds&&userlat)?new GLatLng(userlat,userlong):0;
	var l=addressData.length;
	for(var i=n;i<l;i++) {
		if(!addressData[i]) continue;
		var lc=addressData[i].length-1;
		for(var j=1;j<=lc;j++) {
			var g=new GLatLng(addressData[i][j][0],addressData[i][j][1]);
			addressData[i][j].geo=g;
			var m=new GMarker(g,{"icon":mdot,"zIndexProcess":markerZIndex});
			addressData[i][j].dot=m;
			m.ilist=i;
			m.iloc=j-1;
			m.dot=true;
			GEvent.bind(m, "click", {"marker":m}, markerClick);
			listMap.addOverlay(m);
			if(setBounds) {
				if(!userloc || userloc.distanceFrom(g)<100000) bounds.extend(g);
			}
		}
	}
	setTimeout(showListMarkers,100);
	
	if(setBounds) {
		if(userloc) {
			var udist=bounds.isEmpty()?0:bounds.getCenter().distanceFrom(userloc);
			if(udist<50000) bounds.extend(userloc);
		}
		if(!bounds.isEmpty()) {
			var lev=listMap.getBoundsZoomLevel(bounds);
			if(lev>14) lev=14;
			listMap.setCenter(bounds.getCenter(),lev);
			listMap.savePosition();
		}
	}
}

var showingStart=10000,showingEnd=0;
function showListMarkers()
{
	if(!addressData.length) return;
	var y=0;
	var oh=1;
	var sh=1;
	if(listView) {
		var el=document.getElementById("listings");
		y=document.body.scrollTop-getPos(el).y;
		oh=getWindowHeight();
		if(y<0) { oh+=y; y=0; }
		sh=el.scrollHeight;
	} else
	if(!profile) {
		var el=document.getElementById("listings");
		y=el.scrollTop;
		oh=el.offsetHeight;
		sh=el.scrollHeight;
	}
	var i=Math.floor(addressData.length*y/sh);
	if(i>=addressData.length) i=addressData.length;
	if(i>showingStart) i=showingStart;
	while(i>0 && getListPos(i)>y) i--;
	var nss=10000,nse=10000;
	for(;i<addressData.length;i++) {
		var ly=sh;
		if(i<addressData.length-1) ly=getListPos(i+1);
		if(ly<y && i<showingStart) continue;
		if(addressData[i]) {
			var lc=addressData[i].length-1;
			if((i<showingStart || i>showingEnd) && ly>=y && i<=nse) {	// turn on
				for(var j=1;j<=lc;j++) {
					if(!addressData[i][j].marker) {
						var o={"icon":micon[0],"clickable":true,"labelText":addressData[i][0]+(j>1?j-1:""),"labelOffset":mlaboff,"labelClass":"miconlab","zIndexProcess":markerZIndex};
						var m=new LabeledMarker(addressData[i][j].geo,o);
						addressData[i][j].marker=m;
						m.ilist=i;
						m.iloc=j-1;
						m.dot=false;
						m.infoOpen=false;
						m.hilited=0;
						GEvent.bind(m, "click", {"marker":m}, markerClick);
						GEvent.bind(m, "mouseover", {"marker":m}, markerOver);
						GEvent.bind(m, "mouseout", {"marker":m}, markerOut);
						GEvent.bind(m, "infowindowopen", {"marker":m}, markerInfoOpen);
						GEvent.bind(m, "infowindowclose", {"marker":m}, markerInfoClose);
					}
					listMap.addOverlay(addressData[i][j].marker);
					if(addressData[i][j].dot) listMap.removeOverlay(addressData[i][j].dot);
				}
			}
			else if((ly<y||i>nse) && i>=showingStart && i<=showingEnd) {	// turn off
				for(var j=1;j<=lc;j++) {
					if(addressData[i][j].dot) listMap.addOverlay(addressData[i][j].dot);
					if(addressData[i][j].marker) listMap.removeOverlay(addressData[i][j].marker);
				}
			}
			if(ly>=y && nss==10000) nss=i;
		}
		if(ly>=y+oh && nse==10000) nse=i;
		if(i>=nse && i>=showingEnd) break;
	}
	showingStart=nss;
	showingEnd=nse;
}

function getListPos(i)
{
	if(profile) return 0;
	var py=0;
	var el=document.getElementById("list"+i);
	var lel=document.getElementById("listings");
	if(!el) return 0;
	while(el && el!=lel) {
		py+=el.offsetTop;
		el=el.offsetParent;
	}
	return py;
}

function markerZIndex(m)
{
	var g=m.getLatLng();
	var z=parseInt((g.lat()*5+g.lng())*-1000000);
	if(m==umarker) return z;
	z-=m.ilist*20+m.iloc*2;
	if(m.dot) z-=10000000;
	if(m.ilist==curlist) z+=5000000;
	return z;
}

function markerHilite(i,o)
{
	if(i>=addressData.length) return;
	if(i<showingStart || i>showingEnd) return;
	if(!addressData[i]) return;
	var lc=addressData[i].length-1;
	for(var j=1;j<=lc;j++) {
		var m=addressData[i][j].marker;
		if(!m) continue;
		if(m.hilited==o) continue;
		m.hilited=o;
		if(!m.infoOpen) {
			listMap.removeOverlay(m);
			listMap.addOverlay(m);
		}
		m.setImage(micon[o].image);
	}
}

var mpsto=null;

function markerClick(i,l)
{
	var m=this.marker;
	if(m) { i=m.ilist; l=m.iloc; }
	else m=addressData[i][l+1].marker;
	if(!m) m=addressData[i][l+1].dot;
	var el=document.getElementById(profile?"proname":"lname"+i);
	var html="<div class=mapinfo "+(showsview?"style='width:320px'":"")+"><div class=miname>"+el.innerHTML+"</div>";
	el=document.getElementById("ltbl"+i+"_"+l);
	var h=el.innerHTML;
	var a=h.split("</tr><tr>"); if(a.length==1) a=h.split("</TR><TR>");
	for(j=0;j<a.length;j++) {
		var p1=a[j].lastIndexOf("<td"); if(p1<0) p1=a[j].lastIndexOf("<TD");
		var p2=a[j].lastIndexOf("</td>"); if(p2<0) p2=a[j].lastIndexOf("</TD>");
		if(p1>0&&p2>p1) {
			a[j]=a[j].substr(0,p1)+a[j].substr(p2+5);
		}
	}
	h=a.join("</tr><tr>");
	html+="<table style='width:100%' cellpadding=0 cellspacing=0 border=0>"+h+"</table>";
	if(h.indexOf("ddir(")<0) html+="<div id=mddlink><a href='javascript:void ddir("+i+","+l+")'>Get Driving Directions</a>"
	if(useStreetView) {
		if(profile) setTimeout("streetview2("+i+","+l+")",100);
		else if(!showsview) html+="<br><a href='javascript:void streetview("+i+","+l+")'>Street View</a>";
	}
	el=document.getElementById("ficons"+i);
	if(el) html+="<div class=mficons>"+el.innerHTML+"</div>";
	html+="</div>";
	if(showsview) { html+="<br><br><div id=streetview style='width:320px;height:220px;position:relative'></div>"; showsview=false; setTimeout("streetview2("+i+","+l+")",100); }
	html+="</div>";
	mapPanSearch=false;
	if(mpsto) clearTimeout(mpsto);
	mpsto=setTimeout("mapPanSearch=true;mpsto=null",2000);
	m.openInfoWindowHtml(html);
}

var useStreetView=false;	// enable the feature
var showsview=false;
var showingstreetview=null;

function streetview(i,l)
{
	showsview=true;
	setTimeout("markerClick("+i+","+l+")",10);
}

function streetview2(i,l)
{
	if(profile && showingstreetview==i+","+l) return;
	showingstreetview=i+","+l;
	var g=addressData[i][l+1].geo;
	var el=document.getElementById("streetview");
	if(!el) return;
	el.innerHTML="<div id=nosvlabel style='display:none;text-align:center;color:#888;position:absolute;top:80px;width:"+el.clientWidth+"px;height:50px'>No street view available<br>at this location</div>";
	setTimeout("document.getElementById('nosvlabel').style.display='block'",1000);
	new GStreetviewPanorama(document.getElementById("streetview"),{latlng:g,features:{userPhotos:false}});
}

function umarkerClick()
{
	var a=getCookie("useraddr");
	if(a=="") a=vwhere;
	var h="<div id=mapuser><b>My Location</b><br><input type=text id=muloc value=\""+a+"\" onselectstart='event.cancelBubble=true' onfocus='mufocus()' onkeypress=\"return event.keyCode==13?muenter():true\" onblur='muenter(true)'><div id=muins>Enter address or drag marker to change location</div></div>";
	umarker.openInfoWindowHtml(h);
}

function mufocus()
{
	var el=document.getElementById('muloc');
	var a=el.value;
	if(a==vwhere || a==" "+vwhere) {
		el.value=" "+vwhere;
		setTimeout(function(){setCursorPos(el,0);},10);
	}
	else setTimeout(function(){el.select()},10);
}

var muIsBlur=false;
function muenter(isBlur)
{
	var el=document.getElementById('muloc');
	var a=el.value;
	if(a.length<5) { if(!isBlur) { alert("Please enter an address"); el.focus(); el.select(); } return false; }
	if(a==getCookie("useraddr")) return false;
	if(!geocoder) geocoder=new GClientGeocoder();
	muIsBlur=isBlur||false;
	geocoder.getLocations(a,muGeoCallback);
	return false;
}

function muGeoCallback(r)
{
	var el=document.getElementById('muloc');
	if(!el) return;
	var a=el.value;
	if(r.Status.code==200) {
		var pos=r.Placemark[0].Point.coordinates;
		userlat=pos[1];
		userlong=pos[0];
		setCookie("useraddr",a);
		setCookie("userlat",Math.floor(pos[1]*1e6));
		setCookie("userlon",Math.floor(pos[0]*1e6));
		var loc=new GLatLng(pos[1],pos[0]);
		umarker.setLatLng(loc);
		var b=listMap.getBounds();
		if(!b.containsLatLng(loc)) {
			if(profile) {
				b.extend(loc);
				var lev=listMap.getBoundsZoomLevel(b);
				if(lev>14) lev=14;
				listMap.setCenter(b.getCenter(),lev);
			}
			else listMap.panTo(loc);
			setTimeout(boundsSearch,1000);
		}
		else setTimeout(boundsSearch,10);
		umarker.closeInfoWindow();
	} else {
		alert("The location \""+a+"\" was not found");
		if(!muIsBlur) { el.focus(); el.select(); }
	}
}

function setCursorPos(el,pos)
{
	if(el.setSelectionRange) {
		el.setSelectionRange(pos,pos);
	} else if(el.createTextRange) {
		var range=el.createTextRange();
		range.move('character',pos);
		range.select();
	}
}

function ddir(i,l)
{
	var saddr=getCookie("useraddr");
	if(!saddr) saddr=vwhere;
	saddr+=" @"+userlat+","+userlong;
	var el=document.getElementById("ltbl"+i+"_"+l);
	var h=el.innerHTML;
	var a=h.split("</td>"); if(a.length==1) a=h.split("</TD>");
	h=a[0].replace("<br>"," ").replace("<BR>"," ").replace("<br />"," ").replace("<BR />"," ");
	var daddr=h.substr(h.lastIndexOf(">")+1);
	daddr+=" @"+addressData[i][l+1][0]+","+addressData[i][l+1][1];
	window.open("http://maps.google.com/?saddr="+escape(saddr)+"&daddr="+escape(daddr),"Directions","titlebar=no,status=no,toolbar=no,menubar=no,resizable=yes");
}

function markerOver()
{
	var i=this.marker.ilist;
	if(i==curlist) return;
	listover(i);
}

function markerOut()
{
	var i=this.marker.ilist;
	listout(i);
}

function markerInfoOpen()
{
	this.marker.infoOpen=true;
	setTimeout("listover("+this.marker.ilist+")",1);
}

function markerInfoClose()
{
	this.marker.infoOpen=false;
}

function lmiclick(i,l)
{
	markerClick(i,l);
}

var textImp=0,textSec=0;
function textit() {
	var num=document.getElementById("tnum").value;
	var d=0;
	for(i=0;i<num.length;i++) { c=num.substr(i,1); if(c>="0" && c<="9") d++; }
	if(d<10) { alert("Please enter a phone number with area code."); return; }
	var el=document.getElementById("tserv");
	var p=el.options[el.selectedIndex].value;
	if(p.length<2) { alert("Please select a cell phone service provider"); return; }
	var url="/sys/pageserver.dll?b="+textSec+"&f=tid"+textImp+"&go="+escape(num+"@"+p);
	document.getElementById("txtimg").src=url;
	setCookie("textnumber",num);
	setCookie("textprovider",p);
	setTimeout("document.getElementById('tsent').style.display=''",500);
	setTimeout("texthide()",2500);
}

var txtset=false;
function setsend() {
	if(txtset) return;
	txtset=true;
	document.getElementById("tnum").value=getCookie("textnumber");
	var p=getCookie("textprovider");
	var el=document.getElementById("tserv");
	for(i=2;i<el.options.length;i++) {
		if(el.options[i].value==p) { el.options[i].selected=true; break; }
	}
}

function openReview(pub,n,p)
{
	window.open("http://www.localscout.com/ratings/writeratingreview.aspx?pubid="+pub+"&name="+n+"&phone="+p,"","width=600,height=600,resizable=1,scrollbars=1");
}

function hid(n,sid,nm){
	if(!sid) { document.yp.go.value="hid"+n; dogo(); }
	else with(document.yp) { b.value=sid; go.value=''; f.value="hid"+n; p.value=0; submit(); }
}

function hi(n){
	with(document.yp) { if(pa.value!="" && pa.value!="0") b.value=0; go.value=''; p.value=0; f.value="hi"+n; submit(); }
}

function hh(q,n){
	if(document.yp.pa.value.length) {
		var z=""; if(document.yp.z) { document.yp.z.value; if(z.length && parseInt(z)!=1000) z="/z"+z; else z=""; }
		location.href="/"+document.yp.pa.value+"/hh"+n+z;
	} else with(document.yp) {b.value=q;go.value="";f.value="hh"+n;s.value=0;submit();}
}

var addthis_pub="informationpages";
var addthis_hover_delay = 400;
var addthis_header_color = "#ffffff";
var addthis_header_background = "#cc1010";

var curadthumb=0;
function showadthumb(n)
{
	document.getElementById("proad"+curadthumb).style.display="none";
	document.getElementById("proad"+n).style.display="block";
	curadthumb=n;
}

function showad(n,path,w,h)
{
	var el=document.getElementById("proadi"+n);
	if(!el) return;
	var tw=el.clientWidth,th=el.clientHeight;
	var tpos=getPos(el);
	var x=Math.floor((getWindowWidth()-w)/2);
	var y=Math.floor((getWindowHeight()-h)/2);
	if(document.body.scrollTop) y+=document.body.scrollTop;
	if(y<10) y=10;
	var iel=document.getElementById("showadimg");
	if(!iel) return;
	iel.src=path;
	iel.style.width=tw+"px";
	iel.style.height=th+"px";
	iel.style.left=tpos.x+"px";
	iel.style.top=tpos.y+"px";
	iel.startx=tpos.x;
	iel.endx=x;
	iel.starty=tpos.y;
	iel.endy=y;
	iel.startw=tw;
	iel.endw=w;
	iel.starth=th;
	iel.endh=h;
	iel.stime=new Date().getTime();
	iel.duration=500;
	iel.direction=1;
	iel.timer=setInterval(function(){showadanim(iel)},15);
}

function showadanim(iel)
{
	var ctime=new Date().getTime()-iel.stime;
	var frac=ctime/iel.duration;
	if(frac>1) frac=1;
	if(iel.direction<0) frac=1-frac;
	if(frac<0.5) frac=(frac*frac*2);
	else frac=1-((1-frac)*(1-frac)*2);
	iel.style.left=Math.floor(iel.startx*(1-frac)+iel.endx*frac)+"px";
	iel.style.top=Math.floor(iel.starty*(1-frac)+iel.endy*frac)+"px";
	frac=Math.pow(frac,1.4);
	iel.style.width=Math.floor(iel.startw*(1-frac)+iel.endw*frac)+"px";
	iel.style.height=Math.floor(iel.starth*(1-frac)+iel.endh*frac)+"px";
	if(frac>=1 && iel.direction>0) { clearInterval(iel.timer); iel.timer=null; }
	if(frac<=0 && iel.direction<0) {
		clearInterval(iel.timer); iel.timer=null;
		iel.src="clr.gif";
		iel.style.width="1px";
		iel.style.height="1px";
		iel.style.left="-1000px";
		iel.style.top="0px";
	}
}

function hidead()
{
	var iel=document.getElementById("showadimg");
	if(iel.timer) return;
	iel.direction=-1;
	iel.stime=new Date().getTime();
	iel.timer=setInterval(function(){showadanim(iel)},15);
}

function popad(i,w,h){w+=25;h+=45;sh=screen.availHeight-25;if(sh>=h) str="width="+w+",height="+h;else str="width="+(w+25)+",height="+sh+",screenY="+screen.availTop+",scrollbars";window.open("pageserver.dll?b="+sec+"&f=pw"+i,"",str);}

function map(name,addr,city,st,zip,geo)
{
a=addr;if(a.length) a+=", ";a+=city;if(st.length) a+=", "+st;if(zip.length) a+=" "+zip;
u="http://www.informationpages.com/sys/gmap.htm?addr="+escape(a)+"&title="+escape(name);
if(geo&&geo.length) u+="&geo="+escape(geo);
window.open(u,"Map","width=550,height=580,status=no");
}

function setgo(h,sid)
{
	with(document.yp) { b.value=sid; go.value=h; f.value=""; p.value=""; submit(); }
}

function bookmarkPage(title,url)
{
	if(!url) url=document.location.href;
	if(window.sidebar) window.sidebar.addPanel(title, url, "");	// Firefox
	else if(window.opera && window.print){	// Opera
	    var e=document.createElement('a');
	    e.setAttribute('href',url);
	    e.setAttribute('title',title);
	    e.setAttribute('rel','sidebar');
	    e.click();
	}
	else if(window.external && document.all) window.external.AddFavorite(url,title);	// IE
	else alert("Please press Ctrl-D to add a bookmark");
}

/*
* LabeledMarker Class
*
* Copyright 2007 Mike Purvis (http://uwmike.com)
* 
* 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 extends the Maps API's standard GMarker class with the ability
* to support markers with textual labels. Please see articles here:
*
*       http://googlemapsbook.com/2007/01/22/extending-gmarker/
*       http://googlemapsbook.com/2007/03/06/clickable-labeledmarker/
*/

/* Constructor */
function LabeledMarker(latlng, options){
    this.latlng = latlng;
    this.labelText = options.labelText || "";
    this.labelClass = options.labelClass || "markerLabel";
    this.labelOffset = options.labelOffset || new GSize(0, 0);
    
    this.clickable = options.clickable || true;
    
    if (options.draggable) {
    	// This version of LabeledMarker doesn't support dragging.
    	options.draggable = false;
    }
    
    GMarker.apply(this, arguments);
}


/* It's a limitation of JavaScript inheritance that we can't conveniently
   extend GMarker without having to run its constructor. In order for the
   constructor to run, it requires some dummy GLatLng. */
LabeledMarker.prototype = new GMarker(new GLatLng(0, 0));


// Creates the text div that goes over the marker.
LabeledMarker.prototype.initialize = function(map) {
	// Do the GMarker constructor first.
	GMarker.prototype.initialize.apply(this, arguments);
	
	var div = document.createElement("div");
	div.className = this.labelClass;
	div.innerHTML = this.labelText;
	div.style.position = "absolute";
	map.getPane(G_MAP_MARKER_PANE).appendChild(div);

	if (this.clickable) {
		// Pass through events fired on the text div to the marker.
		var eventPassthrus = ['click', 'dblclick', 'mousedown', 'mouseup', 'mouseover', 'mouseout'];
		for(var i = 0; i < eventPassthrus.length; i++) {
			var name = eventPassthrus[i];
			GEvent.addDomListener(div, name, newEventPassthru(this, name));
		}

		// Mouseover behaviour for the cursor.
		div.style.cursor = "pointer";
	}
	
	this.map = map;
	this.div = div;
}

function newEventPassthru(obj, event) {
	return function() { 
		GEvent.trigger(obj, event);
	};
}

// Redraw the rectangle based on the current projection and zoom level
LabeledMarker.prototype.redraw = function(force) {
	GMarker.prototype.redraw.apply(this, arguments);
	
	// We only need to do anything if the coordinate system has changed
	if (!force) return;
	
	// Calculate the DIV coordinates of two opposite corners of our bounds to
	// get the size and position of our rectangle
	var p = this.map.fromLatLngToDivPixel(this.latlng);
//	var z = GOverlay.getZIndex(this.latlng.lat());
	var z = markerZIndex(this);
	
	// Now position our DIV based on the DIV coordinates of our bounds
	this.div.style.left = (p.x + this.labelOffset.width) + "px";
	this.div.style.top = (p.y + this.labelOffset.height) + "px";
	this.div.style.zIndex = z + 1; // in front of the marker
}

// Remove the main DIV from the map pane, destroy event handlers
LabeledMarker.prototype.remove = function() {
	GEvent.clearInstanceListeners(this.div);
	this.div.parentNode.removeChild(this.div);
	this.div = null;
	GMarker.prototype.remove.apply(this, arguments);
}

