var ProfilePage = {
	addUserToFav: function(item_id, el){
		if (!el || item_id < 1 || !BasePage.isLogged()) return;
		ITcraft.request('/ajax/favorites.php', {
			parameters: {
				cmd: 'add',
				type: 'users',
				item_id: item_id
			},
			onSuccess: function(json, res) {
				if(!json.is_error){
					var link = $(this.el);
					if (link) {
						link.className += ' not_active';
						link.onclick = this.mainScope.removeUserFromFav.bind(this.mainScope, this.item_id, this.el);
						link.update('I\'m Following');
					}
				}
			},
			scope: {
				el: el,
				item_id: item_id,
				mainScope: this
			}
		});
	},
	
	removeUserFromFav: function(item_id, el){
		if (!el || item_id < 1 || !BasePage.isLogged()) return;
		ITcraft.request('/ajax/favorites.php', {
			parameters: {
				cmd: 'delete',
				type: 'users',
				item_id: item_id
			},
			onSuccess: function(json, res) {
				var link = $(this.el);
				if (link) {
					link.className = link.className.replace(/\s?not_active\s?/,'');
					link.onclick = this.mainScope.addUserToFav.bind(this.mainScope, this.item_id, this.el);
					link.update('Follow Me');
				}
			},
			scope: {
				el: el,
				item_id: item_id,
				mainScope: this
			}
		});
	},

	rateIt: function(item_id, el){
		if (!el || item_id < 1 || !BasePage.isLogged()) return;
		ITcraft.request('/ajax/rate.php', {
			parameters:{
				cmd: 'rateIt',
				type: 'users',
				item_id: item_id,
				need_counter: 1
			},
			onSuccess: function(json, res) {
				if(!json.is_error){
					var link = $(this.el);
					if (link) {
						link.className += ' not_active';
						link.onclick = '';
						link.update((json.new_counter > 0 ? json.new_counter : '1') + ' Springs');
					}
				}
			},
			scope: {
				el: el
			}
		});
	}
};