google.load("maps", "2.x");
google.setOnLoadCallback(gooInitialize);


var map;
var bounds;
var ICON_DIR = "icons/";
	
var arrMarkers = new Array()
var arrListItems = new Array();

var g_arr = new Array();


var currentItemID;
//g_arr[0] = new Array();
//g_arr[0].line = line0;

var swlat, swlng, nelng, nelat;
var boundaries;

function gooInitialize() {
	map = new google.maps.Map2(document.getElementById("map"));
	bounds = new GLatLngBounds();
//	map.addControl(new GSmallMapControl());		
//	map.addControl(new GMapTypeControl());	
	map.addMapType(G_PHYSICAL_MAP);
	map.setMapType(G_PHYSICAL_MAP);

	G_PHYSICAL_MAP.getMinimumResolution=function() {
	  return 4;
	
	};
	
	G_PHYSICAL_MAP.getMaximumResolution=function() {
	  return 13;
	
	}; 

	map.setCenter(new google.maps.LatLng(55.3438620637,-131.675949), 13);
	map.disableDoubleClickZoom();
	swlat = 55.3140
	swlng = -131.772;
	nelat = 55.3886;
	nelng= -131.6186;
		 
	boundaries = new GLatLngBounds(new GLatLng(swlat,swlng), new GLatLng(nelat,nelng));
	//centerAndZoomOnBounds(bounds);
	clickItem(0);
	
	fooResize();
}


function clickItem(id){
	map.clearOverlays();
	var line = new GGroundOverlay("http://dannonguyen.com/projects/maptemplate/images/linecut-"+id+".png", boundaries);
	map.addOverlay(line);
	
	
	$(".listItem").each( function(){
	
		var t = $(this);
		
		if (t.attr("id") != "listItem"+id ){
		
		//	t.find('p').slideUp("slow");

			$(this).css("borderColor","#999");
			//t.find(".clicktosee").show();
			$(this).animate({backgroundColor: "#ffffff" }, 440);
			//t.css("backgroundColor", "#fff");
			
		}else{
		
			currentItemID = "listItem"+id;
			//t.find(".clicktosee").hide();
			var b = t.find(".highlight").css("color");
			$(this).css("borderColor",b);			
			$(this).animate({backgroundColor: "#fffddf" }, 440 );
			//t.css("backgroundColor", "#fffdd9");
		//	t.find('p').slideDown("slow");
			var h = t.find(".cost").html();
			$("#priceTag").html(h);
		}
	
	});
	
}





function displayMarkersOnMap(arr){
	//pre: arr contains markers
	//post: markers added to map
	
	for(var id in arr){
		var m = arr[id];
		map.addOverlay(m);
		bounds.extend(m.getLatLng());	
	}
	
	
}



function centerAndZoomOnBounds(bounds) { //function for centering map around all markers
	var center = bounds.getCenter();
	var newZoom = map.getBoundsZoomLevel(bounds);
	if (map.getZoom() != newZoom) {
	
		map.setCenter(center, newZoom);
	} else {
		map.panTo(center);
	}
} 




function createMarker(arr, lati, longi, id, iconi, text, param){
	//pre: m is an array that contains these things:
	//latitude, longitude
	//optional: icon
	//optional: text is what should be in the popup box
	//optional: extra parameters
	//post: A new marker added to the passed in arr
	
	
	iconi = !isEmpty(iconi) ? iconi : google.maps.G_DEFAULT_ICON;



	var pt = new google.maps.LatLng(lati, longi);
	var m = new GMarker( pt, iconi);
	m.id = id;//;lati+"_"+longi;
	trace("id: " + m.id);
	m.txt = text; 
	
	function gotoPoint(){
	
		clickPoint(m.id);
	}
	

	GEvent.addListener(m, 'click', gotoPoint);	

	arr[m.id] = m;
	
}


function clickPoint(id){
	//what happens when you click on a marker or want to goto a marker
	
	
	var m = arrMarkers[id];
	map.panTo(m.getLatLng());
	
	if(!isEmpty(m.txt)){
		m.openInfoWindowHtml(m.txt);
	}
	
	trace(id);
}



