function Map(){
	this.setLatitude(initLat);
	this.setLongitude(initLng);
	this.setZoomLevel(initZoom);
	this.setMapDiv("mapdiv");
	this.setMapType(G_SATELLITE_MAP);
	this.setWidth(500);
	this.setHeight(300);
	this.allpoints = [];
	this.setWrapper("map-wrapper");
	this.setState("view");
	this.allmarkers = [];
	this.ll = "";
}

Map.prototype.prepare = function(){
	var qs = queryString();
	if(qs["ll"]){
		this.ll = qs["ll"].split(",");
		this.setLatitude(this.ll[0]);
		this.setLongitude(this.ll[1]);	
		this.setZoomLevel(10);
	}
	this.setLocation();
	this.mapdiv.style.width = this.getWidth() + "px";
	this.mapdiv.style.height = this.getHeight() + "px";
}

Map.prototype.loadMap = function(){
	this.prepare();
	if(GBrowserIsCompatible()){
		this.map = new GMap2(this.getMapDiv());
		this.map.setCenter(this.getLocation(), this.getZoomLevel());
		this.map.setMapType(this.getMapType());
		this.map.enableDoubleClickZoom();
		changeBodyClass("loading", "standby");
	}
	else {
		alert('Your browser is unable to support Google Maps. You will need to upgrade to a more recent browser version to view this interactive.');
	}
}

Map.prototype.loadPoints = function(datasource){
    var map = this;
    this.markermngr = new GMarkerManager(map.map);
    var request = GXmlHttp.create();

    request.open('GET',datasource,true);
    request.onreadystatechange = function(){
        if(request.readyState == 4 && (request.status == 200 ||
request.status == 302)){
            var pointdata = request.responseText;
            eval(pointdata);
            if(points!="empty"){
                i=0;
                for(id in points){
                    map.allpoints[i] = new Point(points[id],map);
                    map.allpoints[i].initialise();
                    map.allmarkers.push(map.allpoints[i].marker);
                    i++;
                }
            }
            map.category_info = category_info;

            var thumbgallery = new MapList(map);
            thumbgallery.setListType("thumbsgallery");
            thumbgallery.setListTitle("World Beach Project Gallery");
            thumbgallery.setListElementId("thumb-gallery");
            thumbgallery.setListHighlightId("thumb-gallery-current");
            thumbgallery.setListWrapperId("thumb-gallery-wrapper");

            var categories = new MapList(map);
            categories.setListType("continents");
            categories.setListTitle("Continents");
            categories.setListElementId("categories");
            categories.setListHighlightId("categories-current");
            categories.setListWrapperId("categories-wrapper");

            map.addMapList(categories);
            map.addMapList(thumbgallery);

        }
    }
    request.send(null);
}


Map.prototype.addSingleMarker = function(lat,lng){
	var querystr = lat + "," + lng;
	var point = new GLatLng(lat,lng);
	var marker = new GMarker(point);
	this.map.addOverlay(marker);
	GEvent.addListener(marker,'click',
		function(){
			document.location = "index.php?ll=" + querystr;
		}
	);
}

Map.prototype.addMapList = function(maplist){
	maplist.loadList();
	switch(maplist.getListType()){
		case "thumbsgallery":
		var num_thumbs;
		if (this.allpoints.length < 6) {
			num_thumbs = this.allpoints.length;
		} else {
			num_thumbs = 6;
		}
		for(var i = 0; i < num_thumbs; i++){
			var listitem = this.allpoints[i].createPointsListItem(maplist,"thumbslist");
			maplist.getListElement().appendChild(listitem);
		}
		var lightbox = document.createElement("a");
		lightbox.setAttribute("href","index.php?section=1");
		lightbox.setAttribute("id","lightbox_link");
		lightbox.appendChild(document.createTextNode("View all contributions"));
		maplist.getListWrapper().appendChild(lightbox);	
		break;
		case "latestposts":
			for(id in this.allpoints){
				var listitem = this.allpoints[id].createPointsListItem(maplist,"pointslist");
				maplist.getListElement().appendChild(listitem);
			}
		break;
		case "continents":
			for(id in this.category_info){
				if(id!=="All")
				maplist.addContinentList(id, this.allpoints, this.category_info);
			}
			break;
	}
	this.getWrapper().appendChild(maplist.getListWrapper());
}

Map.prototype.uploadForm = function(longitude,latitude){
	this.uploaddiv = document.createElement("div");
	this.uploaddiv.setAttribute("id","uploadformdiv");
	this.uploaddiv.innerHTML = "<p>" + uploadLinkMsg + "</p>";
	this.uploadform = document.createElement("form");
	this.uploadform.setAttribute("action","index.php");
	this.uploadform.setAttribute("method","post");
	this.uploadform.setAttribute("name","newPostForm");
	this.uploadform.onsubmit = function(){submit();};
	this.uploadform.innerHTML = '<input type="hidden" name="section" id="section" value="3" />'
	+ '<input type="hidden" name="longitude" id="longitude" value="' + longitude + '" />'
	+ '<input type="hidden" name="latitude" id="latitude" value="' + latitude + '" />'
	+ '<tr><td class="col1"></td><td class="col2"><input type="submit" value="Submit Your Photos" id="mapsubmit" /></td></tr>'
	+ '</table>';
	this.uploaddiv.appendChild(this.uploadform);
	return this.uploaddiv;
}

Map.prototype.templates = {
}

Map.prototype.setLocation = function(){
	this.location = new GLatLng(this.getLatitude(),this.getLongitude());
}

Map.prototype.getLocation = function(){
	return this.location;
}

Map.prototype.setLatitude = function(latitude){
	this.latitude = latitude;
}

Map.prototype.getLatitude = function(){
	return this.latitude;
}

Map.prototype.setLongitude = function(longitude){
	this.longitude = longitude;
}

Map.prototype.getLongitude = function(){
	return this.longitude;
}

Map.prototype.setZoomLevel = function(zoomlevel){
	this.zoomlevel = zoomlevel;
}

Map.prototype.getZoomLevel = function(){
	return this.zoomlevel;
}

Map.prototype.setMapDiv = function(mapdiv){
	this.mapdiv = document.getElementById(mapdiv);
}

Map.prototype.getMapDiv = function(){
	return this.mapdiv;
}

Map.prototype.setWrapper = function(wrapper){
	this.wrapper = document.getElementById(wrapper);
}

Map.prototype.getWrapper = function(){
	return this.wrapper;
}

Map.prototype.setMapType = function(maptype){
	this.maptype = maptype;
}

Map.prototype.getMapType = function(){
	return this.maptype;
}

Map.prototype.setWidth = function(width){
	this.width = width;
}

Map.prototype.getWidth = function(){
	return this.width;
}

Map.prototype.setHeight = function(height){
	this.height = height;
}

Map.prototype.getHeight = function(){
	return this.height;
}

Map.prototype.setState = function(state){
	this.state_ = state;
}

Map.prototype.getState = function(){
	return this.state_;
}








