/**
 * @author toby
 */
function Point(point,thismap){
	this.map = thismap;
	this.latitude = point["latitude"];
	this.longitude = point["longitude"];
	this.creator = point["creator"];
	this.posttitle = point["posttitle"];
	this.description = point["description"];
	this.category = point["category"];
	this.date = point["date"];
	this.imgurl = point["imgurl"];
	this.link = point["link"];
	this.visible = false;
}

Point.prototype.initialise = function(){
    this.point = new GLatLng(this.latitude,this.longitude);
    this.icon = new this.Icon(this);
    this.marker = new GMarker(this.point,this.icon);
    this.markerhtml = this.templates["beachart"].supplant(this);
    var marker = this.marker;
    var markerhtml = this.markerhtml;

    GEvent.addListener(this.marker,'click',
        function(){
            marker.openInfoWindowHtml(markerhtml);
        }
    );

    this.map.map.addOverlay(this.marker);
}


Point.prototype.templates = {
	"beachart" : "<div id='markercontent'><h3><a href='{link}'>{posttitle}</a></h3><div><img src='{imgurl}' alt='{posttitle}'><a href='{link}'>See all pictures</a></div><p>{description}</p><p>Created by: {creator}</p></div>",
	"pointslist" : "<p><strong>{posttitle}</strong><br />Created by: {creator}<br />Continent: {category}</p>",
	"thumbslist" : "<img src='{imgurl}' alt='{posttitle}'>",
	"categories" : "<a href='#' id='category'>{category}</a>"
}

Point.prototype.createPointsListItem = function(maplist,template){
	this.listitem = maplist.createListItem(this,template);
	
	var marker = this.marker;
	var point = this.point;
	var latitude = this.latitude;
	var longitude = this.longitude;
	var markerhtml = this.markerhtml;
	var map = this.map;
	var listitem = this.listitem;
	
	this.listitem.onclick = function(){
		var toppost = document.getElementById(maplist.getListHighlightId());
		if(toppost)toppost.removeAttribute("id");
		this.setAttribute("id",maplist.getListHighlightId());
		switch(maplist.getListType()){
			case "thumbsgallery":
				if(map.getState() == "view"){
				//if(document.getElementById("instructions")) document.getElementById("instructions").style.display = "none";
				map.setZoomLevel(10);
				map.setLatitude(latitude);
				map.setLongitude(longitude);
				var center = new GLatLng(map.getLatitude(),map.getLongitude());
				map.map.setCenter(center,map.getZoomLevel());
				var centerpoint = new GPoint(375,100);
				var centerll = map.map.fromContainerPixelToLatLng(centerpoint);
				map.map.panTo(centerll);
				
				marker.openInfoWindowHtml(markerhtml);
				}
				return false;
			break;
		}
	}
	
	this.listitem.onmouseover = function(){
		changeCursor(this,"pointer");
	}

	return this.listitem;
}

Point.prototype.Icon = function(thispoint){
	var iconimg, iconimgshadow, iconimgpath;
	iconimgpath = "/apps/map_uploads/images/";
	iconimgshadow = "icon-shadow.png";
	switch(thispoint.category){
		case "North Americ":
		iconimg = "icon-palepurple.png";
		break;
		case "Europe":
		iconimg = "icon-paleblue.png";
		break;
		case "Australasia":
		case "Oceania":
		iconimg = "icon-palepink.png";
		break;
		case "Asia":
		iconimg = "icon-grey.png";
		break;
		case "Africa":
		iconimg = "icon-pink.png";
		break;
		case "South America":
		iconimg = "icon-darkpurple.png";
		break;
		case "Antarctica":
                iconimg = "icon-palegreen.png";
                break;
		default:
		iconimg = "icon-palepurple.png";
		break;
	}
	this.icon = new GIcon();
	this.icon.image = iconimgpath + iconimg;
	this.icon.iconSize = new GSize(20,32);
	//this.icon.shadow = iconimgpath + iconimgshadow;
	//this.icon.shadowSize = new GSize(37,34);
	this.icon.iconAnchor = new GPoint(10, 32);
	this.icon.infoWindowAnchor = new GPoint(20,0);
}


