﻿$(document).ready(
  function () {

      //search-box
      $("#q").focus(function () {
          if (($(this).val() == 'Поиск') || ($(this).val().length == 0)) $(this).removeClass("empty").val('')
      })
      $("#q").blur(function () {
          if (($(this).val() == 'Поиск') || ($(this).val().length == 0)) $(this).addClass("empty").val("Поиск")
      })

      //regions
      $(".current-city a").click(
      function (e) {
          $("#cities #cCities").hide();
          $("#cities #cRegions a").click(function (e) {
              e.preventDefault();
              $.ajax({
                  url: "DOMBuildings.axd",
                  type: 'POST',
                  dataType: 'text',
                  data: {
                      type: "citiesForRegion",
                      regionId: $(this).attr('rid')
                  },
                  success: function (data, textStatus, jqXHR) {
                      var firstChar = data.substring(0, 1);
                      if (firstChar == "#") {
                          var city = data.split('|');
                          //PH bug 5597
                          SaveRegionCookie(geoCookieName, longCurDomain, city[3]);
                          SaveRegionCookie(domGeocookieName, curDomain, city[1]);
                          //PH END
                          window.location = city[0].substr(1);
                      }
                      else if (firstChar == "<") {
                          $("#cities #cRegions").hide();
                          $("#cities #cCities").html(data).show();
                          var docWidth = $('body').width();
                          var popUpWidth = $("#cities").width();
                          $("#cities").css('left', Math.round((docWidth - popUpWidth) / 2) + 'px');
                      }
                  },
                  error: function (jqXHR, textStatus) {
                      alert("err");
                  }
              });
          });
          $("#cities #cRegions").show();
          $("#shadow").fadeIn("fast");
          var docWidth = $('body').width();
          var popUpWidth = $("#cities").width();
          $("#cities").css('left', Math.round((docWidth - popUpWidth) / 2) + 'px').fadeIn("fast");
          e.preventDefault();
      }
    )
      $("#shadow").click(
      function () {
          closeCities();
      }
    )
      $("#cities .closer").click(
      function () {
          closeCities();
      }
    )
      $("#landing .popup").click(
      function () {
          $(".current-city a").trigger('click');
          return false;
      }
    )


      //slider
      $(".slider h3").click(
      function () {
          var x = $(this).parent()
          if (x.hasClass('opened')) {
              x.find(".holder").hide();
              x.removeClass("opened");
          }
          else {
              x.find(".holder").show();
              x.addClass("opened");
          }
          return false
      }
    )

      //dlists
      $('.dlist dt').click(
      function () {
          var dt = $(this);
          var dd = dt.next('dd');
          if (dd.is(":visible")) {
              dt.removeClass("opened");
              dd.fadeOut('fast');
          }
          else {
              dt.addClass("opened");
              dd.fadeIn('fast');
          }
          return false
      }
    )

      $("#kol, #time").bind("focus", function () {
          $(this).val("");
          $(this).removeClass("valcol");
      });

      //forms
      //$("form").not(".search-box form, .connect form").jqTransform({ imgPath: "/f/i/forms/" });

      $(".binfo").click(function () {
          $(".mcol .mopen").removeClass("mopen");
          $(this).parents(".mcol li").toggleClass("mopen");
      })
      $(".map-buble .close").click(function () {
          $(this).parents(".mcol .mopen").removeClass("mopen");
      })

      $(".mb-link").click(function () {
          $(".mb-serv .mopen").removeClass("mopen");
          $(this).parents(".mb-serv li").toggleClass("mopen");
          return false;
      })
      $(".map-buble .close").click(function () {
          $(this).parents(".mb-serv .mopen").removeClass("mopen");
          return false;
      })

      $(".mm-kol").click(function () {
          $(".map-marker-open").removeClass("map-marker-open");
          $(".map-wrap3").addClass("mw-index");
          $(this).parents(".map-marker").addClass("map-marker-open");
          return false;
      })
      $(".map-wrap3").click(function () {
          $(".mw-index").removeClass("mw-index");
          $(".map-marker-open").removeClass("map-marker-open");
      })
      $(".map-buble-close").click(function () {
          $(".mw-index").removeClass("mw-index");
          $(this).parents(".map-marker-open").removeClass("map-marker-open");
      })

      $(".serv-h6 a").click(function () {
          $(this).parents(".services").toggleClass("serv-open");
          return false;
      })

      $('.fl-popup span').click(
      function () {
          var flashvars = {
      };
      var params = {
          menu: "false",
          wmode: "transparent"
      };
      var attributes = {
  };
  $("#shadow").height($(document).height()).addClass("black").show();
  $("#flcontent").css('top', parseInt($(window).scrollTop() + 100, 10) + "px")
  $("#flcontent").show();
  $("#flcontent2").show();
  swfobject.embedSWF("flash/index.swf", "flcontent2", "667", "285", "10.0.0", "expressInstall.swf", flashvars, params, attributes);
}
    );


$(".h-infoform-wrap2, .inf_form").hide();
$(".full_link").click(function () {
    $(this).toggleClass("fl_minus");
    $(".h-infoform-wrap2").toggle();
    return false;
});
$(".full_no").click(function () {
    $(this).toggleClass("fl_minus");
    $(".inf_form").not(".b-infoform2 .inf_form").toggle();
    $(".b-infoform2 .inf_form").hide();
    return false;
});
$(".full_yes").click(function () {
    $(".b-infoform2 .inf_form").toggle();
    $(".h-infoform-wrap2 .fl_minus").removeClass("fl_minus");
    $(".inf_form").not(".b-infoform2 .inf_form").hide();
    return false;
});
}
)

function closeCities()
{
	$("#cities").fadeOut("fast")
	$("#shadow").removeClass("black").hide()
	$("#flcontent").hide()
	$("#flcontent2").hide()
}

function setDefaultCity()
{
	alert("дефолтный город выбран");
}

function mtsRegionsSetCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
  ((expires) ? "; expires=" + expires : "") +
  ((path) ? "; path=" + path : "") +
  ((domain) ? "; domain=" + domain : "") +
  ((secure) ? "; secure" : "");
}

function SaveRegionCookie(cookiName, domain, val) {
    var expires = new Date();
    expires.setYear(expires.getFullYear() + 1);
    mtsRegionsSetCookie(cookiName, val, expires.toUTCString(), '/', domain, null)
} 

