$(function()
{	
//	инициируем прокрутку в облаке
	$('#scrollable').jScrollPane({scrollbarWidth:28, scrollbarMargin:30, dragMaxHeight: 29});

//	создаем обработчик перетаскивания слайдера
	$("#ui-slider-handle").draggable({
		axis: 'x',
		containment: 'parent',
		drag: function(event, ui)
		{
			var handleLeft = $(event.target).position().left;
			var descLeft = $('.description').position().left;
			if (handleLeft <= 95 && descLeft != 20) {
				$('.description').stop().animate({left: '20px'}, 'slow');
				$('#tarif_small_pane').html($('#tarif_1_small').html());
				createOnClick('1');
				if ($('.fulltext:visible').length) {
					xajax_tarif_fulltext('1');
				}
			} else if ((handleLeft >= 96 && handleLeft <= 295) && descLeft != 210) {
				$('.description').stop().animate({left: '210px'}, 'slow');
				$('#tarif_small_pane').html($('#tarif_2_small').html());
				createOnClick('2');
				if ($('.fulltext:visible').length) {
					xajax_tarif_fulltext('2');
				}
			} else if ((handleLeft >= 296 && handleLeft <= 480) && descLeft != 400) {
				$('.description').stop().animate({left: '400px'}, 'slow');
				$('#tarif_small_pane').html($('#tarif_3_small').html());
				createOnClick('3');
				if ($('.fulltext:visible').length) {
					xajax_tarif_fulltext('3');
				}
			} else if ((handleLeft >= 481 && handleLeft <= 655) && descLeft != 580) {
				$('.description').stop().animate({left: '580px'}, 'slow');
				$('#tarif_small_pane').html($('#tarif_4_small').html());
				createOnClick('4');
				if ($('.fulltext:visible').length) {
					xajax_tarif_fulltext('4');
				}
			} else if (handleLeft >=656 && descLeft != 750) {
				$('.description').stop().animate({left: '750px'}, 'slow');
				$('#tarif_small_pane').html($('#tarif_5_small').html());
				createOnClick('5');
				if ($('.fulltext:visible').length) {
					xajax_tarif_fulltext('5');
				}
			}
		},
		stop: function(event)
		{
			var handleLeft = $(event.target).position().left;
			if (handleLeft <= 95) {
				$('#ui-slider-handle').animate({left: '10px'}, 'slow');
			} else if (handleLeft >= 96 && handleLeft <= 295) {
				$('#ui-slider-handle').animate({left: '200px'}, 'slow');
			} else if (handleLeft >= 296 && handleLeft <= 480) {
				$('#ui-slider-handle').animate({left: '390px'}, 'slow');
			} else if (handleLeft >= 481 && handleLeft <= 655) {
				$('#ui-slider-handle').animate({left: '570px'}, 'slow');
			} else if (handleLeft >=656) {
				$('#ui-slider-handle').animate({left: '740px'}, 'slow');
			}
		}
	});
	
//	обработка щелчков по иконкам тарифов
	$('#tarif1').click(function(){
  		$('#ui-slider-handle').animate({left: '10px'}, 'slow');
  		$('.description').animate({left: '20px'}, 'slow');
  		$('#tarif_small_pane').html($('#tarif_1_small').html());
  		createOnClick('1');
  		if ($('.fulltext:visible').length) {
  			xajax_tarif_fulltext('1');
  		}
	});
	$('#tarif2').click(function()
	{
  		$('#ui-slider-handle').animate({left: '200px'}, 'slow');
  		$('.description').animate({left: '210px'}, 'slow');
  		$('#tarif_small_pane').html($('#tarif_2_small').html());
  		createOnClick('2');
  		if ($('.fulltext:visible').length) {
  			xajax_tarif_fulltext('2');
  		}
	});
	$('#tarif3').click(function()
	{
  		$('#ui-slider-handle').animate({left: '390px'}, 'slow');
  		$('.description').animate({left: '400px'}, 'slow');
  		$('#tarif_small_pane').html($('#tarif_3_small').html());
  		createOnClick('3');
  		if ($('.fulltext:visible').length) {
  			xajax_tarif_fulltext('3');
  		}
	});
	$('#tarif4').click(function()
	{
  		$('#ui-slider-handle').animate({left: '570px'}, 'slow');
  		$('.description').animate({left: '580px'}, 'slow');
  		$('#tarif_small_pane').html($('#tarif_4_small').html());
  		createOnClick('4');
  		if ($('.fulltext:visible').length) {
  			xajax_tarif_fulltext('4');
  		}
	});
	$('#tarif5').click(function(){
  		$('#ui-slider-handle').animate({left: '740px'}, 'slow');
  		$('.description').animate({left: '750px'}, 'slow');
  		$('#tarif_small_pane').html($('#tarif_5_small').html());
  		createOnClick('5');
  		if ($('.fulltext:visible').length) {
  			xajax_tarif_fulltext('5');
  		}
	});
	
//	показать/скрыть полное описание тарифа
	$('#close_fulltext').click(function(){
		$('.fulltext').hide();
		$('.description').show();
	});
	
//	
	$('#to_order').bind('click', function(event){
		$('input#subject').focus();
		$('input#subject').val($('#tarif_name').html());
		$('input#subject').blur();
	});
	
//	содаем обработчик при загрузки страницы
	createOnClick('1');
	
//	обновить картинку капчи
	$('img#capcha').click(function()
	{
		var capchaSrc = '/differ/capcha/pic.php?' + Math.round(Math.random(0)*1000);
		$(this).attr({src: capchaSrc});
	});
	
	if ($('h4#feedback_system_mess').html()) {
		$('form#feedback').hide();
		$('h4#feedback_system_mess').show();
		setTimeout(function()
		{
			$('h4#feedback_system_mess').hide();
			$('form#feedback').show();
		}, 3000);
	}
});

//	создаем обработчик для кнопки "перейти к полному описанию тарифа"
function createOnClick(tarifId)
{
	$('#to_fulltext').unbind('click').click(function()
	{
		$('.fulltext').show();
		$('.description').hide();
		xajax_tarif_fulltext(tarifId);
	});
}