$(document).ready(function() {

	$(".containerPlus").buildContainers({
	containment:"document",
	elementsPath:"/elements/"
	});

    var options = {
    	data: 			{overwriten_is_ajax_post: '1'},
        target:        '#ymaps_content',   // target element(s) to be updated with server response
        beforeSubmit:  showRequest,  // pre-submit callback
        success:       showResponse,  // post-submit callback
        error:			showError,

        // other available options:
        //url:       url         // override for form's 'action' attribute
        //type:      type        // 'get' or 'post', override for form's 'method' attribute
        dataType:  'json',        // 'xml', 'script', or 'json' (expected server response type)
        //clearForm: true        // clear all form fields after successful submit
        //resetForm: true        // reset the form after successful submit

        // $.ajax options can be used here too, for example:
        timeout:   60000          // если за минуту не получаем ajaxStop убиваем запрос.
    };
        // bind form using 'ajaxForm'
			$('#yform').ajaxForm(options);

			$(this).find(".close:first").click(function(){			$("#tallContent").removeShadow();
			$("#tallContent").css("visibility","hidden");
			$("#tallContent").css("display","none");
			my_unblock();
	  	});
});

function my_unblock(){	if ($.browser.msie) {
            $(".blockUI").hide();
            }else{
            $.unblockUI();
            }	}

function link_clik(id,source){


   $("#tallContent").css("visibility","visible");
	$("#tallContent").css("display","block");
	 if (source=='yandex'){		$("#ypost").val("");
		$("#gpost").val("");
		$("#ypost").val(id);
		document.getElementById("ysubm").click();
     }else if (source=='google'){
		$("#gpost").val("");
		$("#ypost").val("");
		$("#gpost").val(id);
		document.getElementById("ysubm").click();
     }

		$.blockUI({
            message: $('#tallContent'),
            css: {
                top:  ($(window).height() - 460) /2 + 'px',
                left: ($(window).width() - 650) /2 + 'px',
                width: '650px',
                height: '460px',
                backgroundColor:'',
                border: '0px',
                cursor:         'normal'
            },
            overlayCSS: {
           		backgroundColor:'#85BBEF'
            }
        });

		$("#tallContent").css("top",($(window).height() - 460) /16 + 'px');
		$("#tallContent").css("left",($(window).width() - 650) /16 + 'px');


		 $("#tallContent").dropShadow({							left: 2,
							top: 2,
							blur: 1,
							opacity: .7,
							color:'blue'});


}

//error
function showError(){
		$("#tallContent").removeShadow();		$("#tallContent").css("visibility","hidden");
		$("#tallContent").css("display","none");
		my_unblock();

		 // вырубаю сплеш скрин
		alert ("Произошла ошибка при соxранении данных. Попробуите позже.");
return true;
}

// pre-submit callback
function showRequest(formData, jqForm, options) {

	  return true;
}

// post-submit callback
function showResponse(responseText, statusText)  {
 		// мои обработчик респонза - обрабатівает JSON  ответ от сервера
        // серверная часть респонза - пример echo '{msg:"redirect",redirect:"preferences.php",subm_image:"0", img_length:"subm_image.lengts", responsetip: "submitet_data_type"}';
		// клиентская часть   responseText.msg   responseText.redirect   responseText.subm_image=JSON масив {(int)index: 'path/to/image'}

   if (responseText.responsetip=='json'){
				$('#ymaps_title').html(responseText.title);
    			$('#ymaps_content').html(responseText.msg);
   }

}