﻿$(document).ready(function(){
	var z_index = 5;
	var _timer = null;
	var element_view_id = null;

	$('.models .name_popup').hover(function(){
		var _this = this;
			$(_this).parent('div').parent('li').css('z-index', z_index++);
			var id = $(_this).parent('div').parent('li').attr('id');

	if(z_index>6 && element_view_id != null)
	 element_view_id.abort();

 element_view_id = $.ajax({
   type: "GET",
   url: "ajax.php",
   dataType: "html",
   timeout: "10000",
   data: "notebook=shortinfo&type=" + document.getElementById("type_catalog").value + "&id=" + id.replace("catalog_popup_",""),
   success: function(msg,element_view_id,ar){
	document.getElementById("view_" + id).innerHTML = msg;
			$(_this).parent('div').find('.popup').show();
   }
 });
	},function(){
		if(z_index>6 && element_view_id != null)
		 element_view_id.abort();

		$('.models').find('.popup').hide();
	});
	/*.leftIcons */
	$('.popup_menu').hover(function(){
		var _this = this;

			var css = $(_this).find('.popup').css("left");

			if(css=="127px")
			 $(_this).find('.popup').css("left",$(_this).offset().left-10);

			$(_this).find('.popup').show();
	},function(){
		$('.popup_menu').find('.popup').hide();
	});

	// Пересчет ширины сайта при больших таблицах в контенте
	var tableWidth = $('.main .charTable').width();
	var mainWidth = $('.main').width();
	var deltaWidth = (tableWidth - mainWidth +10);
	if(deltaWidth >= 0){
		$('body').css({width: ($('.wrapper').width() + deltaWidth)});
	}
});

	 function subscribe()
	  {
			document.getElementById("subscribe_preloader").style.display = "block";
			document.getElementById("subscribe_submit").style.display = "none";
	
			jQuery.ajax({
			   type: "POST",
			   url: "ajax.php?subscribe",
			   dataType: "html",
			   timeout: "10000",
			   data: "mail=" + document.getElementById("subscribe_mail").value + "&rand=" + Math.random(),
			   success: function(msg){
				document.getElementById("subscribe_result").innerHTML = msg;
				},
			   error: function() {document.getElementById("subscribe_preloader").style.display = "none";
			document.getElementById("subscribe_submit").style.display = "block";
	},
			   complete: function() {document.getElementById("subscribe_preloader").style.display = "none";
			document.getElementById("subscribe_submit").style.display = "block";
	}
			 });
	 }
