/**
 * @namespace
 * Class Identity
 * 
 * This class is intended to map one of the identities of each User of the system
 * of this class.
 * <br /><br />
 * Created on 29/04/2009
 * 
 * @class Identity
 *
 * @param {XMLDocument} myFrakkingXML A marshalled identity
 *
 * @property {String} _displayName The display name for this identity
 * @property {Number} _timesViewed The number of times that the profile of this
 * identity has been viewed by other users.
 * @property {Number} _timesFollowed The amount of identities that are following
 * this one.
 * @property {Number} _timesFollowing The amount of identities that this one is
 * following
 * @property {Array} _followings An array of String containing the names of the
 * identities that this user is following
 * @property {Array} _followers An array of String containing the names of the 
 * identities that follow this user.
 * @property {String} _imageURL The URL for the image of this identity
 * @property {Number} rating The rating of this Identity, calculated from the
 * ratings of his/her layers
 * @property {String} _description A description for this identity
 * @property {String} _firstName The first name of this identity
 * @property {String} _lastName The last name of this identity
 * 
 * @author "Pablo Casado (pablo.casado@layers.com)"
 * @version <1.0>
 *  
 */
function Identity(){
	this._displayName = "";
	this._timesViewed = 0;
	this._timesFollowed = 0;
	this._timesFollowing = 0;
	this._followings = new Array();
	this._followers = new Array();
	this._imageURL = "";
	this._description = "";
	this._firstName = "";
	this._lastName = "";
	
}

Identity.prototype._displayName;
Identity.prototype._timesViewed;
Identity.prototype._timesFollowed;
Identity.prototype._timesFollowing;
Identity.prototype._followings;
Identity.prototype._followers;
Identity.prototype._imageURL;
Identity.prototype._description;
Identity.prototype._firstName;
Identity.prototype._lastName;



/**
 * Parses a XML Document that contains a marshalled identity.
 * @memberOf Layer
 * @function
 * 
 * @param myFrackingXML An XML Document.
 * 
 * Created on 29/04/2009
 * @author Pablo Casado (pablo.casado@layers.com)
 * @version <1.0>
 * 
 * @return Identity
 * @throws {Exception} If there is an error when creating the Identity from the XML
 */
Identity.prototype.parse = function(myFrakkingXML){
	
	try{
		
		this._displayName = myFrakkingXML.getElementsByTagName("displayName")[0].childNodes[0].nodeValue;
		
		this._imageURL = "http://edita.layers.com/images/" + this._displayName + ".jpg";
		
		
		try{
			this._firstName = myFrakkingXML.getElementsByTagName("firstName")[0].childNodes[0].nodeValue;
		}catch(e){
			this._firstName = "";
		}
		
		try{
			this._lastName = myFrakkingXML.getElementsByTagName("lastName")[0].childNodes[0].nodeValue;
		}catch(e){
			////console.error(e);
			this._lastName = "";
		}
		
		try{
			//this._description = myFrakkingXML.getElementsByTagName("description")[0].childNodes[0].nodeValue;
			this._description = $(myFrakkingXML).find("description:first").text();
		}catch(e){
			this._description = "";
		}
		
		
		try{
			var tmp = myFrakkingXML.getElementsByTagName("followings")[0].getElementsByTagName("id");

			var i = 0;
			while (tmp[i]){
				this._followings[i] = tmp[i].childNodes[0].nodeValue;
				i = i + 1;
			}
			
			this._timesFollowing = tmp.length;
		}catch(e){
			this._timesFollowing = 0;
		}
		
		
		try{
			tmp = myFrakkingXML.getElementsByTagName("followers")[0].getElementsByTagName("id");

			var i = 0;
			while (tmp[i]){
				this._followers[i] = tmp[i].childNodes[0].nodeValue;
				i = i + 1;
			}

			this._timesFollowed = tmp.length;
		}catch(e){
			this._timesFollowed = 0;
		}

	}catch(e){
		throw new Exception("ERROR CREATING IDENTITY FROM XML");
	}
	
	return this;
	
}


