/**
 * @author toby
 */

 function MapList(map){
 	this.setListType("latest");
	this.setListTitle("Recent Posts");
	this.setListTitleElement("h3");
	this.setListElement("ol");
	this.setListElementId("recent-posts");
	this.setListHighlightId("recent-posts-current");
	this.setListWrapper("div");
	this.setListWrapperId("recent-posts-wrapper");
	this.map = map;
 }
 
 MapList.prototype.loadList = function(){
 	this.getListWrapper().setAttribute("id",this.getListWrapperId());
	this.getListTitleElement().appendChild(this.getListTitle());
	this.getListElement().setAttribute("id",this.getListElementId());
	
	this.getListWrapper().appendChild(this.getListTitleElement());
	this.getListWrapper().appendChild(this.getListElement());
}

MapList.prototype.createListItem = function(listobject,template){
	this.listitem = document.createElement("li");
	this.listitem.innerHTML = this.templates[template].supplant(listobject);
	return this.listitem;
}

MapList.prototype.templates = {
	"thumbslist" : "<img src='{imgurl}' alt='{posttitle}' />",
	"categories" : "<a href='#' id={categoryid}>{category}</a>  ({total})"
}

MapList.prototype.addContinentList = function(category,allpoints,category_info){
	var thiscategoryid = category.replace(" ","_").toLowerCase();
	var thiscategory = { 	'category' : category, 
				'total' : category_info[category] + '',
				'categoryid' : '"' + thiscategoryid + '"'
	};
	var continents = ({
		'All' : { 'lat' : initLat, 'lng' : initLng, 'zoom' : initZoom },
		'North America' : { 'lat' : 37.857507, 'lng' : -95.976562, 'zoom' : 3 },	
		'Europe' : { 'lat' : 55.578345, 'lng' : 13.886719, 'zoom' : 3 },	
		'Australasia' : { 'lat' : -20.13847, 'lng' : 131.835938, 'zoom' : 3 },
		'Oceania' : { 'lat' : -20.13847, 'lng' : 131.835938, 'zoom' : 3 },	
		'Asia' : { 'lat' : 55.37911, 'lng' : 75.585938, 'zoom' : 2 },	
		'Africa' : { 'lat' : 1.933227, 'lng' : 20.566406, 'zoom' : 3 },	
		'South America' : { 'lat' : -26.431228, 'lng' : -66.445312, 'zoom' : 3 },
                'Antarctica' : { 'lat' : -75, 'lng' : 180, 'zoom' : 2 }
	});
	thiscategory.listitem = this.createListItem(thiscategory,"categories");
	var map = this.map;
	thiscategory.listitem.onclick = function(){
		if(map.getState() == "view"){
			map.map.closeInfoWindow();
			map.setLatitude(continents[thiscategory.category].lat);
			map.setLongitude(continents[thiscategory.category].lng);
			map.setLocation();
			map.map.setZoom(continents[thiscategory.category].zoom);	
			map.map.panTo(map.getLocation());
		}
		return false;
	}
	this.getListElement().appendChild(thiscategory.listitem);			
}

MapList.prototype.setListType = function(listtype){
	this.listtype = listtype;
}

MapList.prototype.getListType = function(){
	return this.listtype;
}

MapList.prototype.setListTitle = function(listtitle){
	this.listtitle = document.createTextNode(listtitle);
}

MapList.prototype.getListTitle = function(){
	return this.listtitle;
}

MapList.prototype.setListTitleElement = function(listtitle_el){
	this.listtitle_el = document.createElement(listtitle_el);
}

MapList.prototype.getListTitleElement = function(){
	return this.listtitle_el;
}

MapList.prototype.setListElement = function(list_el){
	this.list_el = document.createElement(list_el);
}

MapList.prototype.getListElement = function(){
	return this.list_el;
}

MapList.prototype.setListElementId = function(listelementid){
	this.listelementid = listelementid
}

MapList.prototype.getListElementId = function(){
	return this.listelementid;
}

MapList.prototype.setListHighlightId = function(listhighlightid){
	this.listhighlightid = listhighlightid
}

MapList.prototype.getListHighlightId = function(){
	return this.listhighlightid;
}


MapList.prototype.setListWrapper = function(listwrapper){
	this.listwrapper = document.createElement(listwrapper);
}

MapList.prototype.getListWrapper = function(){
	return this.listwrapper;
}

MapList.prototype.setListWrapperId = function(listwrapperid){
	this.listwrapperid = listwrapperid
}

MapList.prototype.getListWrapperId = function(){
	return this.listwrapperid;
}

