/* HomeSell global methods */
var hsPhotoUrl=hsbase+"/HomeSell_Photo.aspx?"
var hsvts = new Array();
var hsCompare = new Array();

/* Compare properties methods */
function hsAddCp(pid, lsid){
	var r = MLSAjaxFunctions.AjaxAddCp(pid,lsid);
	if(r.value){
		for(i=0;i<hsvts.length;i++){
			hsvts[i].listAdd(r.value)
		}
		$("a[pid='" + pid + "'] .hsscpt").each(function() {
		   this.innerHTML='Remove from Compare List'
		 });
		$("a[pid='" + pid + "'].hsscp").each(function() {
		   this.onclick=function(){hsDelCp(pid,lsid)}
		 });
	}
}
function hsDelCp(pid, lsid,c){
	var r = MLSAjaxFunctions.AjaxDelCp(pid,lsid);
	if(r.value){
		for(i=0;i<hsvts.length;i++){
			if(!c)hsvts[i].listLoad();
			hsvts[i].countUpdate();
		}
		$("a[pid='" + pid + "'] .hsscpt").each(function() {
		   this.innerHTML='Add to Compare List'
		 });
		$("a[pid='" + pid + "'].hsscp").each(function() {
		   this.onclick=function(){hsAddCp(pid,lsid)}
		 });
	}
}

/* My properties methods */
function hsAddMp(pid, lsid){
	var r = MLSAjaxFunctions.AjaxAddMp(pid,lsid);
	if(r.value){
		$("a[pid='" + pid + "'] .hssmpt").each(function() {
		   this.innerHTML='Remove from My Properties'
		 });
		$("a[pid='" + pid + "'].hssmp").each(function() {
		   this.onclick=function(){hsDelMp(pid,lsid)}
		 });
		hsUpdMpCount();
	}
}
function hsDelMp(pid, lsid){
	var r = MLSAjaxFunctions.AjaxDelMp(pid,lsid);
	if(r.value){
		$("a[pid='" + pid + "'] .hssmpt").each(function() {
		   this.innerHTML='Save to My Properties'
		 });
		$("a[pid='" + pid + "'].hssmp").each(function() {
		   this.onclick=function(){hsAddMp(pid,lsid)}
		 });
		hsUpdMpCount();
	}
}
function hsUpdMpCount(){
	var r = MLSAjaxFunctions.AjaxGetMpCount();
	$(".hsmp").text("(" + r.value + ")")
}


/* RoadTrip properties */
function hsAddRt(pid, lsid){
	var r = MLSAjaxFunctions.AjaxAddRt(pid,lsid);
	if(r.value){
		$("a[pid='" + pid + "'] .hssrtt").each(function() {
		   this.innerHTML='Remove from RoadTrip'
		 });
		$("a[pid='" + pid + "'].hssrt").each(function() {
		   this.onclick=function(){hsDelRt(pid,lsid)}
		 });
		hsUpdRtCount();
	}
}
function hsDelRt(pid, lsid){
	var r = MLSAjaxFunctions.AjaxDelRt(pid,lsid);
	if(r.value){
		$("a[pid='" + pid + "'] .hssrtt").each(function() {
		   this.innerHTML='Add to RoadTrip'
		 });
		$("a[pid='" + pid + "'].hssrt").each(function() {
		   this.onclick=function(){hsAddRt(pid,lsid)}
		 });
		hsUpdRtCount();
	}
}
function hsUpdRtCount(){
	var r = MLSAjaxFunctions.AjaxGetRtCount();
	$(".hsrt").text("(" + r.value + ")")
}

function openFlyer(pid,lsid,mid){
    MM_openBrWindow(hsbase + '/HomeSell_Flyer.aspx?pid=' + pid + '&lsid=' + lsid + '&mid=' + mid, 'hsflyer', 'width=650,height=600,scrollbars=1,resizable=0');
}


/* HomeSell preview */
function hsalPreview(id){
	this.id=id;
	this.init();
}
hsalPreview.prototype = {
	init : function(){
		this.element=_gel(this.id);				
		this.Title=_gel(this.id+"Title");		
		this.Close=_gel(this.id+"Close");		
		this.Price=_gel(this.id+"Price");
		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,lsid){
		var p = findPos(caller)
		this.t = p.top;
		this.l = p.left+(caller.clientWidth-10);
		this.pid = pid;
		this.lsid = lsid;
		caller.timer=window.setTimeout(this.id + "._loadPreview();",500)
		caller.onmouseout=function(){window.clearTimeout(this.timer);}
	},
	_loadPreview : function(){
		MLSAjaxFunctions.AjaxGetPreview(this.pid,this.lsid,function(r){r.context._showPreview(r)},this);
	},
	_showPreview : function(r){
		if(!r.value)return;
		r=r.value;
		$(this.Title).html(r.Street);
		$(this.Price).html(r.Price);
		$(this.CitySt).html(r.CitySt);
		$(this.Remarks).html(r.Remarks);
		if(this.Save){
			this.Save.pid=this.pid;
			this.Save.lsid=this.lsid;
			if(r.IsMyProperty){
				$(".hspr .hssmpt").text('Remove From My Properties');
				this.Save.onclick=function(){hsDelMp(this.pid,this.lsid)}
			}else{
				$(".hspr .hssmpt").text('Save to My Properties');
				this.Save.onclick=function(){hsAddMp(this.pid,this.lsid)}	
			}
		}
		var url = 'javascript: var t=function(){$.fn.colorbox({href:\'' + hsDetailUrl + 'pid=' + this.pid + '&lsid=' + this.lsid + '&isModal=1\', open:true})};t();';

		this.View.href = url;
		this.Photo1.src=hsPhotoUrl+"r=1&s=5&p="+r.Photo1;
		if(r.Photo2){
			this.Photo2.style.display="";
			this.Photo2.src=hsPhotoUrl+"r=1&s=1&p="+r.Photo2;
			this.Photo2.target=this.Photo1.id;
			this.Photo2.path=hsPhotoUrl+"r=1&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=hsPhotoUrl+"r=1&s=1&p="+r.Photo3;
			this.Photo3.target=this.Photo1.id;
			this.Photo3.path=hsPhotoUrl+"r=1&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.Price.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";
		$(".hspr .hssmpt").text('Save to My Properties');
	}
}

/* HomeSell visitor tools */
function hsvt(id){
	this.id=id;
	this.init();
}
hsvt.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;
		hsvts[hsvts.length]=this;
	},
	compare : function(){
		hsCompare = 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+","+this.args.lsid+"|"})
		MM_openBrWindow(hsbase + '/HomeSell_Compare.aspx?pids='+q,'hscompare','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 = MLSAjaxFunctions.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 hsvtCpItem(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 hsvtCpItem(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(){
		$('.hscpc').text('('+$("#"+ this.list.id + " .comp").length+')')
	}
}

/* HomeSell compare item */
function hsvtCpItem(args,base){
	this.base=base;
	this.init(args);
	return this.element;
}
hsvtCpItem.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();hsDelCp(this.args.pid, this.args.lsid, 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: hsPhotoUrl+"r=1&s=1&p="+args.Photo1}))
		m.append($(_ce("DIV")).text(args.CitySt))
		m.append($(_ce("DIV")).text(args.Price))
		m.append($(_ce("A")).addClass("forecolor6 hsview").attr({ style: "text-decoration:none", href: hsDetailUrl + "pid=" + args.pid + "&lsid=" + args.lsid }).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;
	}
}

/* HomeSell Dynamic Plat */
function hsdp(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,rs,rc,rf,ar){
	this.map=m;
	this.id=id;
	this.mid=mid;
	this.Limit=l;
	this.Sort=s;

	// Search
	this.PriceMin=pl|0;
	this.PriceMax=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.ResidentialIncome=ri;
	this.Land=vl;
	this.Farm=fr;
	this.Commercial=cb;
	this.Age=ag;
	this.Status=st;
	this.Agent=a;
	this.Office=o;
	this.Subdivision=su;
	this.Builder=b;
	this.Remarks = r;
	//New
	this.ResSingle = rs;
	this.ResCondo = rc;
	this.ResMfg = rf;
    this.MLSAreas = ar;
	//
	this.init();
}
hsdp.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 = _ce("IMG");
		this.ch.src = '/Program%20Files/Neoreef%20Business%20Solutions/HomeSell%202.0/Resources/Images/hsSite.png';
		this.ch.base = this;
		this.ch.map = this.map;
		this.ch.className = "hsch";
		$(_gel(this.map.ID)).append(this.ch);
		this.srt = _gel(this.id + '_DpSort');
		this.sv = _gel(this.id + '_DpSv');
		this.srt.base=this;
		this.srt.onchange=function(){this.base.loadProperties(0)}
		this.pane.onmouseover=function(){this.className="hsdppb"}
		this.pane.onmouseout=function(){this.className="hsdppa"}
		var dp=this;
		this.map.AttachEvent('onendpan',function(){dp.updateStreetView()});
		this.map.AttachEvent('onendpan',function(){dp.loadProperties()});
		this.map.AttachEvent('onendzoom',function(){dp.loadProperties()});
		this.map.AttachEvent('onstartpan',function(){dp.showCrossHair()});
		this.map.AttachEvent('onstartzoom',function(){dp.showCrossHair()});
		this.map.AttachEvent('onmouseup',function(){dp.hideCrossHair()});
		
		var map = this.map;
        this.map.AttachEvent('onclick', function(e) {
            if (e.elementID) {
                var pin = map.GetShapeByID(e.elementID);
                map.HideInfoBox();
                map.ShowInfoBox(pin);
            }
            return false;
        });        
        this.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.map.AttachEvent('onmouseout', function(e) {
            if (e.elementID) {
                var pin = map.GetShapeByID(e.elementID);
                $(pin.base.pinref).html(pin.pca)
                return true
            }
        });
		
		this.updateStreetView()
		this.retreiving=false;
		this.loadProperties(0);
	},
	showCrossHair : function(){
	  $(this.ch).animate({height:'190px',width:'193px',marginLeft:'-96px',marginTop:'-95px'},500)
	  return false;
	},
	hideCrossHair : function(){
	  $(this.ch).animate({height:'0px',width:'0px',marginLeft:'0px',marginTop:'0px'},{ queue:false, duration:500 })
	  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;
			MLSAjaxFunctions.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.ResidentialIncome, this.Land, this.Farm, this.Commercial, this.Age, this.Status, this.Agent, this.Office, this.Subdivision, this.Builder, this.Remarks, this.PriceMin, this.PriceMax, this.Beds, this.Baths, this.Size, this.Garage, this.Acres, this.sAge, this.ResSingle,this.ResCondo,this.ResMfg,this.MLSAreas,function(r) { dp.fillResults(r) });
		}
	},
	updateStreetView : function(){
		var mc=getCenter(this.map);
		if(mc){
			var dp=(this._updateStreetView)?this:this.base;
			MLSAjaxFunctions.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 hsResultItem(dtp.Rows[i],this, this.Offset+i+1)
				$(this.list).append(cp)
			}
		}
		this.hideCrossHair();
		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("hsdpnl").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("hsdpnl").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 hsdpnl").html(i))
						
					}
				}else if(((i + f) == (intPageNum - intCenter) || (i - a) == (intPageNum + intCenter)) && (i != 1 && i != intPages) ){
					$(this.nav).append($(_ce("SPAN")).addClass("hsdpnl").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("hsdpnl").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("hsdpnl").html("Next"))
			}
		}
	}
}

/* HomeSell result item */
function hsResultItem(args,base,c){
	this.base=base;
	this.count=c;
	this.init(args);
	return this.element;
}
hsResultItem.prototype = {
    init: function(args) {
        // Format price
        x = String(args.AskingPrice).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.AddressNumber + ' ' + args.AddressDirection + ' ' + args.AddressStreet;
        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 = 'javascript: var t=function(){$.fn.colorbox({href:\'' + hsDetailUrl + 'pid=' + args.MLSNumber + '&lsid=' + args.ListingServiceID + '&mid=' + this.base.mid + '&isModal=1\', open:true})};t();';

        // 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 = "hsdptitle fontstyle2 forecolor10"
        this.select.className = "forecolor6"
        this.pinref.className = "hsdppinref"
        this.mid.className = "compmid"
        this.select.href = url;

        // Create pin
        this.pin = new VEShape(VEShapeType.Pushpin, new VELatLong(args.MapPointLatitude, args.MapPointLongitude));
        this.pin.SetCustomIcon('<div class="hsdppin">' + 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="hsbub forecolor10 backcolor0"><img class="bordercolor7 hsbubimg" src="'+hsPhotoUrl+"r=1&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 hsview"><span class="fontstyle1" style="text-decoration:underline">View Details</span> <span class="unicode forecolor7">&#9658;</span></a></div></div>'
        if (hsmp || hscp || hsrt) {
            desc += '<div class="hsbubactions fontstyle1 forecolor7 backcolor0 bordercolor8">'
            if (hsmp) {
                desc += '<a href="javascript://" class="forecolor6" pid="' + args.MLSNumber + '" onclick="hsAddMp(' + args.MLSNumber + ',' + args.ListingServiceID + ');"><b>+</b> My Properties</a>'
            }
            if (hscp) {
                desc += '<a href="javascript://" class="forecolor6" pid="' + args.MLSNumber + '" onclick="hsAddCp(' + args.MLSNumber + ',' + args.ListingServiceID + ');"><b>+</b> Compare List</a>'
            }
            if (hsrt) {
                desc += '<a href="javascript://" class="forecolor6" pid="' + args.MLSNumber + '" onclick="hsAddRt(' + args.MLSNumber + ',' + args.ListingServiceID + ');"><b>+</b> RoadTrip</a>'
            }
            desc += '</div>'
        }
        this.pin.SetDescription(desc);
        

        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="hsdppin">' + pcb + '</div>');
            $(this.base.pinref).html(pcb)
            //this.base.base.map.HideInfoBox();
            //this.base.base.map.ShowInfoBox(this.base.pin);
        }
        this.element.onmouseout = function() {
            this.base.pin.SetZIndex(1000)
            this.base.pin.SetCustomIcon('<div class="hsdppin">' + pca + '</div>');
            //this.base.base.map.HideInfoBox();
            $(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 = hsPhotoUrl + "r=1&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 hsview")
		$(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){
	if(!map)return null;
	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;
}
