
/*<script />*/

// these functions are for mapping single properties

var map='';
var nhoodlayers= new Array();
var mWidth = 500;
var mHeight = 375;
function urlencode(str) {
return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}
function SingleMap(){
	nhoodlayers['SELECTED']=new VEShapeLayer();
 	//var center= new VELatLong(lat,long);	
	  var center= new VELatLong(41.878764,-87.666310 );
	 map= new VEMap('searchMap');
	  VEShape.prototype.mls='';// add mls property to shapes
  VEShape.prototype.clusterdata='';// add mls property to shapes
   VEShape.prototype.resultNumber='';// add mls property to shapes
    VEShape.prototype.iconImage='';// add mls property to shapes
	 map.LoadMap(center,13,VEMapStyle.Road,false,VEMapMode.Mode2D,true,1);


map.AttachEvent("onmouseover", PinHover);
}



function ZoomSetSingle(lat,long,mlsnumber){
	var center= new VELatLong(lat,long);
	//alert('zoom set single');
	//	 map= new VEMap('searchMap');
	//	 map.LoadMap(center,13,VEMapStyle.Road,false,VEMapMode.Mode2D,true,1);
	//	  VEShape.prototype.mls='';// add mls property to shapes
  //VEShape.prototype.clusterdata='';// add mls property to shapes
   //VEShape.prototype.resultNumber='';// add mls property to shapes
    //VEShape.prototype.iconImage='';// add mls property to shapes
	map.SetCenterAndZoom(center, 13);	
	//alert('mapsingle');
	
		//call xml for selected properties
		nhoodlayers['SELECTED'].DeleteAllShapes();
			    var points = new Array();
    points.push(map.PixelToLatLong(new VEPixel(0,0)));
    points.push(map.PixelToLatLong(new VEPixel(mWidth,mHeight)));
    var bounds = (points[0].Latitude)+','+(points[0].Longitude)+'|'+(points[1].Latitude)+','+(points[1].Longitude);	
	var zoom = map.GetZoomLevel();	
				var veLayerSpec= new VEShapeSourceSpecification(VEDataType.ImportXML,'http://67.23.23.224/wp-content/themes/SGR/realestate/xmldata/selectedPropXML.php?PHPSESSID='+readCookie('PHPSESSID')+'&nhoodname=SELECTED&bounds='+urlencode(bounds)+'&zoom='+zoom,nhoodlayers['SELECTED']);
	//alert('http://67.23.23.224//wp-content/themes/SGR/realestate/xmldata/testXML.php?PHPSESSID='+readCookie('PHPSESSID'));
	map.ImportShapeLayerData(veLayerSpec,ShapeLayerCallBack,false);
	
}


function ShapeLayerCallBack(newdata){
	//alert('fileloaded');
	//alert(newdata.GetShapeCount());
totalShapes=newdata.GetShapeCount();
		//alert(totalShapes);
for(x=0; x < totalShapes; ++x){
	 var currentShape = newdata.GetShapeByIndex(x);
       if (currentShape.GetType() == VEShapeType.Pushpin){
			// is apush pin
			//currentShape._customIcon=true;
			 currentShape.mls = currentShape.GetTitle();    
			
			// break;
			parts=currentShape.GetDescription().split("|");
			
			currentShape.resultNumber=parts[0];
			currentShape.iconImage=parts[1];
			  currentShape.clusterData = parts[2]+'|'+parts[3]; //alert(currentShape.IconId);
			 // currentShape.SetCustomIcon("<img src='"+ currentShape.IconId+"'/>");
			// alert(currentShape.GetTitle());
			currentShape.SetDescription('Loading Data');
			 //alert(currentShape.OnMouseOverCallback); 
			 //console.log(currentShape);
			 
			 if(parts[2]){
				size=24 + (parts[2]/2);
				if(size > 60){size=60;}
			 }else{
				 size=24;
			 }
			 moveup=size/2+7;
			currentShape.SetCustomIcon("<img src='/wp-content/themes/SGR/images/"+currentShape.iconImage+"' width="+size+" height="+size+" /><span   class='mapPinText' style='width:"+size+"px;top:-"+moveup+"px;'>"+currentShape.resultNumber+"</span>"); 
			 
				 
		}
}
}

function GetInfoData(mls,targetBox,parts){
	//alert(mls+targetBox);
	UpdateData(targetBox,'mapPopUpContent.php?mls='+mls+'&parts='+urlencode(parts));
}

function PinHover(e)
{    
//alert('hover');
//alert(e.elementID);
      if(e.elementID)

    {

        //mouse is over a pushpin (or over a shape)

        var pin= map.GetShapeByID(e.elementID);
		if(pin.clusterData){
		var groups=pin.clusterData;
		}else{
		var groups='';	
		}
		//alert(pin);
      //change Info Box information just before displaying it!

       // var newInfoBoxTitle  = "Some New Title"+ pin.mls;
		//alert(pin.mls);
        
		pin.SetTitle("<div class='titleStyle' >"+ pin.mls+" </div>");
      var newInfoBoxText = "Loading";
		
         pin.SetDescription("<div id='IB"+pin.mls.trim() +"' >"+newInfoBoxText+"</div>");
		GetInfoData(pin.mls,'IB'+pin.mls,groups);
        // or if you want to prevent executing the default behaviour, that is don't show the Info Box, then uncomment the line below

         //return true;

    }
}


if(window.onload){
	
	window.onload=window.onload +'SingleMap();';	
}else{
	
	window.onload=SingleMap;	
}