var searchText = '';
var searchMess = '';
var is_ie = (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent));
function GID(id) { return (is_ie) ? document.all[id] : document.getElementById(id); }

function hashIsEmpty(hash) {
    for (var k in hash) return false;
    return true;
}

function hashLength(hash) {
    var ret = 0;
    for (var k in hash) ret = ret + 1;
    return ret;
}

$(document).ready(function() {
   $(document).pngFix();
   checkFlash();
   if ($("#galleryTop a[rel=fancy]").length) $("#galleryTop a[rel=fancy]").fancybox({ 'hideOnContentClick': true, 'overlayShow': true, 'overlayOpacity': 0.5, 'speedIn': 1000, 'speedOut': 600, 'titlePosition': 'inside', 'transitionIn': 'elastic', 'transitionOut': 'elastic' });
   $(".zobuch_txt").fancybox({ 'titleShow': false });

   $('.tel_txt').click(function(){ $('#form_zvonok').show(); })
   var ColorBoxHeight;
   if (($.browser.msie) && ($.browser.version == '6.0' || $.browser.version == '7.0')) ColorBoxHeight = '480px';
   else ColorBoxHeight = '480px';
   $('.tel_txt').colorbox({
      width:"640px",
      height:ColorBoxHeight,
      inline:true,
      href:"#form_zvonok",
      onCleanup:function(){
         $('#form_zvonok input[name=fio]').val('');
         $('#form_zvonok input[name=company]').val('');
         $('#form_zvonok input[name=phone]').val('');
         $('#form_zvonok input[name=email]').val('');
         $('#form_zvonok textarea[name=time]').val('');
         $('#form_zvonok textarea[name=text]').val('');
         $('#form_zvonok').hide();
      }
   });

   if ($("a[rel=fancy].example1").length) {
      //carousel();
      $("a[rel=fancy].example1").fancybox({
       'titleShow' : false,
       'transitionIn' : 'fade',
       'transitionOut' : 'fade'
      });
   }
   $(".td1Submenu").
   click(
      function() {
         location.href = $('A:first', this).attr('href');
      }
   ).
   hover(
      function () {
         remove = false;
         if (!$(this).hasClass("td1SubmenuSel")) {
            $(this).removeClass("td1Submenu");
            $(this).addClass("td1SubmenuSel");
            remove = true;
         }
      },
      function () {
         if (remove) {
            $(this).removeClass("td1SubmenuSel");
            $(this).addClass("td1Submenu");
         }
      }
   );
});

$(window).load(bodySize);
$(window).resize(bodySize);

function bodySize() {
   if (($.browser.msie || $.browser.safari) && (document.documentElement.clientWidth || document.body.clientWidth)) {
      $("#tablemain").css('width', ((document.documentElement.clientWidth || document.body.clientWidth) > 1280) ? 1280 : "100%");
   }
   var countCar = ($("#tablemain").width() < 1259 ? 3 : 4);
   if ($("#mycarousel").length) $('#mycarousel').jcarousel({'visible': countCar, scroll: countCar});
}

function fnCheckSearchForm(f) {
   if (!f.search.value.match(/^.+$/) || f.search.value == searchText) {
      alert(searchMess);
      f.search.focus();
      return false;
   }
   return true;
}

function fnCheckMailForm(f) {
   if (f.question.value == '') {
      alert("Укажите вопрос!");
      f.question.focus();
      return false;
   }
   if (!f.code.value.match(/^([0-9]+)$/)) {
      alert("Укажите код!");
      f.code.focus();
      return false;
   }
   return true;
}

function showMenu(idM) {
   var offset = $("#id_mmTop_"+idM).offset();
   var left = offset['left']-($.browser.msie ? 2 : 0);
   var top = offset['top']+34-($.browser.msie ? 2 : 0);
   $("#topMenu"+idM).css({'left': left, 'top': top, 'display': 'block'});
}

function hideMenu(idM) {
   $("#topMenu"+idM).css('display', 'none');
}

function showMenuLeft(idM, flag) {
   var offset = $("#leftSubmenu"+idM).offset();
   var left = offset['left']+30+$("#leftSubmenu"+idM).width()-($.browser.msie ? 2 : 0);
   var top = offset['top']-($.browser.msie ? 2 : 0);
   if (!flag) {
      $("#leftSubmenu"+idM).removeClass("td1Submenu");
      $("#leftSubmenu"+idM).addClass("td1SubmenuSel");
   }
   $("#leftMenu"+idM).css({'left': left, 'top': top, 'display': 'block'});
}

function hideMenuLeft(idM, flag) {
   if (!flag) {
      $("#leftSubmenu"+idM).removeClass("td1SubmenuSel");
      $("#leftSubmenu"+idM).addClass("td1Submenu");
   }
   $("#leftMenu"+idM).css('display', 'none');
}
