
function equalHeights(div1,div2,div3) {
	var highestCol = Math.max($('#'+div1).height(),$('#'+div2).height(),$('#'+div3).height());
	$('#'+div1).height(highestCol);
	$('#'+div2).height(highestCol);
	$('#'+div3).height(highestCol);
}

function updateInMyArea() {
  var lat = $.cookie('mlat');
  var lng = $.cookie('mlng');
  if (lat && lng) {
    $('#topmenusearch input[name="lat"]').val(lat);
    $('#topmenusearch input[name="lng"]').val(lng);
    $('#tmmyarea').parent().show();
  } else {
    $('#tmmyarea').parent().hide();
  }
}

function addPub(pub) {
	
  var contentString = formatContent(pub);
  var myLatlng = new google.maps.LatLng(pub.pubLatLng.lat, pub.pubLatLng.lng);
 
	var FAPLogo = new google.maps.MarkerImage('/images/marker.png',
		new google.maps.Size(20,34),
		new google.maps.Point(0,0),
		new google.maps.Point(20,34)
	);
	
	var FAPShadow = new google.maps.MarkerImage('/images/marker_shadow.png',
		new google.maps.Size(34,34),
		new google.maps.Point(0,0),
		new google.maps.Point(20, 34)
	);

  pub.marker = new google.maps.Marker({
     position: myLatlng,
     map: map,
	 title: pub.name,
	 icon: FAPLogo,
     shadow: FAPShadow
  });

  google.maps.event.addListener(pub.marker, 'click', function() {

    infowindow.setContent(contentString);
    infowindow.open(map,pub.marker);
  });

  return pub;
}

function formatContent(pub) {

  var image;

  if (pub.imageLocation != '') {
    image = '/media/' + pub.imageLocation;
  } else {
    image = '/images/awaiting_pub_image.jpg';
  }

  var content = '<div class="map_thumbnails_container"><img class="map_thumbnails" src="../../html/js/' + image + '"/></div>' 
  content = content + '<div class="map_info"><a href="/Pub/view/' + pub.pubId + '"><b>'+ pub.name + '</b><br />' + pub.address.town_city + "<br/>";
  content = content + pub.address.postcode + "</a><br/>";
  if (pub.fapAvg >= 0) {
  	content = content + '<img src="/images/rating_' + Math.round(pub.fapAvg) + '.png" alt="FAP rating" title="FAP rating ' + Math.round(pub.fapAvg) + '" />';
  } else {
	  	if (pub.communityAvg >= 0) {
  			content = content + '<img src="/images/rating_' + Math.round(pub.communityAvg) + '.png" alt="Community rating" title="Community rating ' + Math.round(pub.communityAvg) + '" />';
		} else {
			content = content + '<img src="/images/rating_none.png" alt="Not rated yet!" title="Not rated yet!" />';
		}
  }
  return content;
}

