$(window).load(function()
{

//
	var MinHeightBlock = 0;
	$("#Left .Block").each(function(index)
	{
		MinHeightBlock = MinHeightBlock + $(this).height();
		//alert($(this).height());
	});
	//alert(MinHeightBlock);
	
	$(".MinHeight").css("min-height", MinHeightBlock - $("#Right .PageContentTitle").height() - 17 + "px" );

});


$(function(){

// Проверка на наличие включённого JavaScripts
	$(".jsoff").removeClass("jsoff");


// Скрипт убирающий из формы INPUT девайлсный текст при фокусе на элемент.
	$("form *[rel!='']").each(function(index){if($(this).val() == ""){$(this).attr("value", $(this).attr("rel"));}});
	$("form *[rel!='']").bind("focus", function(){if($(this).val() == $(this).attr("rel")){$(this).val("");}});
	$("form *[rel!='']").bind("blur", function(){if($(this).val() == ""){$(this).val($(this).attr("rel"));}});


// Выравнивение блока с классом ValignFIX по центру родительского блока
	$('.ValignFIX').each(function(index){$(this).css('margin-top', parseInt(($(this).parent().height() - $(this).height()) / 2));});


// 
	$("#TopMenu td a.txt").hover(function(){
        $(this).parent("td").next("th").addClass("hover");
        $(this).parent("td").prev("th").addClass("hover");		
    }, 
    function(){
        $(this).parent("td").next("th").removeClass("hover");
        $(this).parent("td").prev("th").removeClass("hover");	
    });
//
  $(".LogoSlideshow").cycle({
		fx:				'fade',
		sync:			0
	});


// Скрипт горизонтального скрола Promo блоков
	$("#PromoArea").cycle({
	    fx:				'scrollHorz',
	    prev:   	'#ScrollLeft',
	    next:   	'#ScrollRight',
	    before:		onBefore,
	    after:		onAfter,
	    pause:		1,
	    delay:		1000,
	    timeout:	0
	});
	function onBefore() {
	    $('#HideImg').css("z-index","40");
	} 
	function onAfter() {
	    $('#HideImg').css("z-index","-1");
	}
	$('#HideImg').height($("#Promo").height());



    $(".Border").append('<div class="BorderArrow"></div>');


    $(".Tip").append('<div class="case"><div class="top"></div><div class="mid"></div><div class="bot"></div></div>');

    $(".Tip").hover(function() {
        $(this).find(".case").animate({opacity: "show"}, "fast");
        var hoverText = $(this).attr("rel");
        $(this).find(".mid").html(hoverText);
    }, function() {
        $(this).find(".case").hide();
    });
// Эффект тени у меня. Только для IE
	if ( $.browser.msie )
	{
		$("body.ie7 #Header .Logo .NY").click(function(){
				window.location.href= "/";
		});
		$("body.ie6 #Header .Logo .NY").click(function(){
				window.location.href= "/";
		});
	}
// Правки только для IE6
	if ( $.browser.msie && parseInt($.browser.version) == 6 )
	{
		$(".MainSlogan .Relative .Text").addClass("PNGfix");
		$(".MainSlogan .Relative .Car").addClass("PNGfix");
		$("#Header .Logo .LogoSlideshow").addClass("PNGfix");
		$("#Header .Logo .NY").addClass("PNGfix");
	}
	$(window).bind("resize", function(){
      $("#ajax-status").width($(window).width());
	});
	$(".BtmOrder").click(function(){
      var form_object = $(this).parent("form");
      var post_objects = new Array();
      
      form_object.find("input, textarea").each(function(){
          var nm = $(this).attr("name");
          var val = $(this).val();
          post_objects.push(nm+"="+val);
      });
      //var scroll = $(document).scrollTop();
      //var scr_width = $(document).width();
      //var scr_height = $(window).height();
      //$("#ajax-status").height($(document).height());
      //$("#ajax-status").width($(document).width());
      //$("#ajax-status-window").css("top", scr_height / 2 - $("#ajax-status-window").height() / 2);
      $("#ajax-status").show();
      $("#ajax-status-window").fadeIn();
      $("#ajax-status-window .close_link").show();
      $("body").bind("keypress", function(event){
          //если нажат Esc
          if(event.keyCode == 27){
              $("#ajax-status-window").fadeOut('normal', function(){
                  $("#ajax-status").hide();
              });
          }
      });
      //привязываем события закрытия окна при клике на ссылку
      $("#ajax-status-window div a").bind("click", function(event){
          $("#ajax-status-window").fadeOut('normal', function(){
              $("#ajax-status").hide();
              $("#ajax-status-window p.wait").show();
              $("#ajax-status-window p.complete").hide();
              $("#ajax-status-window p.error").hide();
          });
          return false;
      });

      $.post(form_object.attr("action"), post_objects[0]+"&"+post_objects[1]+"&"+post_objects[2]+"&"+post_objects[3]+ "&"+post_objects[4]+"&"+post_objects[5]+"&"+post_objects[6], function(data){
          $("#ajax-status-window p.wait").hide();
          if(data != "form_add_error"){
              $("#ajax-status-window p.complete").show();
              $("#ajax-status-window p.error").hide();
          }
          else{
              $("#ajax-status-window p.complete").hide();
              $("#ajax-status-window p.error").show();
          }
      });
      return false;
	});
});
