// MGeoRSS: GMaps API extension 
// copyright 2006 Mikel Maron (email: mikel_maron yahoo com)
// http://brainoff.com/gmaps/mgeorss.html
// This work is public domain


function MGeoRSS(type){
	this.type=type;
	this.IconStart = new GIcon();
	if (this.type == "photo")
	{
		this.IconStart.image = "images/silk/icons/camera.png";
		//this.IconStart.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		this.IconStart.iconSize = new GSize(16, 16);
		this.IconStart.shadowSize = new GSize(16, 16);
		this.IconStart.iconAnchor = new GPoint(8, 8);
		this.IconStart.infoWindowAnchor = new GPoint(16, 1);
	}
	else
	{
		this.IconStart.image = "images/dd-start.png";
		this.IconStart.iconSize = new GSize(20, 34);
		this.IconStart.iconAnchor = new GPoint(10, 33);
		this.IconStart.infoWindowAnchor = new GPoint(10, 33);
	}
}
MGeoRSS.prototype.initialize=function(map) {
    this.map = map;
    this.rssurl = false;
    this.request = false;
}
MGeoRSS.prototype.load=function(url,proxyurl) {
	if (this.request != false) { return; }
 	this.rssurl = url;
    this.request = createRequestObject();
	if (proxyurl != undefined) {
      		this.request.open("GET",proxyurl + this.rssurl,true);

	} else {
		this.request.open("GET",this.rssurl, true);
	}
	var m = this;
	this.request.onreadystatechange = function() {
		m.callback();
	}
	this.request.send(null);
}
MGeoRSS.prototype.callback = function() {
	if (this.request.readyState == 4) {
		if (this.request.status == "200") {
			var xmlDoc = this.request.responseXML;
	
			var items = xmlDoc.getElementsByTagName("item");
			for (var i = 0; i < items.length; i++) {
				try {
					var marker = this.createMarker(items[i]);
					this.map.addOverlay(marker);
				} catch (e) {
				}
			}
		}
		this.request = false;
	}
}
MGeoRSS.prototype.createMarker = function(item) {
	
	if (this.type == "photo")
	{
		var description = item.getElementsByTagName("description")[0].childNodes[0].nodeValue;
		var title = "";
	}
	else 
	{
		var description = "";
		var title = item.getElementsByTagName("title")[0].childNodes[0].nodeValue;
	}
	var link = item.getElementsByTagName("link")[0].childNodes[0].nodeValue;
	try {
		var description = item.getElementsByTagName("load")[0].childNodes[0].nodeValue;
	} catch (e) {}

	/* namespaces are handled by spec in moz, not in ie */
	if (!window.ActiveXObject) {
		var lat = item.getElementsByTagNameNS("http://www.w3.org/2003/01/geo/wgs84_pos#","lat")[0].childNodes[0].nodeValue;
		var lng = item.getElementsByTagNameNS("http://www.w3.org/2003/01/geo/wgs84_pos#","long")[0].childNodes[0].nodeValue;
	} else {
		var lat = item.getElementsByTagName("geo:lat")[0].childNodes[0].nodeValue;
		var lng = item.getElementsByTagName("geo:long")[0].childNodes[0].nodeValue;
	}

	var point = new GPoint(parseFloat(lng), parseFloat(lat));
	var marker = new GMarker(point,this.IconStart);  
	//var marker = new GMarker(point);
	if (this.type == "photo")
	{
		var html = title + "<a target=\"_blank\" href=\"" + link + "\">" + description + "</a><p/>";
	}
	else 
	{
		var html = "<a target=\"_parent\" href=\"" + link + "\">" + title + "</a><p/>" + description;
	}
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
	});
	return marker;
}


GMap.prototype.addMGeoRSS=function(a) {
    a.initialize(this);

}



