var map= null;
var maps= null;


function getWindowHeight() {
	if (window.self && self.innerHeight) {
		return self.innerHeight;
	}
	if (document.documentElement && document.documentElement.clientHeight) {
		return document.documentElement.clientHeight;
	}
	return 0;
}

function resizeMap() {
	var offset= 0;
	for (var elem= document.getElementById("map"); elem!=null; elem= elem.offsetParent) {
		offset+= elem.offsetTop;
	}
	var windowHeight= getWindowHeight();
	var height= windowHeight - offset - 10;
	if (height >= 0) {
		document.getElementById("map").style.height= height + "px";
	}
}


function onLoad() {
	if (GBrowserIsCompatible()) {
		map= new GMap(document.getElementById("map"));
		//map.addControl(new GMapTypeControl());
		map.addControl(new GLargeMapControl());
		map.addControl(new GScaleControl());
		resizeMap();
map.setCenter(new GLatLng(33.777078407386064, -84.39847469329834),15);

		mapGT();
	}
    	else {
		alert("Sorry, this map is not compatible with your browser.");
    	}
}

function clearMaps(){
	while (G_DEFAULT_MAP_TYPES.length>0)
		G_DEFAULT_MAP_TYPES.pop();
	if (maps!=null){
		map.removeControl(maps);
	}
	maps= new GMapTypeControl();
}

function cloneMapType(maptype){
	newtype= new GMapType();
	newtype.getErrorMessage= function(){ return "No data available"; }
	newtype.getName= maptype.getName;
	newtype.getMinimumResolution= maptype.getMinimumResolution;
	newtype.getMaximumResolution= maptype.getMaximumResolution;
	newtype.getProjection= maptype.getProjection;
	newtype.getCopyright= maptype.getCopyright;
	newtype.getLinkColor= maptype.getLinkColor;
	newtype.getTextColor= maptype.getTextColor;
	//layers:
	newtype.getTileLayers= maptype.getTileLayers;
	return newtype;
}



function mapGT() {
	clearMaps();

	//satellite:
	G_DEFAULT_MAP_TYPES.push(G_SATELLITE_MAP);

	//map:
	G_DEFAULT_MAP_TYPES.push(G_NORMAL_MAP);

	//GT
	gtmap= cloneMapType(G_HYBRID_MAP);
	gtmap.getName= function() { return "GT map"; }
	gtmap.getMinimumResolution= function() { return 13; }
	gtmap.getMaximumResolution= function() { return 17; }
	gtmap.getLinkColor= function() {return "black";}
	gtmap.getTextColor= function() {return "black";}
	//layers:
	gtlayer= new GTileLayer();
	gtlayer.getCopyright= function() {return "&copy;2006 GT";}
	gtlayer.isPng= function() { return false; }
	gtlayer.baseUrls= ["http://www-static.cc.gatech.edu/~pesti/gtmap/t-gt/"];
	gtlayer.getTileUrl= function(a, z) {
    		var c= (a.x + a.y) % this.baseUrls.length;
    		return this.baseUrls[c]+z+"/"+a.x+"-"+a.y+".png";
	} 
	gtlayer.getOpacity= function() { return 1; }
	var gtlayers= [G_NORMAL_MAP.getTileLayers()[0], gtlayer];
	gtmap.getTileLayers= function() { return gtlayers; }
	//install:
	G_DEFAULT_MAP_TYPES.push(gtmap);

	//GT + sat
	gt2map= cloneMapType(gtmap);
	gt2map.getName= function() { return "GT sat"; }
	//layers:
	gt2layer= new GTileLayer();
	gt2layer.getCopyright= gtlayer.getCopyright;
	gt2layer.isPng= gtlayer.isPng;
	gt2layer.baseUrls= gtlayer.baseUrls;
	gt2layer.getTileUrl= gtlayer.getTileUrl;
	gt2layer.getOpacity= function() { return 0.4; }
	var gt2layers= [G_HYBRID_MAP.getTileLayers()[0], gt2layer];
	gt2map.getTileLayers= function() { return gt2layers; }
	//install:
	G_DEFAULT_MAP_TYPES.push(gt2map);

	if (maps!=null){
		map.addControl(maps);
	}
	map.setCenter(new GLatLng(33.777078407386064, -84.39847469329834), 15, gtmap);
}