	var startInd = 0;
	var current_special_offer;	
	var flag_show_more = false;
	var ctime;	

	function show_next_special_offer() {

		new_id = parseInt(current_special_offer.attr("id")) + 1;
		if(new_id > special_offers_count - 1) 
			new_id = 0;
		if(new_id >= 4 && special_offers_count > 4) 
			flag_show_more = true;
		var obj = $("#" + new_id);
		show_big_image(obj);
		if(flag_show_more) 
			show_more_down();	
		ctime = setTimeout("show_next_special_offer()", timeout);
		return true;
	}	

	function show_big_image(obj) {

		var largePath = obj.attr("href");
		var largeAlt = obj.attr("title");
		var id = parseInt(obj.attr("id"));
		
		$("#largeImg").attr({ src: largePath, alt: largeAlt, title: largeAlt });
		$("#largeImgLink").attr({ href: arrImgs[id]['link'] });
		$("#largeImgTitle").attr({ innerHTML: arrImgs[id]['title'] });
		$("#largeImgContent").attr({ innerHTML: arrImgs[id]['content'] });
				
		//$(".special_offer").attr({ src: '/images/brd_spec_small.png' });
		//$(".special_offer").css("background", 'url(http://pauls.ru/img/2/vcart/1/1.jpg) 0 0 no-repeat');
		//obj.find("img").attr({ src: '/images/brd_spec_act.png' });	
		$(".special_offer").removeClass("act");
		obj.find("span").addClass("act");

		current_special_offer = obj;
		
		return true;
	}
	
	function redirect_on_object_page(obj) {

		var id = parseInt(obj.attr("id"));
		window.location = arrImgs[id]['link'];
		return true;
	}	

	function show_more_down() {

		if (startInd >= special_offers_count - 1)
			startInd = 0;
		else
			startInd++;
		var j = startInd;
		
		$(".thumbnails").hide();
		for (i = 0; i < 4; i++)
		{
			if (i == 0)
			{
				$("#thumbnails_" + j).prependTo(".scrollable");
				var el = $("#thumbnails_" + j);
			}
			else
			{
				$("#thumbnails_" + j).insertAfter(el);
				el = $("#thumbnails_" + j);
			}
			$("#thumbnails_" + j).show();
			j++;
			if (j >= special_offers_count)
				j = 0;
		}
		
		return true;
	}
	
	function show_more_up() {

		if (startInd == 0)
			startInd = special_offers_count - 1;
		else
			startInd--;
		var j = startInd;
		
		$(".thumbnails").hide();
		for (i = 0; i < 4; i++)
		{
			if (i == 0)
			{
				$("#thumbnails_" + j).prependTo(".scrollable");
				var el = $("#thumbnails_" + j);
			}
			else
			{
				$("#thumbnails_" + j).insertAfter(el);
				el = $("#thumbnails_" + j);
			}
			$("#thumbnails_" + j).show();
			j++;
			if (j >= special_offers_count)
				j = 0;
		}
		
		return true;
	}	
	
	function check_email(email) {
		var reg_mail = /^[a-z0-9\_\+\.\-]+\@([a-z0-9\-]+\.)+[a-z0-9]{2,4}$/i;
		return email == "" || reg_mail.test(email);
	}
	
	function check_phone(phone) {
		var reg_phone = /^([\d-+\(\) ]+)$/i;
		return phone == "" || reg_phone.test(phone);
	}	
	
	function check_order(form) {
		
		var from = form.elements['from'].value;
		var email = form.elements['email'].value;
		var phone = form.elements['phone'].value;
		var message = form.elements['message'].value;
		var flag = false;
		
		if (from == '') {
			alert('Введите Ваше имя.');
			form.from.focus();
			return false;
		}
		
		if (email == '' && phone == '') {
			alert('Телефон или e-mail обязательно должны быть заполнены.');
			return false;
		}
		
		if(phone != "" && !check_phone(phone)) {
			alert('Некорректное значение поля: Телефон.');
			form.phone.focus();
			return false;			
		}	
		
		if(email != "" && !check_email(email)) {
			alert('Некорректное значение поля: Электронная почта.');
			form.email.focus();
			return false;			
		}
	
		for (var i = 0; i <  document.forms[0].service_id.length; i++) {
			if (document.forms[0].service_id[i].checked) flag = true;
		}
		
		if (!flag) {
			alert('Выберите тип услуги.');
			return false;
		}
		
		flag = false;
		for (var i = 0; i <  document.forms[0].order_type_id.length; i++) {
			if (document.forms[0].order_type_id[i].checked) flag = true;
		}
		if (!flag) {
			alert('Выберите тип недвижимости.');
			return false;
		}		

		if (message == '') {
			alert('Введите Ваше сообщение.');
			form.message.focus();
			return false;
		}

		return true;
	}	
