/**
 * @author toby
 */
function Point(point,thismap,id){
	this.map = thismap;
	this.id = id;
	this.latitude = point["latitude"];
	this.longitude = point["longitude"];
	this.photo_title = point["photo_title"];
	this.photo_id = point["photo_id"];
	this.photo_secret = point["photo_secret"];
	this.photo_server = point["photo_server"];
	this.owner = point["owner"];
	this.owner_name = point["owner_name"];
	this.date_taken = point["date_taken"];
	this.photo_tags = point["photo_tags"];
	this.photo_tag_list = "";
	this.visible = false;
	this.zoomlevelshow;
}

Point.prototype.initialise = function(){
	
	this.lat_lng = new GLatLng(this.latitude,this.longitude);
	this.icon = new this.Icon(this);
	this.marker = new GMarker(this.lat_lng,this.icon);
	
	//this.photo_tags = this.photo_tags.trim();
	var tag_array = this.photo_tags.split(" ");
	for(tag in tag_array){
			var tagobj = { 'tag' : tag_array[tag] }
			tag = this.templates["tagLink"].supplant(tagobj);
			this.photo_tag_list += tag;
	}
	
	this.markerhtml = this.templates["imageWindow"].supplant(this);
	
	var map = this.map;
	var marker = this.marker;
	var markerhtml = this.markerhtml;
	
	GEvent.addListener(this.marker,'click',
		function(){
			closePhotoInfo();
			marker.openInfoWindowHtml(markerhtml);
		}
	);

	this.show = function(){
		if(!this.visible){
			map.map.addOverlay(marker);
			this.visible = true;
		}
	}
	
	this.hide = function(){
		if(this.visible){
			map.map.removeOverlay(marker);
			this.visible = false;
		}
	}
	
	this.openwindow = function(){
		marker.openInfoWindowHtml(markerhtml);
	}
	
}

Point.prototype.templates = {
	"imageWindow" : "<div id=\"info-window\"><h3><a href=\"http://www.flickr.com/photos/{owner}/{photo_id}\" onclick=\"showPhotoInfo({id}); return false;\">{photo_title}</a></h3><p><div class=\"info_window_image\"><a href=\"http://www.flickr.com/photos/{owner}/{photo_id}\" onclick=\"showPhotoInfo({id}); return false;\"><img src=\"http://static.flickr.com/{photo_server}/{photo_id}_{photo_secret}_s.jpg\" alt=\"{photo_title}\" /></a></div>{photo_tag_list}</p><p class=\"photo_details\">Taken by <a href=\"http://www.flickr.com/people/{owner}\">{owner_name}</a> on {date_taken}</p></div>",
	"tagLink" : "<a href=\"#\" onclick=\"mapTagSearch('{tag}'); return false;\">{tag}</a> ",
	"photoInfo" : "<img src=\"http://static.flickr.com/{photo_server}/{photo_id}_{photo_secret}_m.jpg\" alt=\"{photo_title}\" /><dl><dt>Title</dt><dd>{photo_title}</dd><dt>Owner</dt><dd>{owner_name}</dd><dt>Date Taken</dt><dd>{date_taken}</dd><dt>Tags</dt><dd>{photo_tags}</dd><dt></dt><dd><a href=\"http://www.flickr.com/photos/{owner}/{photo_id}\" onclick=\"showLargePhoto({id}); return false;\" target=\"_blank\">Enlarge photo</a></dd><dt></dt><dd><a href=\"http://www.flickr.com/photos/{owner}/{photo_id}\" class=\"flickr-link\">View on flickr</a></dd></dl><a href=\"#\" id=\"close_photo_info\" onclick=\"closePhotoInfo(); return false;\">Close window</a>",
	"largeImageWindow" : "<img src=\"http://static.flickr.com/{photo_server}/{photo_id}_{photo_secret}.jpg\" alt=\"{photo_title}\" /><p><strong>{photo_title}</strong>, {owner_name}, {date_taken}</p>"
}

Point.prototype.Icon = function(thispoint,icontype){
	var iconimg, iconimgshadow, iconimgpath;
	this.icon = new GIcon();
	switch(icontype){
		case "buddy":
			iconimg = thispoint.buddy_icon;
			this.icon.image = iconimg;
			this.icon.iconSize = new GSize(40,40);
			this.icon.iconAnchor = new GPoint(40,40);
		break;
		default:
			iconimgpath = "images/";
			iconimgshadow = "icon-shadow.png";
			iconimg = "icon-pink.png";
			this.icon.shadow = iconimgpath + iconimgshadow;
			this.icon.image = iconimgpath + iconimg;
			this.icon.iconSize = new GSize(20,32);
			this.icon.shadowSize = new GSize(37,34);
			this.icon.iconAnchor = new GPoint(10, 32);
			this.icon.infoWindowAnchor = new GPoint(20,0);
		break;
	}
}

