// CustomGetTileUrl returns the URL for a tile, custom or google-----
function CustomGetTileUrl(a,b) 
{ 
	var z = 17 - b;

	// If tiles are not in our range (ie Millersville area), use google tiles
	if ((z == 1 && a.x <= 18869 && a.x >= 18866 && a.y <= 24812 && a.y >= 24809) || 
		 (z == 0 && a.x <= 37739 && a.x >= 37732 && a.y <= 49626 && a.y >= 49619)) 
		return "http://www.millersville.edu/directions/img/maptiles/" + a.x + "_" + a.y + "_" + z + ".gif";
	else
		return G_NORMAL_MAP.getTileLayers()[0].getTileUrl(a,b);
}

//start copyright----------------------------------------------------
function setCopyright()
{
	var copyright=new GCopyright( 1, new GLatLngBounds(new GLatLng(39.998344762043594, -76.3653016090393), new GLatLng(39.99872283336272, -76.34457349777222)), 0, "©Millersville University");
	var copyrightCollection = new GCopyrightCollection("Chart");
	copyrightCollection.addCopyright(copyright);
	return copyrightCollection;
}


// ###########################################################
// Start creating map
// -----------------------------------------------------------

if (GBrowserIsCompatible()) 
{
	batch = [];	// holds array of markers
	// Initialize point var
	var boyer = new GLatLng(39.997588613125686, -76.35656833648682);

	var tilelayers = [new GTileLayer(setCopyright() , 0, 17)];
	tilelayers[0].getTileUrl = CustomGetTileUrl;

	custommap = new GMapType(tilelayers, new GMercatorProjection(18), "Chart", {errorMessage:"No data available"});
	
	var map = new GMap2(document.getElementById("map"));
	map.addMapType(custommap);
	map.setCenter(boyer, 16, custommap);		// startpoint, start zoom, start map
	map.addControl(new GSmallMapControl());	// Add + / - for zoom

	// 1st Tab
	loc ='<div style="white-space:nowrap; width:260px; font-size:11px;"><strong>Help Desk - Boyer Computer Building</strong><p>37 West Frederick St.<br />Millersville, PA 17551</p></div>';

	// 2nd tab
	//desc = '<div style="margin-top: 20px; width: 350px; height: 150px; white-space: normal; overflow:scroll; overflow-x:hidden;"><p><a href="http://www.millersville.edu/~infotech/help/">Submit/Update</a> a request for help</p><p><a href="http://www.millersville.edu/~infotech/about/location.php">Walk-In</a> - Location and hours of the nearest technical support center.</p><p>Call (717)871-2371 - Call the Help Desk to speak with a support person.</p></div>';

	// Our info window content
	var infoTabs = [
	  new GInfoWindowTab("Location", loc)
	];

	// Create the marker's icon
	var icon = new GIcon();
	icon.image = 'http://www.millersville.edu/directions/img/yellowcirclemarker.png';
	icon.iconSize = new GSize(24, 24);
	icon.iconAnchor = new GPoint(16, 16);
	icon.infoWindowAnchor = new GPoint(10, 15);

	opts = { 
		 "icon"       : icon,
		 "clickable"  : true,
		 "labelOffset": new GSize(-11, -11)
	};

	var marker = new GMarker(map.getCenter(), opts);

	// Add the click event to the marker
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowTabsHtml(infoTabs);
	});

	// Load the marker and open its info window
	map.addOverlay(marker);
	marker.openInfoWindowTabsHtml(infoTabs);
}
else 
	alert("Sorry, our map is not compatible with this browser");
