var slider = {
	
	_speed : 1500,
	
	toLeft: function (callback) {
		
		_l = $('#header').css('margin-left');
		
		$('#header')
			.animate({'margin-left': '-100%'}, slider._speed / 2)
			.animate({'margin-left': _l}, slider._speed / 2);
		
		$('#body').animate({
			'margin-left' : '100%'
		}, slider._speed, function (){

			if(typeof(callback) == 'function') {
				callback();
			}

		});
		
	},
	
	toRight: function (callback) {
		
		_l = $('#header').css('margin-left');

		$('#header')
			.animate({'margin-left': '100%'}, slider._speed / 2)
			.animate({'margin-left': _l}, slider._speed / 2);

		$('#body').animate({
			'margin-left' : '-100%'
		}, slider._speed, function (){

			if(typeof(callback) == 'function') {
				callback();
			}

		});
		
	}
	
}

$(function () {

	var _initLinks = function () {

		if (_isDisableAjax()) {
			return false;
		}
		
		$('a, form').each(function () {
			
			$(this).historyAjax({
				container: '#for_ajax',
				callbackBefore: function (fromHistory) {
					
				},
				callbackComplete: function (fromHistory) {
					
					_this = $('.ajaxed');

					var _moveDirection = $(_this).is('.moveToLeft') ? 'right' : 'left',
						_insertWrapper = _moveDirection == 'left' ? '#right_wrapper' : '#left_wrapper';
						
					if (fromHistory) {	// если пришли с истории всегда мотаем направо
						var _moveDirection = 'right',
							_insertWrapper = '#left_wrapper';
					}
					
					$('#left_wrapper, #right_wrapper').html('');
					$(_insertWrapper).html($('#for_ajax').html());
					$('#for_ajax').html('');
					
					var functionMove = _moveDirection == 'right' ? slider.toLeft : slider.toRight;
					functionMove(function () {
						
						$('#center_wrapper').html($(_insertWrapper).html());
						$('#left_wrapper, #right_wrapper').html('');
						
						$('#body').css('margin-left', 0);
						
						// выставляем TITLE браузера
						if (!$.browser.msie) {
							$('TITLE').html($('#head_title').html());
						}
						
						_initLinks();
						_initOnLoad();
								
					});
					
				}
			});
			
		});
		
		
	}
	
	_initLinks();
	
	
})



var preloader = {
	show : function () {
		$('#overlay').show();
	},
	
	hide : function () {
		$('#overlay').hide();
	}
}

