var map;
var bounds;
var mapCenter;
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();

function HoverItem(hitem, on)
{

	if (on)
	{
		hitem.style.backgroundColor='#EEEEEE';
	}
	else
	{
		hitem.style.backgroundColor='';
	}
}

function HoverMarker(listitem, on)
{

	if (on)
	{
		document.getElementById(listitem).style.backgroundColor='#EEEEEE';
	}
	else
	{
		document.getElementById(listitem).style.backgroundColor='';
	}
}

function setMarkers(map, listings) {
	var shadow = new google.maps.MarkerImage('/images/map/shadow.png',
	    new google.maps.Size(37, 34),
    	new google.maps.Point(0,0),
      	new google.maps.Point(0, 34));
	bounds = new google.maps.LatLngBounds();
	for (var i = 0; i < listings.length; i++) {
		var biz = listings[i];
		var point = new google.maps.LatLng(biz[1], biz[2]);
		var image = new google.maps.MarkerImage('/images/map/marker'+biz[0]+'.png',
		new google.maps.Size(20, 34),
	    new google.maps.Point(0,0),
        new google.maps.Point(0, 34));
		var marker = new google.maps.Marker({
	        position: point,
    	    map: map,
        	icon: image,
			shadow: shadow,
			title: biz[3],
			zIndex: 100-biz[0],
			optimized: false
	    });
		google.maps.event.addListener(marker, 'mouseover', markerOver(marker, biz[0]));
		google.maps.event.addListener(marker, 'mouseout', markerOut(marker, biz[0]));
		google.maps.event.addListener(marker, 'click', markerClick(marker, biz[4]));
		bounds.extend(point);


	}
}

function markerClick(marker, url){
	return function(){
		location.href=url}
}
function markerOver(marker, n){
	return function(){
		$('#list'+n).addClass('hoverOn');}
}
function markerOut(marker, n){
	return function(){
		$('#list'+n).removeClass('hoverOn');}
}
function markerOverL(marker, n){
		$('#list'+n).addClass('hoverOn');
}
function markerOutL(marker, n){
		$('#list'+n).removeClass('hoverOn');
}


