/*---------------------------------------------------[ other ajax ]------------------------------------------*/
function followUser(userId) {
	var link = $('#followLink');
	link.html('Please wait...');
	
	if (link.attr('rel') == 'follow') {

		$.post("/followers/follow/"+userId+"?call=ajax", {}, function(response) {
			if (response.result == 'success') {
				link.attr('rel', 'unfollow').attr('title', response.title);
			}
			link.html(response.message);
		}, 'json');
		
	} else if (link.attr('rel') == 'unfollow') {
		
		$.post("/followers/unfollow/"+userId+"?call=ajax", {}, function(response) {
			if (response.result == 'success') {
				link.attr('rel', 'follow').attr('title', response.title);
			}
			link.html(response.message);
		}, 'json');
		
	}

	return false;
}
	

function subscribeToComments(model, parentId) {
	$('#subscribeLink_'+model+'_'+parentId).html('Please wait...');
	$.post("/subscribes/subscribe/"+model+"/"+parentId+"?call=ajax", {}, function(response) {
		$('#subscribeLink_'+model+'_'+parentId).html(response);
	});
}
function unsubscribeFromComments(model, parentId) {
	$('#subscribeLink_'+model+'_'+parentId).html('Please wait...');
	$.post("/subscribes/unsubscribe/"+model+"/"+parentId+"?call=ajax", {}, function(response) {
		$('#subscribeLink_'+model+'_'+parentId).html(response);
	});
}
function showFollowers(followedUserId) {
	if ($('#followersDiv').length > 0) {
		$('#followersDiv').show();
	} else {
		$.get('/feeds/followers/'+followedUserId+'?call=ajax&_='+Math.random(), function(response){
			$('.followmenu li:first').append(response);
			$('#followersDiv').show();
		});
	}
}
function showFollowed(followerId) {
	if ($('#followedDiv').length > 0) {
		$('#followedDiv').show();
	} else {
		$.get('/feeds/followed/'+followerId+'?call=ajax&_='+Math.random(), function(response){
			$('.followmenu li:eq(1)').append(response);
			$('#followedDiv').show();
		});
	}
}
function changeImageSet(setSelect) {
	var imageId = $(setSelect).attr('id').split('_')[1];
	var setId = $(setSelect).val();
	$(setSelect).after('<img src="http://'+siteTopDomain+'/img/working.gif" class="ajaxWorking" />');
	$.post('/images/changeSet?call=ajax&_='+Math.random(), {'data[Image][id]':imageId,'data[Image][image_set_id]':setId}, function(response){
		$('.ajaxWorking').remove();
		if (response == 'forbidden') {
			alert('This action is forbidden. Please log in.');
		} else if (response == 'error') {
			alert('Error while saving');
		} else {
			//success
		}
	});
}
function switch_theme(new_theme) {
	$.post('/systems/switchTheme/?call=ajax', {'theme':new_theme}, function(response){
		window.location.reload(false);
	});
}

function saveStatus() {
	var newStatus = $('div.editsubmenu div.statusbox input').val();
	$('div.editsubmenu div.statusbox img[alt="Ok"]').attr('src', '/img/load_dark.gif')
	$.post('/profiles/saveStatus/?call=ajax', {'data[Profile][status]':newStatus}, function(response){
		$('div.editsubmenu div.statusbox img[alt="Ok"]').attr('src', '/img/statusok.gif');
		if ($('.savedSpan').length == 0) {
			$('div.editsubmenu div.statusbox img[alt="Ok"]').after('<span class="savedSpan"><img src="/img/saved.gif" class="floatleft" style="padding-left:4px;" alt="Saved" /></span>');
		}
		setTimeout("$('div.editsubmenu div.statusbox .savedSpan').remove()", 5000);
	});
}

function showFavorites(model, parentId) {
	var favoriteByDiv = $('#favoriteByDiv');
	
	if (favoriteByDiv.is(':visible')) {
		
		favoriteByDiv.hide();
		
	} else if (favoriteByDiv.html().trim() == '') {
		
		favoriteByDiv.html('<img src="/img/load_dark.gif">');
		
		$.ajax({
			'url':'/favorites/getUsersByFavorite/'+model+'/'+parentId,
			'type':'GET',
			'cache':true,
			'success':function(response){
				favoriteByDiv.html(response);
			}
		});
		
		favoriteByDiv.slideDown('fast');
	} else {
		favoriteByDiv.slideDown('fast');
	}
	
	return false;
}