//this function for image map
function submitState(myState){
	document.mapform.state.value = myState;
	document.mapform.submit();
}
function createMarker( point, num, address, icon ){
	var marker = new GMarker( point, icon );
	GEvent.addListener( marker, "click", function(){
		marker.openInfoWindowHtml( "<h4>Listing " + num + ":<\/h4>" + address );
	});
	return marker;
}
function createAddress( name, street, city, state, zip ){
	address = name + "<br/>" + street + "<br/>" + city
	+ ", " + state + " " + zip;
	return address;
}
function load(){
	if(GBrowserIsCompatible()){
		if ($$('.noresults').length){
			 $("map").innerHTML = "<img src='/static/img/bg/noresults.jpg' /><p>There are no theaters within the selected<br />range of this zipcode.<br /><br />Increase mileage to see more results.<\/p>";
			return;
		}
		var addressList = document.getElementById("address-list");
		if (! addressList) return;
		var i = 0;
		var offset = 1;
		var length = addressList.rows.length - offset;
		var points = new Array( length );
		var addresses = new Array( length );
		for(i = offset; i < addressList.rows.length; i++){
			var row = addressList.rows[i];
			var name = row.cells[3].innerHTML;
			var street = row.cells[4].innerHTML;
			var city = row.cells[5].innerHTML;
			var state = row.cells[6].innerHTML;
			var zip = row.cells[7].innerHTML;
			var latitude = parseFloat( row.cells[8].innerHTML );
			var longitude = parseFloat( row.cells[9].innerHTML );
			var point = new GLatLng( latitude, longitude );
			points[i - offset] = point;
			addresses[i - offset] = createAddress( name, street, city, state, zip );
		} // end for
		var map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.setCenter(points[0], 15);
		var bounds = map.getBounds();
		var icon = new GIcon();
		icon.image = "/static/img/icon.star.png";
		icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		icon.iconSize = new GSize( 20, 34 );
		icon.shadowSize = new GSize( 37, 34 );
		icon.iconAnchor = new GPoint( 9, 34 );
		icon.infoWindowAnchor = new GPoint( 9, 2 );
		icon.infoShadowAnchor = new GPoint( 18, 25 );
		for(i = 0; i < length; i++){
			var point = points[i];
			map.addOverlay(createMarker(point, i+ 1, addresses[i], icon ));
			bounds.extend(point);
		}
		var sw = bounds.getSouthWest();
		var ne = bounds.getNorthEast();
		var south = sw.lat();
		var west = sw.lng();
		var north = ne.lat();
		var east = ne.lng();
		var lngCtr= (west+east) / 2;
		var latCtr= (south+north) / 2;
		var zoom = map.getBoundsZoomLevel(bounds);
		map.setCenter(new GLatLng( latCtr, lngCtr), zoom);
	} // end if
} // end load()


// function switchDiv()
//  this function takes the id of a div
//  and calls the other functions required
//  to show that div
//
function switchDiv(div_id)
{
  var style_sheet = getStyleObject(div_id);
  if (style_sheet)
  {
    hideAll();
    changeObjectVisibility(div_id,"visible");
	document.getElementById("radioSearch").style.height = 58 + 'px';
  }
  else 
  {
    alert("sorry, this only works in browsers that do Dynamic HTML");
  }
}

// function hideAll()
//  hides a bunch of divs
//
function hideAll()
{
   changeObjectVisibility("city","hidden");
   changeObjectVisibility("state","hidden");
   changeObjectVisibility("zip","hidden");
   changeObjectVisibility("dma","hidden");
}

// function getStyleObject(string) -> returns style object
//  given a string containing the id of an object
//  the function returns the stylesheet of that object
//  or false if it can't find a stylesheet.  Handles
//  cross-browser compatibility issues.
//
function getStyleObject(objectId) {
  // checkW3C DOM, then MSIE 4, then NN 4.
  //
  if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
   }
   else if (document.all && document.all(objectId)) {  
	return document.all(objectId).style;
   } 
   else if (document.layers && document.layers[objectId]) { 
	return document.layers[objectId];
   } else {
	return false;
   }
}

function changeObjectVisibility(objectId, newVisibility) {
    // first get a reference to the cross-browser style object 
    // and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
}
// -->