var mainpage = window.location.href;
var iminusstd = 186;//195
var iminuszoom = 31;
var iminusframe = iminusstd;
function sh(e) {
  var fram = document.getElementById('mydiv');
  $(fram).text($(e).text());
}
function setmainheight() {
  var fram = document.getElementById('mainframe');
  $(fram).height($(window).height() - iminusframe);
}
function setmainframeheight() {
  setmainheight();
  $(window).resize(setmainheight);
}
function resizemainframe() {
  var fram = document.getElementById('content');
  var fcont = document.getElementById('container');
  var fhead = document.getElementById('header');
  var fside = document.getElementById('sidebar');
  var ffoot = document.getElementById('footer');
  var flay = document.getElementById('layout');
  var bexp = document.getElementById('bexpand');
  var iexp = document.getElementById('iexpand');
  if (iminusframe == iminusstd) {
    fram.style.margin = '0';
    flay.style.margin = '0';
    fcont.style.width = '100%';
    fhead.style.display = 'none';
    fside.style.display = 'none';
    ffoot.style.display = 'none';
    bexp.title = 'Свернуть';
    iexp.src = 'images/bcollapse.png';
    iminusframe = iminuszoom;
  } else {
    fram.style.margin = '';
    flay.style.margin = '';
    fcont.style.width = '';
    fhead.style.display = '';
    fside.style.display = '';
    ffoot.style.display = '';
    bexp.title = 'Развернуть';
    iexp.src = 'images/bexpand.png';
    iminusframe = iminusstd;
  }
  setmainheight();
}
function setmainframe(sturl, stthis) {
  var fram = document.getElementById('mainframe');
  fram.src = sturl;
  sh(stthis);
}
function gomainurl() {
  if (mainpage[mainpage.length - 1] == '#') {
    mainpage = mainpage.slice(0, -1);
  }
  window.location.href = mainpage;
}
function digitalWatch() {
  setInterval(function () {
    var vdate = new Date();
    var h = vdate.getHours();
    var m = vdate.getMinutes();
    var s = vdate.getSeconds();
    var dw = document.getElementById('digital_watch');
    h = (h < 10) ? '0' + h : h;
    m = (m < 10) ? '0' + m : m;
    s = (s < 10) ? '0' + s : s;
    dw.innerHTML = h + ':' + m + ':' + s;
  }, 1000);
}
function openmenu() {
  var checkCookie = $.cookie("sub-nav");
  if (checkCookie != "") {
    $.removeCookie("sub-nav");
  }
  checkCookie = $.cookie("sub-link");
  if (checkCookie != "") {
    $.removeCookie("sub-link");
  }
  $('#menu li a').removeClass('active');
  $('#menu li ul li a').removeClass('active');
  $('#menu li ul').slideDown();
}
function closemenu() {
  var checkCookie = $.cookie("sub-nav");
  if (checkCookie != "") {
    $.removeCookie("sub-nav");
  }
  checkCookie = $.cookie("sub-link");
  if (checkCookie != "") {
    $.removeCookie("sub-link");
  }
  $('#menu li a').removeClass('active');
  $('#menu li ul li a').removeClass('active');
  $('#menu li ul').slideUp();
  gomainurl();
}
$(document).ready(function () {
  var checkCookie = $.cookie("sub-nav");
  if (checkCookie != "") {
    $('#menu > li.sub > a:eq(' + checkCookie + ')').addClass('active').next().show();
  }
  $('#menu > li.sub > a').click(function () {
    var navIndex = $('#menu > li.sub > a').index(this);
    $.cookie("sub-nav", navIndex);
    $('#menu li ul').slideUp();
    $('#menu li a').removeClass('active');
    if ($(this).next().is(":visible")) {
      $(this).next().slideUp();
      $('this').removeClass('active');
    } else {
      $(this).next().slideToggle();
      $(this).addClass('active');
    }
  });
  var checkCookie = $.cookie("sub-link");
  if (checkCookie != "") {
    $('#menu > li.sub > ul li a:eq(' + checkCookie + ')').addClass('active');
  }
  $('.sub ul li a').click(function () {
    var subIndex = $('.sub ul li a').index(this);
    $.cookie("sub-link", subIndex);
    $('.sub ul li a').removeClass('active');
    $(this).addClass('active');
  });
});
