function Photo(param){
	this.root_url = param.root_url;
	this.xhr = new XHRequest({method:'get',onComplete:this.onGetRecent.bind(this)});
}
Photo.prototype = {
	getRecent : function(limit, uid){
		var qs = '&limit='+limit+'&user_id='+uid;
		this.xhr.send(this.root_url+'services?method=woophy.photo.getRecent', qs);
	},
	onGetRecent : function(text, xml){
		var photos = xml.getElementsByTagName('photo');	
		if(photo = photos[0]){
			var el = $('MotM');
			while(el.firstChild) el.removeChild(el.firstChild);//remove old nodes
			var id = this.getDataById(photo,'id');
			
			var image = document.createElement('img');
			image.setAttribute('src', this.getDataById(photo,'thumb_url'));
			el.appendChild(image);

			var a = document.createElement('a');
			var user_name = this.getDataById(photo, 'user_name');
			a.setAttribute('href', this.root_url + 'member/' +encodeURIComponent(user_name));
			a.appendChild(document.createTextNode(user_name));
			el.appendChild(a);
			el.appendChild(document.createElement('br'));
			el.appendChild(document.createElement('br'));
			el.appendChild(document.createTextNode(this.getDataById(photo,'city_name')+', '+this.getDataById(photo,'country_name')));
			el.appendChild(document.createElement('br'));
			var s = document.createElement('span');
			s.className= 'photodate';
			s.appendChild(document.createTextNode('Added on ' + this.formatDate(this.getDataById(photo,'date'))));
			el.appendChild(s);

			var d = document.createElement('div');
			d.style.clear = 'both';
			el.appendChild(d);
		}
	},
	getDataById : function(xml, id){
		var e,c;
		e = xml.getElementsByTagName(id);
		if(e.length) if(c = e.item(0).firstChild) return c.data;
		return '';
	},
	formatDate : function(str){/*input: '2006-06-03 14:00:51', returns: June 3rd, 2006*/
		var s = '',a = str.split(/[-: ]/),d,n,m,sf,i;
		if(a.length>=3){
			m = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
			s += (n=m[parseInt(a[1],10)-1])?n+' ':'';
			if(d=parseInt(a[2],10)){
				s += d;
				sf = ['th','st','nd','rd'];
				i = d%10;
				s += sf[i>sf.length-1?0:i];
			}
			s += ', '+a[0];
		}
		return s;
	}
};
