/////////////
// util.js //
/////////////

function startLoadingAnimation() {
	document.getElementById('loading_animation').style.visibility = 'visible';
}

function stopLoadingAnimation() {
	document.getElementById('loading_animation').style.visibility = 'hidden';
}


function asyncGetJson(url, cb, eb) {
	var opt = {
			 method: 'get',			 
			 onSuccess: cb,
			 on404: function(){alert('404 error, unable to load.');},
			 onFailure: eb
			};
	return (new Ajax.Request(url+'&nocache='+(new Date()).getTime(), opt)); 
}

function findImagesArray(marker) {
	for (var i in marker){
		if (typeof marker[i] == "object"){
			try {
				if (typeof marker[i][0].src != "undefined"){
					return i;
				}
			}
			catch (e) {}
		}
	}
	return '';
}


/////////////////////////////
// gxmarker.yelp.js /////////
// based on gxmarker.1.js //
////////////////////////////

function GxMarkerNamespace() {

var likesDXFilters = false;
var hideHoodOverlays = false;
if (Prototype.Browser.IE) {
	var ua = navigator.userAgent;
	var re	= new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	if (re.exec(ua) != null) {
		var rv = parseFloat( RegExp.$1 );
		if ((rv >= 6) && ((new RegExp("SV1")).exec(ua) != null)) { 
			likesDXFilters = true;
		} else if (rv == 6) {
			// If user has IE6 and but doesn't have SV1, then we hide 
			// hood overlays. Affects IE pre-SP2, and IE SP3
			hideHoodOverlays = true;
		}
	}
}
window.likesDXFilters = likesDXFilters;
window.hideHoodOverlays = hideHoodOverlays;

//will artificially bump up the zIndex of the marker
Yelp.importanceOrder = function(marker) {
	var rpp = fetchresults.current_query.rpp || 1;
	return rpp*10000;
}

function GxMarker(point, icon, tooltipHtml, clickURL, target, opts) {
	this.inheritFrom = GMarker;
	this.opts = opts || {};
	this.opts['icon'] = icon;
	this.inheritFrom(point, this.opts);
	if ( typeof tooltipHtml != "undefined" ) this.setTooltip( tooltipHtml );
	this.target = target || '_blank';
	this.clickURL = clickURL;
	this.imagesArray = '';
	this.oldImagePath = "";
	this.hoverIcon = createSliceIcon(icon.num, SLICE_STYLE_HIGHLIGHTED);
	this.events = new Array();
	this.markerMoused = false;
}

GxMarker.prototype = new GMarker(new GLatLng(1,1));

GxMarker.prototype.setTooltip = function( string ) {
	this.tooltip = new Object();
	this.tooltip.contents = string;
};

GxMarker.prototype.showHighlight = function() {
	if (this.imagesArray.length == 0) this.imagesArray = findImagesArray(this);

	if (this.imagesArray.length != '') {
		if (this.oldImagePath.length == 0) {
			this.oldImagePath = this[this.imagesArray][0].src;
		}
		if (Prototype.Browser.IE && likesDXFilters) {
			this[this.imagesArray][0].style.filter = 
				'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + this.hoverIcon.image + '")';
		} else {
			this[this.imagesArray][0].src = this.hoverIcon.image;
		}
		this[this.imagesArray][0].style.zIndex = 4999;
		this.redraw(true);
	}
};

GxMarker.prototype.removeHighlight = function() {
	if (this.imagesArray.length == 0) this.imagesArray = findImagesArray(this);

	if (this.imagesArray.length > 0 && this.oldImagePath) {
		if (Prototype.Browser.IE && likesDXFilters) {
			this[this.imagesArray][0].style.filter = 
				'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + this.oldImagePath + '")';
		} else {
			this[this.imagesArray][0].src = this.oldImagePath;
		}
		this.oldImagePath = "";
		this[this.imagesArray][0].style.zIndex = 4998;
		this.redraw(true);
	}
};

GxMarker.prototype.initialize = function( a ) {
	try {
		GMarker.prototype.initialize.call(this, a);
		
		// Setup the mouse over/out events
		this.events.unshift(GEvent.bind(this, "mouseover", this, this.onDelayedMouseOver));
		this.events.unshift(GEvent.bind(this, "mouseout",  this, this.onMouseOut));
		this.events.unshift(GEvent.bind(this, "click", this, this.onClick));
		this.map = a;
	} catch(e) {
		alert(e);
	}
};

GxMarker.prototype.remove = function( a ) {
	GMarker.prototype.remove.call(this);
	if( this.tooltipObject ) $(this.tooltipObject).remove();
	this.removeEvents();
	this.map = null;
};

GxMarker.prototype.onInfoWindowOpen = function() {
	this.hideMouseOver();
	GMarker.prototype.onInfoWindowOpen.call(this);
};

GxMarker.prototype.onClick = function() {
	if( this.clickURL ) window.open(this.clickURL, this.target);
};

GxMarker.prototype.onMouseOver = function(e) {
	var target = e ? Event.element(e) : null;
	this.showMouseOver(target);
};

GxMarker.prototype.onDelayedMouseOver = function(e){
	this.markerMoused = true;
	var target = e.element ? e.element() : null;
	function _delayedHover(){
		if(this.markerMoused){
			this.showMouseOver(target);
		}
	}
	_delayedHover.bind(this).delay(.5);
};

GxMarker.prototype.onMouseOut = function() {
    this.markerMoused = false;
	this.hideMouseOver();
};

GxMarker.prototype.showMouseOver = function(eventSource) {
	if ( this.tooltip ) {
		if ( typeof(this.tooltipObject) == "undefined" ) {
			this.tooltipObject = new Element("div");
			this.tooltipObject.setStyle({display:'none',position:'absolute',padding:'0px',margin:'0px',zIndex:5000});
			this.tooltipObject.innerHTML = '<div class="markerTooltip">' + this.tooltip.contents + '</div>';
			if(!$('tooltip_container')) //you can apply a className to this container to quickly change styles on all tooltips dynamically.
				document.body.appendChild(new Element('div', {id: 'tooltip_container'}));
			$('tooltip_container').appendChild(this.tooltipObject);

		}

		var bb = this.map.getBounds();
		// make sure the point is currently within map bounds
		if(bb.contains(this.getPoint())){
			var tlcLatLng = this.map.fromContainerPixelToLatLng(new GPoint(0,0), true);
			var tlcDivPixel = this.map.fromLatLngToDivPixel(tlcLatLng);
			var pointDivPixel = this.map.fromLatLngToDivPixel(this.getPoint());
			var c = new GPoint(pointDivPixel.x-tlcDivPixel.x, pointDivPixel.y-tlcDivPixel.y);
			var mapPos = findPosition(this.map.getContainer());
			
			this.tooltipObject.setStyle({left:'-999em',top:'-999em',display:'block'});
		
			// is it the location pin?
			var pin = (this.tooltip.contents.indexOf('loc_pin_flag') >= 0) ? true : false;
			var icon = this.getIcon();
			var tipLeft = c.x - icon.iconAnchor.x + mapPos[0];
			if(pin){
				tipLeft -= ((icon.iconSize.width / 2) - 6);
			}else if (tipLeft > (document.body.offsetWidth / 2)) {
				tipLeft -= this.tooltipObject.getWidth();
				
			} else {
				tipLeft += icon.iconSize.width;
			}

			var tipTop = c.y - icon.iconAnchor.y + mapPos[1];
			var tipHeight = this.tooltipObject.getHeight(); 
			if(pin){
				tipTop -= ((icon.iconSize.height) + 23); //23 is the height of the pin icon
				this.tooltipObject.setOpacity(.8);
			}else if ((c.y + this.map.getContainer().offsetTop) > (this.map.getContainer().offsetHeight / 2)) {
				tipTop -= tipHeight;
			} else {
				tipTop += icon.iconSize.height;
			}
			
			// Check for overlap with the eventSource (an HTML link), and move accordingly to avoid a flicker bug
			if( eventSource ) {
				var sourcePos = findPosition(eventSource);
				if( (tipLeft < sourcePos[0] + eventSource.offsetWidth) &&
				    ((tipTop < sourcePos[1] + tipHeight + 1) && (tipTop + tipHeight > sourcePos[1])) 
				  ) {
					tipLeft += (sourcePos[0] + eventSource.offsetWidth - tipLeft + 5);
				}
			}
			// also, keep tip out of way of search results for mo_map 
			var searchResults = $('searchLayoutMainResults');
			var tipBottom = tipTop + tipHeight;
			if(searchResults && $('searchPanelContainer').hasClassName('mo_map') && Position.within(searchResults, tipLeft, tipBottom)){
				tipLeft = findPosition(searchResults)[0] + searchResults.getWidth();
			}

			var scrollDist = document.viewport.getScrollOffsets()[1];

			this.tooltipObject.setStyle({left : tipLeft + "px", top : tipTop + "px"});
	
			var tipY = findPosition(this.tooltipObject)[1];
			//make sure tooltip does now show above the top of viewport 
			if(scrollDist > tipY){
				this.tooltipObject.setStyle({top : scrollDist+'px'});
			}
			
			if(this.opts.onDisplay){
				this.opts.onDisplay();
			}

			// reset locPin timeout
			if(pin && this.locPinTimeout){window.clearTimeout(this.locPinTimeout);}
		}
		this.showHighlight();
	}
};

GxMarker.prototype.hideMouseOver = function() {
	if ( typeof this.tooltipObject != "undefined" ) {		
		if(this.tooltip.contents.indexOf('loc_pin_flag') >=0 ){
			// delay locPin tooltip hide.
			Yelp.tooltipHolder = this.tooltipObject;
			this.locPinTimeout = window.setTimeout(function(){
				if(Yelp.tooltipHolder){
					Yelp.tooltipHolder.style.display = "none";
					Yelp.tooltipHolder=null;
				}
			},2000);
		}else{
			this.tooltipObject.style.display = "none";
		}
	}
	this.removeHighlight();
};

GxMarker.prototype.removeEvents = function () { 
	while (this.events.length > 0) { 
		GEvent.removeListener(this.events.shift());
	}
};
GxMarker.prototype.unload = function () {
	this.removeEvents();	 
	this.tooltipObject = null;
	this.tooltip = null;
	this.imagesArray = '';
	this.map = null;
	this.hoverIcon = null;
};
function makeInterface(a) {
	var b = a || window;
	b.GxMarker = GxMarker;
}

makeInterface();
}

GxMarkerNamespace();

// Yelp extension
GMap2.prototype.findCenterAndZoom = function(points) {
	var defaultZoom = 14;
	var center = null;
	if (points.length == 1){
		center = new GLatLng(points[0]['latitude'], points[0]['longitude']);
		return {zoom: defaultZoom, center: center};
	}

	var bounds = new GLatLngBounds(new GLatLng(90.0,180.0), new GLatLng(-90.0,-180.0));
	for (var i = 0; i < points.length; i++){
		if(points[i]['latitude'] && points[i]['longitude']){
			bounds.extend(new GLatLng(parseFloat(points[i]['latitude']), parseFloat(points[i]['longitude'])));
		}
	}

	center = bounds.getCenter();
	
	var newZoom = this.getBoundsZoomLevel(bounds);
	if (newZoom <= 0 || newZoom >= defaultZoom) {
		newZoom = defaultZoom;
	}

	return {zoom: newZoom, center: center, bounds: bounds};
};


//////////////////////////
// Original maputil.js //
/////////////////////////

var SLICE_STYLE_NORMAL = 1;
var SLICE_STYLE_HIGHLIGHTED = 2;
var SLICE_STYLE_FADED = 3;

function createSliceIcon(num, style) {
	var icon = new GIcon();
	// is it the location pin?
	var pin = typeof(num)=='number' ? false : true; //if it's the location pin, num will be 'loc_pin'
	if (!pin&&(num < 0)) {
		icon.image = imagesPrefix+'map/'+ ((style == SLICE_STYLE_HIGHLIGHTED) ? 'marker_star_highlighted.png' : 'marker_star.png');
	} else {
		var style_dir;
		if (style == SLICE_STYLE_NORMAL) {
			style_dir = 'normal';
		} else if (style == SLICE_STYLE_HIGHLIGHTED) {
			style_dir = 'hi';
		} else if (style == SLICE_STYLE_FADED) { //we currently only use faded markers on the mini-map
			style_dir = 'faded';
		}
		icon.image = imagesHostUrl + 'mapmarkers/' + imagesSerial + '/' + style_dir + '/' + num + '.png';
	}
	if(!pin){
		icon.iconSize = new GSize(20, 29);		
		icon.shadowSize = new GSize(38, 29);
		icon.shadow = imagesPrefix+'map/marker_shadow.png';
		icon.iconAnchor = new GPoint(15, 29);
		icon.infoWindowAnchor = new GPoint(15, 3);
	}else if(num == 'loc_pin'){
		icon.iconSize=new GSize(33,23);
		icon.iconAnchor=new GPoint(11, 21);
		icon.infoWindowAnchor=new GPoint(8, 1);
	}else if(num == 'Ad1'){//sponsor marker
		icon.image = (imagesPrefix + 'map/') + ((style == SLICE_STYLE_HIGHLIGHTED) ? 'sponsor_map_flag_highlight.png' : 'sponsor_map_flag.png');
		icon.iconSize=new GSize(25,33);
		icon.iconAnchor=new GPoint(11, 21);
		icon.infoWindowAnchor=new GPoint(8, 1);
		icon.shadowSize = new GSize(38, 29);
		icon.shadow = imagesPrefix+'map/marker_shadow.png';
	}
	icon.num = num;
	return icon;
};

function createBizMarker(biz, number, faded, url) {
	var clickURL = url || null;
	var point = new GPoint(biz['longitude'], biz['latitude']);
	var icon = createSliceIcon(number, faded ? SLICE_STYLE_FADED : SLICE_STYLE_NORMAL);
	var ad = null;
	var ad_type = null;
	
	// render popup HTML
	if(number=='Ad1') {
		var ad = $$('.add-result .biz-info')[0];
		var ad_type = $w(ad.readAttribute('class'))[0];
		if(biz['photos']) {
			var popupHTML = '<div class="sponsor"><span class="sp_text">' + Yelp._('Sponsored Result') + '</span><div class="markerbox iewidth">';
		} else {
			var popupHTML = '<div class="sponsor"><span class="sp_text">' + Yelp._('Sponsored Result') + '</span><div class="markerbox">';
		}
	} else if(biz['photos']) {
		var popupHTML = '<div class="markerbox iewidth">';
	} else {
		var popupHTML = '<div class="markerbox">';
	}

	if(biz['photos'] && biz['photos'].size() > 0) {
		var bizPhotoUrl = (imagesHostUrl + 'bphoto/' + biz['photos'][0]['id'] + '/ms');
		Yelp.preloadImage(bizPhotoUrl);
		popupHTML += '<img class="mbizPhoto" src="' + bizPhotoUrl + '" alt=""/>';
	}else if(biz['photo_url']){
		var bizPhotoUrl = imagesHostUrl + biz['photo_url'].substr(1);
		Yelp.preloadImage(bizPhotoUrl);
		popupHTML += '<img class="mbizPhoto" src="' + bizPhotoUrl + '" alt=""/>';
	}
	popupHTML += '<h3>' + biz['name'].escapeHTML() + '</h3>';
	
	popupHTML += fillBizMarker(biz, ad_type, ad);
	
	popupHTML += '</div></div>';
	if(number=='Ad1') popupHTML += '</div>';
	clickURL = (clickURL!=null) ? clickURL : (biz['id']) ? '/biz/' + biz['id'] : false;

	return new GxMarker(point, icon, popupHTML, clickURL);
};

function fillBizMarker(biz, ad_type, ad) {
	var popupHTML = '';
	switch(ad_type) {
		case 'announcement':
			var description = ad.down('blockquote p').innerHTML;
			var title = ad.down('strong').innerHTML;
			var title_class = ad.down('strong').readAttribute('class');
			popupHTML += '<strong class="' + title_class + '">' + title + '</strong><blockquote>' + description + '</blockquote>';
			break;
		case 'specialty':
			var description = ad.down('blockquote p').innerHTML;
			popupHTML += '<blockquote><p><strong>' + Yelp._('Specialties:') + '</strong> ' + description + '</p></blockquote>';
			break;
		case 'review':
		default:
			if (biz['review_count'] > 0) popupHTML += '<span class="markerboxstars">' + Yelp.HTML.stars(biz['rating'], false) + 'based on ' + biz['review_count'] + ' review' + (biz['review_count'] != 1 ? 's' : '') + '</span>';
			if (biz['formatted_address']) {
				popupHTML += '<address>';
				for (i=0; i < biz['formatted_address'].size(); i++) {
					popupHTML += biz['formatted_address'][i].escapeHTML() + '<br/>';
				}
				popupHTML += '</address>'
			}
			popupHTML += '<div class="mb_details">';
			if (biz['neighborhoods'].length > 0) {
				popupHTML += '<div class="hood">' + Yelp.ngettext("Neighborhood", "Neighborhoods", biz['neighborhoods'].length) + ': ' + biz['neighborhoods'].join(', ').escapeHTML() + '</div>';
			}
			if (biz['phone']) {
				popupHTML += biz['phone'].escapeHTML() + '<br />';
			}
			break;
	}
	return popupHTML;
}

function getAdjustedMapBounds(map, mapContainer) {
	var adjBounds = {};
	var topDead = 25;
	var leftDead = 10;
	var rightDead = 5;
	var bounds = map.getBounds();
	var lonPerPix = (bounds.getNorthEast().lng() - bounds.getSouthWest().lng())/mapContainer.clientWidth;
	var latPerPix = (bounds.getNorthEast().lat() - bounds.getSouthWest().lat())/mapContainer.clientHeight;
	
	adjBounds['minlon'] = bounds.getSouthWest().lng() + leftDead*lonPerPix;
	adjBounds['maxlon'] = bounds.getNorthEast().lng() - rightDead*lonPerPix;
	adjBounds['minlat'] = bounds.getSouthWest().lat();
	adjBounds['maxlat'] = bounds.getNorthEast().lat() - topDead*latPerPix;
	return adjBounds;
};


// functions for nearby biz map

//////////////////////
// mappity map map //
/////////////////////

var map = null;
var markers = null;
var highlightMarker = null;
var firstQuery = true;
var NEARBY_BIZ_COUNT = 5;

// this method highlights the appropriate marker on 
// the map when you enter or leave a particular element
// (usually a div) with class 'highlight_marker_box'.
// We require this particular class because the 
// event may be fired by any element within the box,
// so we need some way of indentifying the containing box
//
// You should set up this function to handle both 
// 'mouseover' and 'mouseout' events; it'll look at where
// the mouse pointer is to figure out what to do
function updateHighlightMarker(evt) {
	// get our target element
	var target = $(findEventTarget(evt));
	// this event came from something within the box
	if (!target.hasClassName('highlight_marker_box')) {
		target = target.up('.highlight_marker_box');
	}
	// get the index of the marker that target corresponds to 
	var target_id_parsed = target.id.split('_');
	var index = target_id_parsed[target_id_parsed.length-1];

	// are we in the box or out of it?
	if (Position.within(target, Event.pointerX(evt), Event.pointerY(evt))) {
		if (!highlightMarker) { // no current highlight
			// set the global highlight marker
			highlightMarker = new GMarker(markers[index].getPoint(), {
				icon:createSliceIcon(parseInt(index)+Yelp.pageStart, SLICE_STYLE_HIGHLIGHTED), 
				zIndexProcess:function(marker, b) { return 10000000; } 
			});
			// add the highlight marker to the map
			map.addOverlay(highlightMarker);
		}
	}
	else {
		if (highlightMarker) { // current highlight
			// remove the (global) highlight marker
			map.removeOverlay(highlightMarker);
			highlightMarker = null; 
		}
	}
}

function showPopupIndex(evt) {
	var target = $(findEventTarget(evt));
	var target_id_parsed = target.id.match(/\d+/);
	var index = parseInt(target_id_parsed.last());
	markers[index].showMouseOver(target);
}

function hidePopupIndex(evt) {
	var target = findEventTarget(evt);
	var target_id_parsed = target.id.match(/\d+/);
	var index = parseInt(target_id_parsed.last());
	markers[index].hideMouseOver();
}

function handleQueryResponse(results) {
	results = JSON.parse(results.responseText);
	map.clearOverlays();

	if (!results['success']) {
		Element.update('nearby_biz_list', '<span class="error">' + results['result'] + '</span>');
		stopLoadingAnimation();
		return;
	}

	var biz;
	var near_cat_select=$('nearby_cat_select');
	markers = new Array();
	var r = '';
	var bizInfos = results['result']['biz_list'];

	if ((bizInfos.length == 0)||(bizInfos.length==1 && bizInfos[0].id==json_biz.id)) {
		r += 'No matching '+somewhatSanitize(near_cat_select[near_cat_select.selectedIndex].innerHTML)+' found.	 Try <a href="#" onclick="map.setZoom(map.getZoom()-1);return false">zooming out<'+'/a> on the map.';
	} else {
		var index = 0;
		r += '<ul id="mapsearch_results">';
		for (var i = 0; (i < bizInfos.length) && (index < NEARBY_BIZ_COUNT); i++) {
			biz = bizInfos[i];

			if (biz['id'] == json_biz.id) {
				continue;
			}

			index++;

			var bizdUrl = '/biz/' + biz['id'];
			// list item
			r += '<li>'+ index + '.&nbsp;';
			if(biz['longitude']&&biz['latitude']){
				r += '<a id="nearby_biz_name_'+ index + '" href="' + bizdUrl + '">' + biz['name'] + '<'+'/a>';
			}else{
				r += '<a href="' + bizdUrl + '">' + biz['name'] + '<'+'/a>';
			}
			// Should we check for a 0 rating as well?
			if ((biz['rating'] != null) && (biz['review_count'] > 0)) {
				r += '<br/><div class="nonwrapping">' + Yelp.HTML.stars(biz['rating'], true);
				r += '<em class="smaller">' + biz['review_count'] + ' review' + (biz['review_count'] != 1 ? 's' : '') + '<'+'/em>' + '<' + '/div>';
			}			
			r += '<'+'/li>';

			var m = createBizMarker(biz, index, true);
			markers[index] = m;
			map.addOverlay(m);
		}
		if(bizInfos.length>=5){
			var spRE = /%20/g;
			var mnb = '<li id="more_nearby_results"><a href="/search?find_loc='+encodeURIComponent(json_biz.formatted_address_brief.join(', '));
			mnb.replace(spRE,'+');
			if(near_cat_select[near_cat_select.selectedIndex].value!='root'){
				mnb+='&cflt='+encodeURIComponent(near_cat_select[near_cat_select.selectedIndex].value);
			}
			mnb+='&z=15">... More Nearby '+somewhatSanitize(near_cat_select[near_cat_select.selectedIndex].innerHTML)+' &raquo;</a></li>';
			r+= mnb;
		}
		r += '<'+'/ul>';
	}
	
	Element.update('nearby_biz_list', r);
	
	for(var i=1;i<=NEARBY_BIZ_COUNT;i++){
		var el_index = $('nearby_biz_name_'+i);
		if(el_index){
			Element.observe(el_index,'mouseover',showPopupIndex);
			Element.observe(el_index,'mouseout',hidePopupIndex);
		}
	}

	biz = json_biz;
	map.addOverlay(createBizMarker(biz, -1, false));

	stopLoadingAnimation();
	near_cat_select=null;
}

function handleQueryError(req) {
	Element.update('nearby_biz_list', '<span class="error">Error connecting to server.  Please try again later.</span>');
	stopLoadingAnimation();
}

function updateResults() {
	startLoadingAnimation();

	var params = getAdjustedMapBounds(map, document.getElementById("mapdiv"));
	params['type'] = 'browse';
	var select_element = document.getElementById('nearby_cat_select');
	params['arg'] = select_element.options[select_element.selectedIndex].value;
	params['sort'] = 'rating';
	params['start'] = 0;
	params['count'] = NEARBY_BIZ_COUNT + 1;
	if (firstQuery) {
		params['ch'] = '1';
	}

	firstQuery = false;

	var url = '/mapsearch_query/search?' + Yelp.encodeQueryComponents(params);
	asyncGetJson(url, handleQueryResponse, handleQueryError);
}

var copyrightTimer = null;

function initMap() {
	map = new GMap2(document.getElementById("mapdiv"));

	map.addControl(new GSmallZoomControl());
	map.setCenter(new GLatLng(parseFloat(json_biz.latitude), parseFloat(json_biz.longitude)), 15);

	GEvent.addListener(map, "moveend", updateResults);

	updateResults();
	
	copyrightTimer = window.setInterval('makeCopyrightSmaller()', 150); 
}
// for unloading nearby_biz map objects
function uninitMap(){
	// 'this' should be the ID prefix for the elements you want to stop observing.
	for(var i=1;i<=NEARBY_BIZ_COUNT;i++){
		var el_index = $(this+'_'+i);
		if(el_index){
			Element.stopObserving(el_index,'mouseover',showPopupIndex);
			Element.stopObserving(el_index,'mouseout',hidePopupIndex);
		}
	}
	if(map){
		map.clearOverlays.call(map);
		GUnload();
	}
	markers = null;
	map = null;
}
function makeCopyrightSmaller() {
	if (map && map.isLoaded()){
		for(var i = 0; i < map.getContainer().childNodes.length; ++i) {
			if(map.getContainer().childNodes[i].innerHTML.indexOf(String.fromCharCode(169)) !== -1){
				map.getContainer().childNodes[i].style.fontSize = '9px';
				var logo = $$('.gmnoprint img').first();
				if(logo){
					logo.setStyle({width:'45px',height:'21px'});
				}
				window.clearInterval(copyrightTimer);
				break;
			}
		}
	}
}

Yelp.mapScrollObserver = function (event) {
	if(!Yelp.prevent_scroll){
		// check if user has scrolled to the point where we would need to move the map
		if (Yelp.mTest) { 
			clearInterval(Yelp.mTest);
		} else {	
			Yelp.startScroll = document.documentElement.scrollTop;
		}
		Yelp.mTest = setInterval("Yelp.moveTest()", 300);
	}
};

// checks how far user has scrolled window, and moves map accordingly.
Yelp.moveTest = function (){
	var num = document.viewport.getScrollOffsets()[1];	
	if(Yelp.startScroll==num){
		clearInterval(Yelp.mTest);
		Yelp.mTest = null;
		Yelp.moveBox(num);	// right now moveBox must be defined seperately for each map page.
	}	
	Yelp.startScroll = num;
};

