﻿$(document).ready(function()
{
	//Форма: оставить заявку
	var htmlForm = $('#purchase-form-container').html();
	$('#purchase-form-container').remove();
	
	$('a.box').click(function() {
		new Boxy(htmlForm, {title: this.innerHTML, closeable: true});
	});
	
	var options = {
	 	target: "#form-message",
		beforeSubmit: showRequest, // функция, вызываемая перед передачей 
		success: showResponse, // функция, вызываемая при получении ответа
		timeout: 30000 // тайм-аут
	};

	$('#purchase_request').live('submit',function() { 
		$(this).ajaxSubmit(options);
		return false;
	});

	function showRequest(formData, jqForm, options) {
		$('#purchase_request').addClass('fade');
		$('#purchase-form .splash').css('display','block');
	}
	
	function showResponse(responseText, statusText)  {
			$('#purchase_request').removeClass('fade');
			$('#purchase-form .splash').css('display','none');
		if('ok' == $(responseText).attr('class')){
			$('#form-message').css('padding', '15px 40px')
			$('#purchase_request').remove();
		}
	}
	//\\Форма: оставить заявку

	
	$("a.print-sale").click(function()
	{
		window.print();
		return false;
	});
	
	$("#header .right-head p.a").click(function()
	{
		var wd = 0.9*$(window).width();
		if (wd<1199)
		{
			$("#telephone-wrapper .into").css("width",wd+"px");
			$("#telephone-wrapper .into").css("marginLeft",-wd/2+"px");
			$("#telephone-wrapper .c div").css("font-size",wd/8.7+"px");		
			$("#telephone-wrapper .c .doomer").css("font-size",wd/70+"px");
		}
		$("#telephone-wrapper").animate({opacity: 'toggle'},250);
		$("#telephone-wrapper .into").css("marginTop",-$("#telephone-wrapper .into").height()/2+"px");
	});
	$(window).resize(function()
	{
		var wd = 0.9*$(window).width();
		if ((wd<1199) && (wd>700))
		{
			$("#telephone-wrapper .into").css("width",wd+"px");
			$("#telephone-wrapper .into").css("marginLeft",-wd/2+"px");
			$("#telephone-wrapper .c div").css("font-size",wd/8.7+"px");
			$("#telephone-wrapper .c .doomer").css("font-size",wd/70+"px");
		}
	});
	$("#telephone-wrapper .cl-button").hover(function()
	{
		$(this).addClass("cl-button-hovered");
	},
	function()
	{
		$(this).removeClass("cl-button-hovered");
	});
	$("#telephone-wrapper .cl-button").click(function()
	{
		$("#telephone-wrapper").animate({opacity: 'toggle'},250);
	});
});

