var windowWidth;
var searchText = 'поиск';

$(document).ready(function() {
   $(".pngFix").pngFix();
   if (typeof window['checkFlash'] == 'function') checkFlash();
   $("#clientsBgr").bgscroll({ scrollSpeed: 15, direction: 'h' });
   $(".cabinetForm").fancybox({ 'titleShow': false });
   $(".menuTLink").hover(
      function() { var id = $(this).attr('id').match(/^menuT(L|R)?([0-9]+)$/)[2]; showSubmenu(id); },
      function() { var id = $(this).attr('id').match(/^menuT(L|R)?([0-9]+)$/)[2]; hideSubmenu(id); }
   );
   $(".submenuT").hover(
      function() { var id = $(this).attr('id').match(/^submenuT([0-9]+)$/)[1]; showSubmenu(id); },
      function() { var id = $(this).attr('id').match(/^submenuT([0-9]+)$/)[1]; hideSubmenu(id); }
   );
   $(".submenuTS").hover(
      function() { $(this).css('background', 'url("image/top-menu-bgr.gif") repeat-x left top'); },
      function() { $(this).css('background', '#EDEEF0'); }
   );
   //Скролл логотипов на главной
   if ($('.scrollable').length) $(".scrollable").scrollable({ circular: true });
   //
   if ($("#gallery a[rel=fancy]").length) $("#gallery a[rel=fancy]").fancybox({ 'hideOnContentClick': true, 'overlayShow': true, 'overlayOpacity': 0.5, 'speedIn': 1000, 'speedOut': 600, 'titlePosition': 'inside', 'transitionIn': 'elastic', 'transitionOut': 'elastic', 'autoScale': false });
   if ($("#gallery a[rel=fancy2]").length) $("#gallery a[rel=fancy2]").fancybox({ 'hideOnContentClick': true, 'overlayShow': true, 'overlayOpacity': 0.5, 'speedIn': 1000, 'speedOut': 600, 'titlePosition': 'inside', 'transitionIn': 'elastic', 'transitionOut': 'elastic', 'autoScale': false });
   //Выделение ссылок фансибокса пунктирным подчёркиванием
   if ($("#gallery").length) {
      $("#gallery a").each(function() {
         var rel = $(this).attr('rel');
         if ((rel == 'fancy' || rel == 'fancy2' || rel == 'fancy3') && !$(this).html().match(/<img /i)) {
            $(this).css('text-decoration', 'none');
            $(this).css('border-bottom', '#018cd4 1px dashed');
         }
      });
   }
   //
   //Показ формы заказа
   if ($('.formLShow').length) $(".formLShow").click(function() {
      $(".formLHid").each(function() {
         if ($(this).hasClass('dn')) $(this).fadeIn(500);
      });
   });
   //
   if ($(".logo_table a").length) $('.logo_table a').easyTooltip();
   $(".pbCl").click(function() {
      $(this).parent().find('.pBa').removeClass('pBa').addClass('pB');
      $(this).removeClass('pB').addClass('pBa');
      var idC = $(this).attr('class').match(/pB([1-4])/)[1];
      $(".pBT").hide();
      $(".pBT"+idC).show();
   });
   $(".develop").
   hover(
      function() { var idC = $(this).attr('class').match(/dev([1-5])/)[1]; $(this).css('background-position', (0 - (idC - 1)*155)+'px -63px'); },
      function() { var idC = $(this).attr('class').match(/dev([1-5])/)[1]; $(this).css('background-position', (0 - (idC - 1)*155)+'px top'); }
   ).
   click(function() { document.location.href = $(this).find('a').attr('href'); });
   $(".IMBtn1, .IMBtn2, .IMBtn3, .IMBtn4").
   hover(
      function() { var idC = $(this).attr('class').match(/IMBtn([1-4])/)[1]; $(".IMBtn").css('background-position', 'left '+(0 - idC*54)+'px'); },
      function() { $(".IMBtn").css('background-position', 'left top'); }
   );
   $(".IMBtnS1, .IMBtnS2, .IMBtnS3, .IMBtnS4").
   hover(
      function() { var idC = $(this).attr('class').match(/IMBtnS([1-4])/)[1]; $(".IMBtn").css('background-position', 'left '+(0 - idC*54)+'px'); },
      function() { $(".IMBtn").css('background-position', 'left top'); }
   );
   $(".IMBtn1").click(function() { document.location.href = 'http://www.interlabs-promo.ru/banners.htm'; });
   $(".IMBtn2").click(function() { document.location.href = 'http://www.interlabs-promo.ru/social.htm'; });
   $(".IMBtn3").click(function() { document.location.href = 'http://www.interlabs-promo.ru/search-content.htm'; });
   $(".IMBtn4").click(function() { document.location.href = 'http://www.interlabs-promo.ru/context.htm'; });
});

$(window).load(bodySize);
$(window).resize(bodySize);

function bodySize() {
   windowWidth = $("body").innerWidth();
   if (windowWidth <= 1024) $(".minwidth").width(990);
   else if (windowWidth > 1280) $(".minwidth").width(1280);
   else $(".minwidth").width("100%");
}

function showSubmenu(id) {
   if (!$("#menuT"+id).hasClass("menuSel2")) {
      $("#menuTL"+id).addClass("menuSel2");
      $("#menuT"+id).addClass("menuSel2");
      $("#menuTR"+id).addClass("menuSel2");
      if ($("#submenuT"+id).length) {
         if ($("#submenuT"+id).css('display') == 'none' || !$("#submenuT"+id).css('display')) {
            var offset = $("#menuTL"+id).offset();
            $("#submenuT"+id).css({'left': offset['left']+($.browser.mozilla ? 0 : 1), 'top': (offset['top'] + 30 + ($.browser.mozilla || $.browser.opera ? 0 : 3))});
            $("#submenuT"+id).show();
         }
      }
   }
}

function hideSubmenu(id) {
   if (!$("#menuT"+id).hasClass("menuTA") && $("#menuT"+id).hasClass("menuSel2")) {
      $("#menuTL"+id).removeClass("menuSel2");
      $("#menuT"+id).removeClass("menuSel2");
      $("#menuTR"+id).removeClass("menuSel2");
      if ($("#submenuT"+id).length) {
         if ($("#submenuT"+id).css('display') == 'block') {
            $("#submenuT"+id).hide();
         }
      }
   }
}

function fnCheckSearchForm(f) {
   if (!f.search.value.match(/^.+$/) || f.search.value == searchText) {
      alert("Укажите поисковый запрос!");
      f.search.focus();
      return false;
   }
   return true;
}

function checkCabForm(form_name) {
    if (!form_name.loginInterlabs.value.match(/.+/)) {
      alert("Укажите логин для входа в кабинет!");
      form_name.loginInterlabs.focus();
      return false;
    }
    if (!form_name.passwordInterlabs.value.match(/.+/)) {
      alert("Укажите пароль для входа в кабинет!");
      form_name.passwordInterlabs.focus();
      return false;
    }
   return true;
}

function showBigPic(idP) {
   for (var k in picsLeft) if (k != idP) $("#picSmallLeft"+k).attr('src', picsLeft[k]['pic_small']);
   $("#picSmallLeft"+idP).attr('src', picsLeft[idP]['pic_small_sel']);
   $("#bigPicPortfolio").attr('src', picsLeft[idP]['pic_big']);
}
