/*
 * The OTl Event object
 */

function OTlEvent(title, tss, tse, id) {
	
	this.id;
	this.title = '';
	this.description = '';
	this.media = '';
	this.timestampStart;
	this.timestampEnd = false;
	this.categories = [];
	this.tags = [];
	this.people = [];
	this.places = [];
	this.prominence = 0;
	this.references = '';
	
	
	this.setTimestampStart = function(ts) {
		if(typeof(ts) == "string") {
			this.timestampStart = new Timestamp(ts);
		}
		else if(typeof(ts) == "object") {
			this.timestampStart = ts;
		}
	}
	
	this.setTimestampEnd = function(ts) {
		if(typeof(ts) == "string") {
			this.timestampEnd = new Timestamp(ts);
		}
		else if(typeof(ts) == "object") {
			this.timestampEnd = ts;
		}
	}
	
	this.setTitle = function(newTitle) {
		this.title = newTitle;
	}
	
	this.setId = function(newId) {
		this.id = newId;
	}
	
	this.setDescription = function(newDesc) {
		this.description = newDesc;
	}
	
	this.setCategories = function(newCats) {
		this.categories = newCats;
	}
	
	this.setProminence = function(newProm) {
		this.prominence = newProm;
	}
	
	this.setReferences = function(newReferences){
	  this.references = newReferences;
	}
	
	this.addCategory = function(newCat) {
		this.categories.push(newCat);
	}
	
	this.addPlace = function(newPlace) {
		this.places.push(newPlace);
	}
	
	this.addPerson = function(newPerson) {
		this.people.push(newPerson);
	}
	
	this.addTag = function(newTag) {
		switch(newTag.substr(0,1)) {
			case "#":
				this.addCategory(newTag.substring(1));
				break;
			case "@":
				this.addPlace(newTag.substring(1));
				break;
			case ":":
				this.addPerson(newTag.substring(1));
				break;
			default:
			//	this.addTag(newTag);
		}
		this.tags.push(newTag);
	}
	
	/*
	 * Returns a jQuery object that can be appended to the Timeline Layer
	 */
	this.jqObj = function(pps) {
		if(!pps) {
			
		}
		var obj = jQuery('<div class="otl-event"></div>');
		obj.append('<div class="otl-time-marker"></div>');
		obj.append('<div class="otl-event-icon"></div>');
		for(i in this.categories) {
			obj.addClass("cat-" + String(this.categories[i]).replace(" ", "_"));
		}
		obj.attr('id', this.id);
		obj.append('<div class="otl-event-label">'+this.title+'</div>');
		
		return obj;
	}
	
	if(title) {
		this.title = title;
	}
	else {
		this.title = '';
	}
	if(tss) {
		this.setTimestampStart(tss);
	}
	else {
		this.timestampStart = new Timestamp();
	}
	if(tse) {
		this.setTimestampEnd(tse);
	}
	if(id) {
		this.id = id;
	}
	else {
		this.id = '';
	}
}

