function Destination(jsonInfo, controller, type) {
	this._info = jsonInfo;
	this._controller = controller;
	this._type = type;
	return this;
}
Destination.prototype = {
	_info:null,
	_controller:null,
	_type:null,
	_container:null,
	_marker:null,

	isPartOfTrip: function() {
		return this.getInfo().part_of_trip;
	},

	getContainers: function() {
		return $('.' + this.getUId());
	},
	
	getContainer: function() {
		return this._container || $('#' + this.getUId() + this.getType());
	},
	
	getClonedContainer: function() {
		return this.getContainer().clone().removeAttr('id');
	},
	
	getId: function() {
		return this.getInfo().id;
	},
	
	getUId: function() {
		return this.getInfo().uid;
	},
	
	getCategory: function() {
		return this.getInfo().category;
	},

	getName: function() {
		return this.getInfo().name;
	},
	
	getGLatLng: function() {
		return new GLatLng(this.getInfo().lat, this.getInfo().lng);
	},
	
	getInfo: function() {
		return this._info;
	},
	
	getType: function() {
		return this._type;
	},
	
	setContainer: function(container) {
		this._container = container;
		return this;
	},
	
	setType: function(value) {
		this._type = value;
		return this;
	},

	displayDetails:function() {
		var self = this;
		var url = '/destination/' + this.getCategory() + '/' + this.getId();
		ajaxHTML(url, null, function(html) { 
			$('#destinationDetailsContainer').html(html);
		});
		return this;
	},
	
	select: function() {
		this.getContainers().addClass('selected');
		this.displayDetails();

		// report to global destinations controller		
		this._controller.destinationSelected(this);
				
		// update maps
		if (gm) {
			gm.selectMarker(this).centerOnDestination(this);
		}

		return this;
	},
	
	deselect: function() {
		this.getContainers().removeClass('selected');
		
		// report to global destinations controller		
		this._controller.destinationDeselected(this);
		
		// update maps
		if (gm) {
			gm.resetMarker(this);
		}
		return this;
	},

	save: function() {
		ViewManager.showStep(3);
		// copy destination then sort to pending
		if (!this._controller.isDestinationInList(this, 'pending') && !this._controller.isDestinationInList(this, 'completed')) {
			this._controller.copyDestinationTo(this, 'pending');
			this._controller.sortList('pending');

			ajax('/destination/save/' + this.getCategory() + '/' + this.getId());
			this.setClass('pending');
		}
		return this;
	},

	forget: function() {
		this._controller.removeDestination(this);
		this._controller.sortList(this.getType());
		ajax('/destination/forget/' + this.getCategory() + '/' + this.getId());
		this.setClass('search');
		return this;
	},

	verify: function() {
		var self = this;
		ajaxHTML('/destination/verify/' + this.getCategory() + '/' + this.getId(), null, function(html) {
			self.verifyRender(html);
		});
	},
	
	verifyRender: function(html) {
		$('#DestinationverificationContainer').html(html).show();
		$("#DestinationverificationContainer").draggable({ handle: '.popuptop', cursor: 'move' });
		cancelButton('#DestinationverificationContainer');
	},

	verifySubmit: function(form) {
		var data = $(form).serialize();
		var self = this;
		ajax('/destination/verify/' + this.getCategory() + '/' + this.getId(), data, function(json) {
			if (json.success) {
				$('#DestinationverificationContainer').hide().empty();
				self.setClass('completed');

				// move destination and sort completed
				self._info.part_of_trip = 0;
				self._controller.moveDestinationTo(self, 'completed');
				self._controller.sortList('completed');

				// update user profile for new stats
				$('#userProfile').replaceWith(json.profile);
				
				// show certificate if needed
				if (json.showCertificate) {
					renderCertificate();
				}
			}
			else {
				self.verifyRender(json.html);
				$('#verificationErrorMessage').show();
			}
		});
	},
	
	addToTrip: function() {
		this._controller.copyDestinationTo(this, 'trip');
		this.getContainer().hide();
		this._controller.directionsInstructionsToggle();
		this._controller.fixDirectionsParity();
		this._controller.routeTrip();
		this._controller.getListContainer('trip').sortable('refresh');
		ViewManager.showStep(5);
		return this;
	},
	
	removeFromTrip: function() {
		this._controller.removeDestinationFromTrip(this);
		this._controller.directionsInstructionsToggle();
		this._controller.fixDirectionsParity();
		this._controller.routeTrip();
		return this;
	},
	
	setClass: function(newClass) {
		// remove all classes
		var classes = ['pending', 'search', 'completed', 'trip'];
		for (var i = 0; i < classes.length; i++) {
			$('.' + this.getUId()).removeClass(classes[i]);
		}

		// add new one
		$('.' + this.getUId()).addClass(newClass);
	}
};