﻿// JScript File

var MemberMap = Class.create({
	initialize: function()
	{
		this.members = new Array();
		this.bounds = new GLatLngBounds();
		Event.observe(window, "load", this.loadMap.bindAsEventListener(this));
	},
	loadMap: function()
	{
		if (GBrowserIsCompatible()) 
		{
			this.map = new GMap2(document.getElementById("map"));
			this.map.setCenter(new GLatLng(43.6, -116.3), 11);
						this.map.addControl(new GSmallMapControl());			this.map.addControl(new GMapTypeControl());
			
			var memberItem;
			var link;
			var base = this;
			$$('li.member').each(function(item) 
			{
				memberItem = new MemberItem(
				{
					name: item.select('h3')[0].innerHTML, 
					lat: item.select('input.latitude')[0].value, 
					lng: item.select('input.longitude')[0].value,
					memberID: item.select('input.memberID')[0].value
				});
				base.addItem(memberItem);
				//link = item.select('a.resultlink')[0];
				//Event.observe(link, "click", base.resultLink_ClickSelf);
				//Event.observe(link, "click", base.resultLink_Click.bindAsEventListener(base, item.select('span.mlsnumber')[0].innerHTML));
				
			});
			//this.map.addOverlay(new GMarker(new GLatLng(43.6, -116.3)));
			this.draw();
			
		}
	
	},
	draw: function()
	{
		var base = this;
		this.members.each(function(item)
		{
			if (item.lat != '0')
			{
				base.bounds.extend(item.point);
				base.map.addOverlay(item.marker);
			}
			
		});
		this.map.setZoom(this.map.getBoundsZoomLevel(this.bounds));
		this.map.setCenter(base.bounds.getCenter());
	},
	clearItems: function()
	{
		this.members = new Array();
		this.bounds = new GLatLngBounds();
	},
	addItem: function(memberItem)
	{
		this.members.push(memberItem);
	},
	findItem: function(name)
	{
		var found = null;
		for(var idx = 0; idx < this.members.length; idx++)
		{
			if (this.members[idx].name == name)
			{
				found = this.results[idx];	
				break;	
			}
		}
		return found;
	}
});

var MemberItem = Class.create({
	initialize: function(jsonInfo)
	{
		this.name = jsonInfo.name;
		this.lat = jsonInfo.lat;
		this.lng = jsonInfo.lng;
		this.memberID = jsonInfo.memberID;
		this.values = jsonInfo;
		this.point = new GLatLng(this.lat, this.lng);
		this.marker = new GMarker(this.point);
		
		GEvent.bind(this.marker, "click", this, this.onMarkerClick);
	    GEvent.bind(this.marker, "mouseover", this, this.onRollover);
	    GEvent.bind(this.marker, "mouseout", this, this.onRollout);
	    
	},    onMarkerClick: function()    {        /*this.marker.openInfoWindowHtml(        '<div class="infowin">' + 			'<a href="/members/profile/?member=' + this.memberID + '">' + 			this.name + 			'</a>' + 		'</div>');*/		this.marker.openInfoWindowHtml($('member' + this.memberID).innerHTML);		    
        //this.marker.showMapBlowup(18, G_SATELLITE_TYPE);    },    onRollover: function()    {           },    highlightInList: function()    {            },    onRollout: function()    {            }
});
var bafMap = new MemberMap();