 function mapLayer(name, url, iconURL, iconSelectedURL, iconHighlightedURL, countId, countVar, mapObj, useIdForIconName){
	
	this.name = name;
	this.url = url;
	this.iconURL = iconURL;
	this.mapObj = mapObj;
	this.countId = countId;
	this.visible = true;
	this.iconSelectedURL = iconSelectedURL; 
	this.iconHighlightedURL = iconHighlightedURL; 
	
	this.countVar = countVar;
	this.useIdForIconName = useIdForIconName;
}

mapLayer.prototype.initialise = function(last){	
	this.last = last;
	this.loadData();
}

mapLayer.prototype.switchLayer = function(){
	if(this.visible){
		this.hide();
		this.visible = false;		
	}else{
		this.show();
		this.visible = true;
	}
}

mapLayer.prototype.getMarkerById = function (whichId) {
	for(var i=0; i<this.data.length; i++){
		if(this.data[i].getAttribute('id') == whichId){
			
			return this.data[i];
			
		}
	}
}

mapLayer.prototype.show = function(){
	for(var i=0; i<this.data.length;i++){
		this.data[i].show();
	}
	
//	CorrectPNG();	
}

mapLayer.prototype.hide = function(){
	for(var i=0; i<this.data.length;i++){
		this.data[i].hide();
	}
}

mapLayer.prototype.loadData = function(){
	var obj = this;
	var getRef = glow.net.get(this.url, {
	    onLoad: function(response) {
	       obj.parseData(response.xml());
	    },
	    onError: function(response) {
	        alert("Error getting file: " + response.responseXML());
	    }
	});
}


mapLayer.prototype.setData = function(pointLayer){

	this.data = pointLayer;
	
	if(this.last) {	
		this.mapObj.layersLoaded();	

	}	
}

mapLayer.prototype.updateCount = function(howMany) {
	this.countVar.addTo(howMany);
	
	document.getElementById(this.countId).innerHTML = '(' + this.countVar.count + ')';
}

mapLayer.prototype.parseData =function (xmlDoc){	
		var points = xmlDoc.getElementsByTagName("item");		

		var pointLayer = new Array();
		
		
		for(var i=0;i<points.length;i++){
			var lat,lng,img,guid,title,link,description,emp_media_type,emp_media_id,related_links, particular_icon, clickheretext, inactive;
	
			guid=points[i].getElementsByTagName("guid")[0].firstChild.nodeValue;
			
			
			if (xmlDoc.getElementsByTagNameNS  && ! isFF3()) {
				lat=points[i].getElementsByTagName("lat")[0].firstChild.nodeValue;
				lng=points[i].getElementsByTagName("long")[0].firstChild.nodeValue;
			
			}else{
				lat=points[i].getElementsByTagName("geo:lat")[0].firstChild.nodeValue;
				lng=points[i].getElementsByTagName("geo:long")[0].firstChild.nodeValue;
			}
			
			title=points[i].getElementsByTagName("title")[0].firstChild.nodeValue;
			if(points[i].getElementsByTagName("description")[0].firstChild){
				description=points[i].getElementsByTagName("description")[0].firstChild.nodeValue;
			}
			

			link=(points[i].getElementsByTagName("link")[0])?points[i].getElementsByTagName("link")[0].firstChild.nodeValue:null;
			

		 	var related_links = points[i].getElementsByTagName('related_link');
			var related = new Array();
				if(related_links){					
					for(var l=0;l<related_links.length;l++){
					related.push( {url:related_links[l].getAttribute('href'),text:related_links[l].firstChild.nodeValue});
				}
			}
			
			// If using the guid to construct icon, we need to work out what icon to use for this one
			var myIconUrl, mySelectedIconUrl;
			
			if(this.useIdForIconName)
			{

				myIconUrl = lc2s_mapkey.getIconFromPlace(guid);
				mySelectedIconUrl = lc2s_mapkey.getSelectedIconFromPlace(guid);
				myHighlightedIconUrl = lc2s_mapkey.getHighlightedIconFromPlace(guid);
				
			}else
			{
				myIconUrl = this.iconURL;
				mySelectedIconUrl = this.iconSelectedURL;
				myHighlightedIconUrl = this.iconHighlightedURL;
			}
			
			try { 
				var tmp = points[i].getElementsByTagName("clickheretext")[0].firstChild.nodeValue;
				if(tmp!=null&&tmp.length>0)
					clickheretext = tmp;
			}
			catch(e) { }
			
			try { 
				var tmp = points[i].getElementsByTagName("inactive")[0].firstChild.nodeValue;
				if(tmp!=null&&tmp.length>0)
					inactive = true;
				else
					inactive = false;
			}
			catch(e) { }
			
			pointLayer.push(this.mapObj.createMarker(guid,lat,lng,title,description,img,link,emp_media_type,emp_media_id,related, myIconUrl, mySelectedIconUrl, myHighlightedIconUrl, clickheretext, inactive));
		}

		this.setData(pointLayer);
		//this.updateCount(i);
		
	
}
