/* PropertyManage global methods */
var PhotoInfoUrl=pmbase+"/PropertyManage_Photo.aspx?"
var pmvts = new Array();
var pmCompare = new Array();

/* Compare properties methods */
function pmAddCp(pid){
	var r = PMAjaxFunctions.AjaxAddCp(pid);
	if(r.value){
		for(i=0;i<pmvts.length;i++){
			pmvts[i].listAdd(r.value)
		}
		$("a[@pid='" + pid + "'] .pmscpt").each(function() {
		   this.innerHTML='Remove from Compare List'
		 });
		$("a[@pid='" + pid + "'].pmscp").each(function() {
		   this.onclick=function(){pmDelCp(pid)}
		 });
	}
}
function pmDelCp(pid,c){
	var r = PMAjaxFunctions.AjaxDelCp(pid);
	if(r.value){
		for(i=0;i<pmvts.length;i++){
			if(!c)pmvts[i].listLoad();
			pmvts[i].countUpdate();
		}
		$("a[@pid='" + pid + "'] .pmscpt").each(function() {
		   this.innerHTML='Add to Compare List'
		 });
		$("a[@pid='" + pid + "'].pmscp").each(function() {
		   this.onclick=function(){pmAddCp(pid)}
		 });
	}
}

/* My properties methods */
function pmAddMp(pid){
	var r = PMAjaxFunctions.AjaxAddMp(pid);
	if(r.value){
		$("a[@pid='" + pid + "'] .pmsmpt").each(function() {
		   this.innerHTML='Remove from My Properties'
		 });
		$("a[@pid='" + pid + "'].pmsmp").each(function() {
		   this.onclick=function(){pmDelMp(pid)}
		 });
		pmUpdMpCount();
	}
}
function pmDelMp(pid){
	var r = PMAjaxFunctions.AjaxDelMp(pid);
	if(r.value){
		$("a[@pid='" + pid + "'] .pmsmpt").each(function() {
		   this.innerHTML='Save to My Properties'
		 });
		$("a[@pid='" + pid + "'].pmsmp").each(function() {
		   this.onclick=function(){pmAddMp(pid)}
		 });
		pmUpdMpCount();
	}
}
function pmUpdMpCount(){
	var r = PMAjaxFunctions.AjaxGetMpCount();
	$(".pmmp").text("(" + r.value + ")")
}


/* RoadTrip properties */
function pmAddRt(pid){
	var r = PMAjaxFunctions.AjaxAddRt(pid);
	if(r.value){
		$("a[@pid='" + pid + "'] .pmsrtt").each(function() {
		   this.innerHTML='Remove from RoadTrip'
		 });
		$("a[@pid='" + pid + "'].pmsrt").each(function() {
		   this.onclick=function(){pmDelRt(pid)}
		 });
		pmUpdRtCount();
	}
}
function pmDelRt(pid){
	var r = PMAjaxFunctions.AjaxDelRt(pid);
	if(r.value){
		$("a[@pid='" + pid + "'] .pmsrtt").each(function() {
		   this.innerHTML='Add to RoadTrip'
		 });
		$("a[@pid='" + pid + "'].pmsrt").each(function() {
		   this.onclick=function(){pmAddRt(pid)}
		 });
		pmUpdRtCount();
	}
}
function pmUpdRtCount(){
	var r = PMAjaxFunctions.AjaxGetRtCount();
	$(".pmrt").text("(" + r.value + ")")
}

function openFlyer(pid){
	MM_openBrWindow(pmbase + '/PropertyManage_Flyer.aspx?pid='+pid,'pmflyer','width=800,height=570');
}


/* PropertyManage preview */
function pmalPreview(id){
	this.id=id;
	this.init();
}
pmalPreview.prototype = {
	init : function(){
		this.element=_gel(this.id);				
		this.Title=_gel(this.id+"Title");		
		this.Close=_gel(this.id+"Close");		
		this.Rent=_gel(this.id+"Rent");
		this.CitySt=_gel(this.id+"CitySt");		
		this.Photo1=_gel(this.id+"Photo1");		
		this.Photo2=_gel(this.id+"Photo2");		
		this.Photo3=_gel(this.id+"Photo3");
		this.Remarks=_gel(this.id+"Remarks");	
		this.Save=_gel(this.id+"Save");			
		this.View=_gel(this.id+"View");			
		this.Close.base=this;
		this.Close.onclick=function(){this.base.hidePreview()}
		this.element.base=this;
	},
	showPreview : function(caller,pid){
		var p = findPos(caller)
		this.t = p.top;
		this.l = p.left+(caller.clientWidth-10);
		this.pid = pid;
		caller.timer=window.setTimeout(this.id + "._loadPreview();",500)
		caller.onmouseout=function(){window.clearTimeout(this.timer);}
	},
	_loadPreview : function(){
		PMAjaxFunctions.AjaxGetPreview(this.pid,function(r){r.context._showPreview(r)},this);
	},
	_showPreview : function(r){
		if(!r.value)return;
		r=r.value;
		$(this.Title).html(r.Street);
		$(this.Rent).html(r.Rent);
		$(this.CitySt).html(r.CitySt);
		$(this.Remarks).html(r.Remarks);
		if(this.Save){
			this.Save.pid=this.pid;
			if(r.IsMyProperty){
				$(".pmpr .pmsmpt").text('Remove From My Properties');
				this.Save.onclick=function(){pmDelMp(this.pid)}
			}else{
				$(".pmpr .pmsmpt").text('Save to My Properties');
				this.Save.onclick=function(){pmAddMp(this.pid)}	
			}
		}
		this.View.href=pmDetailUrl+"pid="+this.pid;
		this.Photo1.src=PhotoInfoUrl+"s=5&p="+r.Photo1;
		if(r.Photo2){
			this.Photo2.style.display="";
			this.Photo2.src=PhotoInfoUrl+"s=1&p="+r.Photo2;
			this.Photo2.target=this.Photo1.id;
			this.Photo2.path=PhotoInfoUrl+"s=5&p="+r.Photo2;
			this.Photo2.onmouseover=function(){MM_swapImage(this.target,'',this.path,1)}
			this.Photo2.onmouseout=function(){MM_swapImgRestore()};
		}
		if(r.Photo3){
			this.Photo3.style.display="";
			this.Photo3.src=PhotoInfoUrl+"s=1&p="+r.Photo3;
			this.Photo3.target=this.Photo1.id;
			this.Photo3.path=PhotoInfoUrl+"s=5&p="+r.Photo3;
			this.Photo3.onmouseover=function(){MM_swapImage(this.target,'',this.path,1)}
			this.Photo3.onmouseout=function(){MM_swapImgRestore()};
		}
		$(this.element).animate({ width: 'show', opacity: 'show' }, 'fast');
		this.element.style.left=this.l+"px";
		this.element.style.top=(37+this.t-(this.element.clientHeight/2))+"px";
		
	},
	hidePreview : function(){
		$(this.element).animate({ width: 'hide', opacity: 'hide' }, 'fast', function(){
			this.base.resetPreview()
		});
	},
	resetPreview : function(){
		this.Title.innerHTML="";
		this.Rent.innerHTML="";
		this.CitySt.innerHTML="";
		this.Remarks.innerHTML="";
		this.Photo1.src=null;
		this.Photo1.oSrc=null;
		this.Photo2.src=null;
		this.Photo2.style.display="none";
		this.Photo3.src=null;
		this.Photo3.style.display="none";
		$(".pmpr .pmsmpt").text('Save to My Properties');
	}
}

/* PropertyManage visitor tools */
function pmvt(id){
	this.id=id;
	this.init();
}
pmvt.prototype = {
	init : function(){
		this.loaded=false;
		
		// Compare switch
		this.cpswitch=_gel(this.id+'_CpSwitch');
		this.cpswitch.base=this;
		this.cpswitch.open=function(f){$(this.base.pane).animate({height:'show',opacity:'show'},'slow',f);if(!this.base.loaded)this.base.listLoad();this.base.pane.open=true;}
		this.cpswitch.close=function(f){$(this.base.pane).animate({height:'hide',opacity:'hide'},'slow',f);this.base.pane.open=false;}
		this.cpswitch.onclick=function(){
			if(this.base.pane.open){
				this.base.paneClose()
			}else{
				this.base.paneOpen()
			}
		}

		// Compare pane
		this.pane=_gel(this.id+'_CpPane');
		this.pane.open=false;
		this.pane.base=this;
		
		// Compare list
		this.list=_gel(this.id+'_CpList');
		this.list.base=this;
		
		// Compare command
		this.cpcmd=_gel(this.id+'_CpCmd');
		this.cpcmd.base=this;
		this.cpcmd.onclick=this.compare;
		pmvts[pmvts.length]=this;
	},
	compare : function(){
		pmCompare = new Array();
		var q="",l=$("#"+ this.base.list.id + " input:checked").length;
		if(l<2||l>5){alert('Please select 2 to 5 properties.');return false}
		$("#"+ this.base.list.id + " input:checked").each(function(){q+=this.args.pid+"|"})
		MM_openBrWindow(pmbase + '/PropertyManage_Compare.aspx?pids='+q,'pmcompare','width=800,height=570');
		this.base.paneClose();
		return false;
	},
	paneOpen : function(f){
		this.cpswitch.open(f);
				this.countUpdate();
	},
	paneClose : function(f){
		this.cpswitch.close(f);
				this.countUpdate();
	},
	listLoad : function(){
		$(this.list).empty();
		var r = PMAjaxFunctions.AjaxGetCp();
		var dt = r.value;
		if(dt!=null&&typeof(dt)=="object"&&dt.Rows.length>0){
			for(var i=0;i<dt.Rows.length;i++){
				var cp = new pmvtCpItem(dt.Rows[i],this)
				$(this.list).append(cp)
				$(cp).animate({height:'show',opacity:'show'},'slow')
			}
		}
		this.loaded=true;
	},
	listAdd : function(args){
		if(!this.loaded){
			this.listLoad();
			this.paneOpen(function(){this.base.paneClose()});
		}else{
			var s = this.pane.open
			this.paneOpen(function(){
				var cp = new pmvtCpItem(args,this.base);
				$(this.base.list).prepend(cp);
				var o,base=this.base;
				if(!s)o=function(){base.paneClose()};
				$(cp).animate({height:'show',opacity:'show'},1000,o)
			});
		}
	},
	countUpdate : function(){
		$('.pmcpc').text('('+$("#"+ this.list.id + " .comp").length+')')
	}
}

/* PropertyManage compare item */
function pmvtCpItem(args,base){
	this.base=base;
	this.init(args);
	return this.element;
}
pmvtCpItem.prototype = {
	init : function(args){
		var e,t,d,c,l,m,i,r,p,v
		e=$(_ce("DIV")).addClass("comp").attr("style","display:none");
		t=$(_ce("DIV")).addClass("comptop");
		d=_ce("A");
		d.args=args;
		d.base=this;
		d.onclick=function(){
			$(this.base.element).animate({height:'hide',opacity:'hide'},'slow',function(){$(this).remove();pmDelCp(this.args.pid, true)});
		}
		d.href="javascript://"
		t.append($(d).addClass("compdel unicode").attr({title:"Remove this item"}).html("&#10006;"))
		c=_ce("INPUT")
		c.args=args;
		c.id=args.pid;
		t.append($(c).addClass("compchk").attr({type:'checkbox'}));
		t.append($(_ce('LABEL')).attr("for",args.pid).addClass('comptitle fontstyle2 forecolor10').html(args.Street))
		e.append(t);
		m=$(_ce("DIV")).addClass("compmid");
		m.append($(_ce("IMG")).addClass("bordercolor7 compimg").attr({height:38,width:50,src: PhotoInfoUrl+"s=1&p="+args.Photo1}))
		m.append($(_ce("DIV")).text(args.CitySt))
		m.append($(_ce("DIV")).text(args.Rent))
		m.append($(_ce("A")).addClass("forecolor6 pmview").attr({style:"text-decoration:none",href:pmDetailUrl+"pid="+args.pid}).html('<span class="fontstyle1" style="text-decoration:underline">View Details</span> <span class="unicode forecolor7">&#9658;</span>'))
		e.append(m);
		
		this.element=e[0];
		this.element.args=args;
		this.element.base=this.base;
	}
}

/* PropertyManage Dynamic Plat */
function pmdp(m,id,mid,l,s,re,ri,vl,fr,cb,ag,st,a,o,su,b,r,pl,ph,be,ba,sz,g,ac,sa){
	this.map=m;
	this.id=id;
	this.mid=mid;
	this.Limit=l;
	this.Sort=s;

	// Search
	this.RentMin=pl|0;
	this.RentMax=ph|0;
	this.Beds=be|0;
	this.Baths=ba|0;
	this.Size=sz|0;
	this.Garage=g|0;
	this.Acres=ac|0;
	this.sAge=sa|0;
		
	// Filters
	this.Residential=re;
	this.Vacation=ri;
	this.Land=vl;
	this.Farm=fr;
	this.Commercial=cb;
	this.Age=ag;
	this.Status=st;
	this.Subdivision=su;
	this.Builder=b;
	this.Remarks=r;
	this.init();
}
pmdp.prototype = {
	init : function(){
		// Find elements
		this.pane = _gel(this.id + '_DpPane');
		this.list = _gel(this.id + '_DpList');
		this.nav = _gel(this.id + '_DpNav');
		this.stat = _gel(this.id + '_DpStat');
		this.ch = _gel(this.id + '_DpCh');
		this.srt = _gel(this.id + '_DpSort');
		this.sv = _gel(this.id + '_DpSv');
		this.srt.base=this;
		//if(browserType()!="safari")this.ch.className="pmcpmf";
		this.srt.onchange=function(){this.base.loadProperties(0)}
		this.pane.onmouseover=function(){this.className="pmdppb"}
		this.pane.onmouseout=function(){this.className="pmdppa"}
		var dp=this;
		this.map.AttachEvent('onobliqueenter',function(){dp.loadProperties();dp.updateStreetView()});
		this.map.AttachEvent('onendpan',function(){dp.updateStreetView()});
		this.map.AttachEvent('onendpan',function(){dp.loadProperties()});
		this.map.AttachEvent('onendzoom',function(){dp.loadProperties()});
		this.map.AttachEvent('onmousedown',function(){dp.mdown=true;});
		this.map.AttachEvent('onmousemove',function(){dp.showCrossHair()});
		this.map.AttachEvent('onmouseup',function(){dp.mdown=false;dp.hideCrossHair()});
		this.retreiving=false;
		this.mdown=false;
		this.hideCrossHair();
		this.updateStreetView();
		this.loadProperties(0);
	},
	showCrossHair : function(){
	  if(this.mdown)this.ch.style.display="";
	  return false;
	},
	hideCrossHair : function(){
	  this.ch.style.display="none";
	  return false;
	},
	loadProperties : function(pi){
		if(!pi)pi=0;
		this.Offset=pi*this.Limit;
		this.Sort=this.srt.value;
		var mc=getCenter(this.map);
		var view=getMapView(this.map)
		if(this.map.GetMapStyle()==VEMapStyle.Birdseye){
			this.map.SetShapesAccuracy(VEShapeAccuracy.Pushpin);
			this.map.SetFailedShapeRequest(VEFailedShapeRequest.DrawInaccurately);
		}else{
			this.map.SetShapesAccuracy(VEShapeAccuracy.None);
		}
		if(mc&&view&&this.retreiving!=true){
			this.retreiving=true;
			var dp=this;
			PMAjaxFunctions.AjaxGetPropertiesByCoordinates(this.Offset,this.Limit,this.Sort,mc.Latitude,mc.Longitude,view.TopLeftLatLong.Latitude,view.TopLeftLatLong.Longitude,view.BottomRightLatLong.Latitude,view.BottomRightLatLong.Longitude,this.Residential,this.Vacation,this.Land,this.Farm,this.Commercial,this.Age,this.Status,this.Agent,this.Office,this.Subdivision,this.Remarks,this.RentMin,this.RentMax,this.Beds,this.Baths,this.Size,this.Garage,this.Acres,this.sAge,function(r){dp.fillResults(r)});
		}
	},
	updateStreetView : function(){
		var mc=getCenter(this.map);
		if(mc){
			var dp=this;
			PMAjaxFunctions.AjaxGetStreetView(mc.Latitude,mc.Longitude,function(r){dp._updateStreetView(r)})
		}
	},
	_updateStreetView : function(r){
		if(!r.value||r.value==""){
			this.sv.style.display="none";
		}else{
			this.sv.style.display="";
			this.sv.src=r.value;
		}
	},
	fillResults : function(r){
		this.retreiving=false;
		this.map.HideInfoBox()
		$(this.list).empty();
		$(this.nav).empty();
		this.map.DeleteAllShapes();
		if(!r.value)return;
		var ds = r.value;
		
		// Fill list & add pins
		var dtp = ds.Tables[0];
		if(dtp!=null&&typeof(dtp)=="object"&&dtp.Rows.length>0){
			for(var i=0;i<dtp.Rows.length;i++){
				var cp = new pmResultItem(dtp.Rows[i],this, this.Offset+i+1)
				$(this.list).append(cp)
			}
		}
		
		var dts = ds.Tables[1];
		if(dts!=null&&typeof(dts)=="object"&&dts.Rows.length>0){
		
			var results=dts.Rows[0]
			var intCurrentPage = this.Offset / this.Limit
			var intDisplay = 5
			var intCenter = Math.ceil(intDisplay / 2)
			var intPages = Math.ceil(results.TotalResults / this.Limit)
			var intPageNum = (intCurrentPage + 1)
			
			// Set status
			$(this.stat).html('Properties ' + results.FirstRecord + '-' + results.LastRecord + ' of ' + results.TotalResults + ' in view.')
			
			// Add nav items
			if(intPageNum > 1){
				var link=_ce("A");
				link.base=this;
				link.index=(intCurrentPage - 1)
				link.onclick=function(){
					this.base.loadProperties(this.index);
				}
				link.href="javascript://"
				$(this.nav).append($(link).addClass("pmdpnl").html('Previous'))
			}
			
			var f=0,a=0
			for(var i=1;i<=intPages;i++){
				if(intPageNum + intCenter > intPages){
					f = Math.abs((intPageNum + intCenter) - intPages) - 1
				}else{
					f = 0
				}
				if(intPageNum - intCenter < 1){
					a = Math.abs(intPageNum - intCenter)
				}else{
					a = 0
				}
				if((i + f) > (intPageNum - intCenter) && (i - a) < (intPageNum + intCenter)){
					if(i == intPageNum){
						$(this.nav).append($(_ce("SPAN")).addClass("pmdpnl").html(i))
					}else{
						var link=_ce("A");
						link.base=this;
						link.index=(i-1)
						link.onclick=function(){
							this.base.loadProperties(this.index);
						}
						link.href="javascript://"
						$(this.nav).append($(link).addClass("forecolor6 pmdpnl").html(i))
						
					}
				}else if(((i + f) == (intPageNum - intCenter) || (i - a) == (intPageNum + intCenter)) && (i != 1 && i != intPages) ){
					$(this.nav).append($(_ce("SPAN")).addClass("pmdpnl").html('...'))
				}else if(i == 1 || i == intPages){
					var link=_ce("A");
					link.base=this;
					link.index=(i-1)
					link.onclick=function(){
							this.base.loadProperties(this.index);
					}
					link.href="javascript://"
					$(this.nav).append($(link).addClass("pmdpnl").html(i))
				}
			}
			if(intPageNum < intPages){
				var link=_ce("A");
				link.base=this;
				link.index=(intCurrentPage + 1)
				link.onclick=function(){
					this.base.loadProperties(this.index);
				}
				link.href="javascript://"
				$(this.nav).append($(link).addClass("pmdpnl").html("Next"))
			}
		}
	}
}

/* PropertyManage result item */
function pmResultItem(args,base,c){
	this.base=base;
	this.count=c;
	this.init(args);
	return this.element;
}
pmResultItem.prototype = {
	init : function(args){
		// Format price
		x=String(args.Rent).split('.');
		x1=x[0];
		x2=x.length>1?'.'+x[1]:'';
		var rgx=/(\d+)(\d{3})/;
		while (rgx.test(x1)){
			x1=x1.replace(rgx,'$1'+','+'$2');
		}
		// Set data
		var ap="$"+x1+x2;
		var ti=args.Street;
		var cs=args.City + ', ' +args.State;
		var bb=args.Beds + ' Beds, ' + args.Baths + ' Baths';
		var pd=args.ApxSqFt + ' Sqft, ' + args.Acres + ' Acres';
		var pca='<span class="backcolor2 bordercolor5 forecolor8 fontstyle2">' + this.count + '</span>';
		var pcb='<span class="backcolor6 bordercolor8 forecolor0 fontstyle2">' + this.count + '</span>';
		var url=pmDetailUrl+"pid="+args.ListingID+"&mid="+this.base.mid;
		
		// Create elements
		this.element=_ce("DIV");
		this.top=_ce("DIV");
		this.title=_ce("DIV");
		this.select=_ce("A");
		this.pinref=_ce("DIV");
		this.mid=_ce("DIV");
		this.element.style.cursor="pointer";
		this.element.className="comp"
		this.top.className="comptop";
		this.title.className="pmdptitle fontstyle2 forecolor10"
		this.select.className="forecolor6"
		this.pinref.className="pmdppinref"
		this.mid.className="compmid"
		this.select.href=url;
		// Create pin
		this.pin = new VEShape(VEShapeType.Pushpin, new VELatLong(args.Latitude,args.Longitude));
		this.pin.SetCustomIcon('<div class="pmdppin">' + pca + '</div>');
		this.pin.base=this;
		this.pin.pca=pca;
		this.pin.pcb=pcb;
		this.pin.SetTitle('<div class="fontstyle4 forecolor7 backcolor1" style="padding:2px">' + ti + '</div>');
		var desc = '<div class="pmbub forecolor10 backcolor0"><img class="bordercolor7 pmbubimg" src="'+PhotoInfoUrl+"s=2&p="+args.PhotoID+'"><div class="fontstyle3"><div>'+cs+'</div><div>'+ap+'</div><div>'+bb+'</div><div>'+pd+'</div><a href="'+url+'" class="forecolor6 pmview"><span class="fontstyle1" style="text-decoration:underline">View Details</span> <span class="unicode forecolor7">&#9658;</span></a></div></div>'
		if(pmmp||pmcp||pmrt){
			desc += '<div class="pmbubactions fontstyle1 forecolor7 backcolor0 bordercolor8">'
			if(pmmp){
				desc += '<a href="javascript://" class="forecolor6" pid="'+args.ListingID+'" onclick="pmAddMp('+args.ListingID+');"><b>+</b> My Properties</a>'
			}
			if(pmcp){
				desc += '<a href="javascript://" class="forecolor6" pid="'+args.ListingID+'" onclick="pmAddCp('+args.ListingID+');"><b>+</b> Compare List</a>'
			}
			if(pmrt){
				desc += '<a href="javascript://" class="forecolor6" pid="'+args.ListingID+'" onclick="pmAddRt('+args.ListingID+');"><b>+</b> RoadTrip</a>'
			}
			desc += '</div>'
		}
		this.pin.SetDescription(desc);
		var map=this.base.map;
		this.base.map.AttachEvent('onclick', function(e){
				if(e.elementID){
					var pin= map.GetShapeByID(e.elementID);
					map.HideInfoBox();
					map.ShowInfoBox(pin);
				}
			});
		this.base.map.AttachEvent('onmouseover', function(e){
				if(e.elementID){
					var pin= map.GetShapeByID(e.elementID);
					$(pin.base.pinref).html(pin.pcb)
					pin.base.base.list.scrollTop=pin.base.element.offsetTop
					return true
				}
			});
		this.base.map.AttachEvent('onmouseout', function(e){
				if(e.elementID){
					var pin= map.GetShapeByID(e.elementID);
					$(pin.base.pinref).html(pin.pca)
					return true
				}
			});
		this.base.map.AddShape(this.pin);

		// Base refs
		this.element.base=this;
		this.select.base=this;
		
		// Methods
		this.element.onclick=function(){
			this.base.base.map.HideInfoBox();
			this.base.base.map.ShowInfoBox(this.base.pin);
		}
		this.element.onmouseover=function(){
			this.base.pin.SetZIndex(2001)
			this.base.pin.SetCustomIcon('<div class="pmdppin">' + pcb + '</div>');
			$(this.base.pinref).html(pcb)
		}
		this.element.onmouseout=function(){
			this.base.pin.SetZIndex(1000)
			this.base.pin.SetCustomIcon('<div class="pmdppin">' + pca + '</div>');
			$(this.base.pinref).html(pca)
		}

		// Assemble nodes
		$(this.title).append($(this.select).html(ti));
		$(this.pinref).html(pca);
		$(this.top).append(this.pinref);
		$(this.top).append(this.title);
		$(this.element).append(this.top);
		var img = _ce("IMG")
		img.height=38;
		img.width=50;
		img.src=PhotoInfoUrl+"s=1&p="+args.PhotoID;
		$(img).addClass("bordercolor7 compimg")
		$(this.mid).append(img)
		$(this.mid).append($(_ce("DIV")).text(cs));
		$(this.mid).append($(_ce("DIV")).text(ap));
		var link=_ce("A");
		$(link).addClass("forecolor6 pmview")
		$(link).html('<span class="fontstyle1" style="text-decoration:underline">View Details</span> <span class="unicode forecolor7">&#9658;</span>')
		link.href=url;
		$(this.mid).append(link);
		$(this.element).append(this.mid);
	}
}

function getCenter(map){
	var mc=map.GetCenter()
	if(mc&&map.GetMapStyle()==VEMapStyle.Birdseye){
		var p=new _xz1
		var d=p.Decode(mc._reserved);
		mc = new VELatLong(d[0],d[1])
	}
	return mc;
}

function getMapView(map){
	var v = map.GetMapView();
	if(v&&map.GetMapStyle()==VEMapStyle.Birdseye){
		var p=new _xz1
		var dtl=p.Decode(v.TopLeftLatLong._reserved);
		var tl = new VELatLong(dtl[0],dtl[1])
		var dbr=p.Decode(v.BottomRightLatLong._reserved);
		var br = new VELatLong(dbr[0],dbr[1])
		var be = map.GetBirdseyeScene();
		switch(be.GetOrientation()){
			case VEOrientation.North:
				v = new VELatLongRectangle(tl,br,null,null);
				break;
			case VEOrientation.East:
				//flip long
				v = new VELatLongRectangle(new VELatLong(tl.Latitude,br.Longitude),new VELatLong(br.Latitude,tl.Longitude),null,null);
				break;
			case VEOrientation.South:
				//flip lat and long
				v = new VELatLongRectangle(br,tl,null,null);
				break;
			case VEOrientation.West:
				//flip lat
				v = new VELatLongRectangle(new VELatLong(br.Latitude,tl.Longitude),new VELatLong(tl.Latitude,br.Longitude),null,null);
				break;
		}
	}
	return v;
}