;(function($) {

	$.widget("ui.hotelFavoriteAdd", $.extend({
	
	    get: function() {
	        return +this.element[0].checked
	    },
	
		set: function(checked) {
			this.element[0].checked = checked
		},
		
		_init: function() {
			
			this.init.apply(this, arguments);
		},
		
		init: function() {
			$.widget.prototype._init.apply(this,arguments)
	
			var self = this
			this.ajaxController = new AjaxController(this, '/tour/', '.php')
	
			this.element.click(function() {
	
				var req = {
					url: 'hotels',
					data: {
						country: $('#Co').CoSelect('get'),
						city: $('#city').stringSelect('get'),
						efavorite: 1
					}
				}
	
				// disable cache (useful when user selects new favorite in another window)
				self.ajaxController.sendRequest(req, true)
	
			})
		},
	
		onLoaded: function(data) {
			if (data.count==0) {
				// display after onloaded removes loading status
				setTimeout(function() { jAlert("У Вас нет избранных отелей") },0)
				return
			}
			$('#hotel-choose-name-tab').selectedHotels('set',data.hotels)
		}
	
	}, stringLoadingWidgetMixin))
})(jQuery)