

	var popup = new Object();
	popup.opened = -1;
	popup.inited = false;

	/**
	 * Инициализация
	 */
	popup.init = function () {
		popup.height = Math.max(document.body.clientHeight, document.body.scrollHeight);
		popup.content = $("#frame .center .center div.box");
		popup.text = $("#frame .center .center div.text");
		popup.inited = true;
		popup.popups = $("div.popup div.popup_item");
		popup.box = $('#main_shadow');
		popup.f = $("#frame");
	}

	/**
	 * Открыть попап
	 */
	popup.open = function (id) {
		if (this.inited==false) this.init();
		popup.content.css('width','1px');
		popup.content.css('height','1px');
		popup.box.css("width","100%");
		popup.box.css("height", popup.height+"px");
		popup.box.css('top', '0px');
		popup.box.css('left', '0px');

		popup.opened = id;
		popup.shadowOn();
	}

	/**
	 * Закрыть попап
	 */
	popup.close = function () {
		popup.heightOff();
	}

	/**
	 * Затенить контент
	 */
	popup.shadowOn = function () {
		popup.box.animate({opacity: 'show'}, 300, popup.heightOn);
	}

	/**
	 * Растенить контент
	 */
	popup.shadowOff = function () {
		popup.box.animate({opacity: 0.1}, 300, function () {popup.box.removeAttr('style')});
	}

	/**
	 * Развернуть вертикаль
	 */
	popup.heightOn = function () {
		popup.f.show('fast');
		popup.correction();
		popup.text.html(popup.popups[popup.opened].innerHTML);


		var height = popup.text.height()+40;
		popup.f.animate({top: Math.round(document.body.scrollTop + document.body.clientHeight/2 - height/2)}, 'fast');
		popup.content.animate({ height: height+'px'}, 'slow', popup.widthOn);
	}

	/**
	 * Свернуть вертикаль
	 */
	popup.heightOff = function () {
		var height = 2;
		popup.f.animate({top: Math.round(document.body.scrollTop + document.body.clientHeight/2 - height/2)}, 'slow');
		popup.content.animate({ height: height+'px'}, 'slow', popup.widthOff);
	}

	/**
	 *  Развернуть горизонталь
	 */
	popup.widthOn = function () {
		popup.content.animate({ width: 800+'px'}, 'slow');
	}

	/**
	 *  Свернуть горизонталь
	 */
	popup.widthOff = function () {
		popup.content.animate({ width: 2+'px'}, 'slow', popup.shadowOff);
	}

	popup.correction = function () {
		popup.f.css('top', Math.round(document.body.scrollTop + document.body.clientHeight/2 - Math.max(popup.f.height(), 50)/2));
	}
	
	
	function mail (obj){
		var obj = $(obj).parents("form");
		if (obj.find("textarea").val().length<1) {
			alert('Пожалуйста, заполните текст сообщения');
			return false;
		}
		$.ajax({
			type: 'POST',
			url: "/mail/",
			data: obj.serialize(),
			success: function(data){
				if (data=='ok'){
					alert('Сообщение успешно отправлено');
					obj.find("input[type=text], textarea").val('');
				}else{
					alert(data);
				}
			}
		});
		return false;
	}	
	
	
	
