$.noConflict();
jQuery(document).ready( function ($) {
  //контрастная версия
  function setcookie(a,b,c) {if(c){var d = new Date();d.setDate(d.getDate()+c);}if(a && b) document.cookie = a+'='+b+(c ? '; path=/; expires='+d.toUTCString() : '');else return false;}
  function getcookie(a) {var b = new RegExp(a+'=([^;]){1,}');var c = b.exec(document.cookie);if(c) c = c[0].split('=');else return false;return c[1] ? c[1] : false;}
  var contrastcookie = getcookie("contrast");
  var siteid = $("body").attr("siteid");
  var siteDir = '/';
  if (siteid == 's1') {
    var usualversiontext = 'Обычная версия';
    var contrastversiontext = 'Контрастная версия';
  }
  else {
    var usualversiontext = 'Normal version';
    var contrastversiontext = 'Contrast version';
    siteDir = '/en/'
  }
  if (contrastcookie == "yes") {
    $("body").attr("id","contrast");
    $(".contrtumbler").html("<a href=\"#\"><span></span>"+usualversiontext+"</a>").attr("version", "1");
    $('a#logo').html('<img src="/bitrix/templates/sberbank_new/images'+siteDir+'new_logo_contrast.gif" />');
  }
  else {
    $('a#logo').html('<img src="/bitrix/templates/sberbank_new/images'+siteDir+'new_logo.gif" />');
  }

  $(".contrtumbler").click(function () {  
    if ($(this).attr("version") == "0") {
      $(this).html("<a href=\"#\"><span></span>"+usualversiontext+"</a>").attr("version", "1");
      $("body").attr("id","contrast");
      $('a#logo').html('<img src="/bitrix/templates/sberbank_new/images'+siteDir+'new_logo_contrast.gif" />');
      setcookie("contrast","yes",10);
    }
    else {
      $(this).html("<a href=\"#\"><span></span>"+contrastversiontext+"</a>").attr("version", "0");
      $("body").attr("id","work");
      $('a#logo').html('<img src="/bitrix/templates/sberbank_new/images'+siteDir+'new_logo.gif" />');
      setcookie("contrast","no",10);
    }
    jQuery('body').delay(300).animate({scrollTop:0}, 'slow');
  });

  //скрипты инструментов
  $('#share_item .email').click(function() {
    modalShow($('#email_friend_form').html());
    return false;
  });

  if ($('.ef_form .errortext').length != 0) {
    modalShow($('#email_friend_form').html());
  }

  if ($('.ef_form .mf-ok-text').length != 0) {
    modalShow($('#email_friend_form').html());
    setTimeout('modalClose()', 3000);
  }

  if ($('.mfeedback .errortext').length != 0) {
    modalShow($('#feedback_form').html());
  }

  if ($('.mfeedback .mf-ok-text').length != 0) {
    modalShow($('#feedback_form').html());
    setTimeout('modalClose()', 3000);
  }

  $('#overlay, #modal_window .close').click(function() {
    modalClose();
    return false;
  });

  //меню история просмотров
  var mouseyes = false;
  var mousenow = false;
  $('.rm-chasy').mouseenter(function () {
    $('.tools_drop_menu').fadeIn('200');
    mousenow = true;
  });

  $('.rm-chasy').mouseleave(function () {
    mousenow = false;
  });

  $('.tools_drop_menu').mouseleave(function () {
    $(this).fadeOut('200');
    mouseyes = false;
  });

  $('.tools_drop_menu').mouseenter(function () {
    mouseyes = true;
  });
  setInterval(function () {
    if (mouseyes == false && mousenow == false) {
      $('.tools_drop_menu').fadeOut('200');
    }
  }, 2000);

  $('#slideshow, #videoslides').slides({
    effect: 'fade',
    /*crossfade: true,*/
    play: 5000,
    pause: 1500,
    pagination: true,
    generatePagination: true,
    hoverPause: true
  });
  
  $('#slideshow2').slides({
    effect: 'fade',
    crossfade: false,
    play: 5000,
    pause: 1500,
    pagination: true,
    generatePagination: true,
    hoverPause: true
  });
      
  // Тултип
  $(".up").hover(function () {
        tip = $(this).find('span');
        tip.show();
    }, function () {
        tip.hide();
  }).mousemove(function (e) {
    var pos = $('#content-box').position();
        var mousex = e.pageX - pos.left + 20;
        var mousey = e.pageY - pos.top + 20;
    tip.css({  top: mousey, left: mousex });
  });
  
  //Share
  $('#share').hover(function(){
    $(this).children('ul').show();
  }, function(){
    $(this).children('ul').hide();
  });

  $(".read-report").on("click", function(){
    $(this).addClass("hidden");
    $("#submenu").removeClass("hidden");
  });

  $("#main #block2 a").on("click", function(e){
    e.preventDefault();
    $(".video-box").removeClass("hidden").on("click",function(){
      $(this).addClass("hidden")
    })
  });

  $("#main #block1,#main #slideshow,#main #block2,#main #slideshow2").addClass("shown");

  $('.modal-close').on("click touchstart", function (e) {
    e.preventDefault();
    $(this).parent().hide();
    $('#anmodbox').hide()
    $('body').css({'overflow':'auto'});
    return false;
  });

  $('body').on('click touchstart', '#anmodbox .modal-close', function (e) {
    e.preventDefault();
    $(this).parent().parent().hide().empty();
    return false;
  });

  $('.rm-mail, #feedback_bottom').on("click touchstart", function (e) {
    e.preventDefault();
    if ($('#anmodbox').length == 0) {
      $('body').append('<div id="anmodbox"></div>')
    }
    else {
      $('#anmodbox').show();
    }
    $('#mail-feedback').show();
    window.scrollTo($('#mail-feedback').scrollTop(), 0);
    $('body').css({'overflow':'hidden'});
    return false;
  });
});