window.addEvent('domready', function(){
	
	if($('r-container')) {
		
		new Scroller('r-container', 836, 150, 342, 'r-prev', 'r-next');
	}
	
	if($('s-container')) {
		
		new Scroller('s-container', 836, 150, 544, 's-prev', 's-next');
	}
	
});

function AddToFavorites(id, type) {

	var link = $(type + '-' + 'add' + '-' + id);
	var link_rem = $(type + '-' + 'rem' + '-' + id);
	
	if(link && link_rem) {
		
		link.className = 'loading';
		new Request.JSON({url: '/', method: 'get', onSuccess: function(){
			link.style.display = 'none';
			link_rem.className = 'added';
			link_rem.style.display = 'block';
		}}).get({Event: 'AddToFavorites', id: id, type: type});
	}
	
	return false;
}

function RemoveFromFavorites(id, type) {
	
	var link = $(type + '-' + 'rem' + '-' + id);
	var link_add = $(type + '-' + 'add' + '-' + id);
	
	if(link && link_add) {
		
		link.className = 'loading';
		
		new Request.JSON({url: '/', method: 'get', onSuccess: function(){
			link.style.display = 'none';
			link_add.className = '';
			link_add.style.display = 'block';
		}}).get({Event: 'RemoveFromFavorites', id: id, type: type});
	}
	
	return false;
}

function DontAddToFavorites(type){
	
	if(type == 'resume') {
		
		alert('Что бы добавить резюме в избранное необходимо авторизоваться');
	}
	else {
		
		alert('Что бы добавить вакансию в избранное необходимо авторизоваться');
	}
	
	return false;
}

function RemoveFromFavoritesList(id, type) {
	
	var link = $('link-' + id);
	
	if(link) {
		
		link.className = 'loading';
		
		new Request.JSON({url: '/', method: 'get', onSuccess: function(){
			
			$$('.row-' + id + ' td').each(function(cell){
				
				var el = cell.getFirst();
				
				el.style.overflow = 'hidden';
				var coord = el.getCoordinates();
				new Fx.Morph(el, {duration: 300, onComplete: function(){
					cell.dispose();
				}}).start({
					opacity: [1, 0], 
					height: [coord.height, 0]
				});
			});
			
			total_favorites_cnt--;
			if(total_favorites_cnt <= 0) {
				
				$('favorites-items-list').dispose();
				$('favorites-empty-list').removeClass('hidden');
			}
		}}).get({Event: 'RemoveFromFavorites', id: id, type: type});
		
		return false;
	}
}

