window.addEvent('domready', function() {
	var peoples_switch_prew = $$('.peoples-switch-prew');
	var peoples_switch_next = $$('.peoples-switch-next');
	
	var peoples_switch_params = {
		'limit' : 3,
		'woman': {
			'start': 0
		},
		'man': {
			'start': 0
		}
	}
	
	var peoples_draw_box = function(sex, start) {
		var request = new Request({
			method: 'get',
			url: '/ajax/main/',
			onSuccess: function(text) {
				var block = '';
				if (sex == 'man') {
					block = $('peoples-switch-box-man');
				}
				if (sex == 'woman') {
					block = $('peoples-switch-box-woman');
				}
				block.set('html', text);
			}
		}).send('DEBUG_MODE=0&prefix=1&sex='+sex+'&start='+start);
	}
	
	var peoples_switch_prew = $$('.peoples-switch-prew');
	var peoples_switch_next = $$('.peoples-switch-next');
	
	peoples_switch_prew.addEvent('click', function() {
		sex = this.get('rel');
		if (sex == 'man') {
			peoples_switch_params.man.start--;
			if (peoples_switch_params.man.start < 0) {
				peoples_switch_params.man.start = daily_man_count - peoples_switch_params.limit;
			}
		
			peoples_draw_box(sex, peoples_switch_params.man.start);
		}
	
		if (sex == 'woman') {
			peoples_switch_params.woman.start--;
			if (peoples_switch_params.woman.start < 0) {
				peoples_switch_params.woman.start = daily_woman_count - peoples_switch_params.limit;
			}
		
			peoples_draw_box(sex, peoples_switch_params.woman.start);
		}
	});

	peoples_switch_next.addEvent('click', function() {
		sex = this.get('rel');
		if (sex == 'man') {
			peoples_switch_params.man.start++;
			if (peoples_switch_params.man.start > daily_man_count - peoples_switch_params.limit) {
				peoples_switch_params.man.start = 0;
			}

			peoples_draw_box(sex, peoples_switch_params.man.start);
		}
	
		if (sex == 'woman') {
			peoples_switch_params.woman.start++;
			if (peoples_switch_params.woman.start > daily_woman_count - peoples_switch_params.limit) {
				peoples_switch_params.woman.start = 0;
			}
		
			peoples_draw_box(sex, peoples_switch_params.woman.start);
		}
	});

});
