function copy_to_submenu($node) {
  if ($node.parent().find('ul').length) {
    $('#submenu').html('<ul>'+$node.parent().find('ul:first').html()+'</ul><div style="clear:both"></div>');
  }
}

$(function() {
  $('.stdform label.required').append(' <span class="star">*</span>');
  
  // подсказки в формах
  $('#s').focus(function() {
    $('label[for='+$(this).attr('id')+']').hide();
  }).blur(function() {
    if ($(this).val() == '') $('label[for='+$(this).attr('id')+']').show();
  }).change(function() {
    if ($(this).val() != '') $('label[for='+$(this).attr('id')+']').hide();
  }).mouseover(function() {
    if ($(this).val() != '') $('label[for='+$(this).attr('id')+']').hide();
  });
  
  $('#s').each(function() {
    if ($(this).val() != '') $('label[for='+$(this).attr('id')+']').hide();
  });
  
  // глагне меню
  $('#mainmenu a').each(function(index) {
    if (document.location.pathname.indexOf($(this).attr('href')) != -1 && $(this).attr('href').length > 4
    || document.location.pathname == $(this).attr('href')) {
      $(this).addClass('sel').addClass('_sel');
      $(this).parents('li').find('a:first').addClass('sel').addClass('_sel');
    }
  });
  copy_to_submenu($('#mainmenu>li>a.sel'));

  // hover на глагне меню
  $('#mainmenu>li').mouseenter(function() {
    $(this).find('ul').show();
    $(this).find('a:first').addClass('sel');
  }).mouseleave(function() {
    $(this).find('ul').hide();
    if (!$(this).find('a:first').hasClass('_sel')) $(this).find('a:first').removeClass('sel');
  })
  
  // клик на глагне меню
  $('#mainmenu>li>a').click(function() {
    copy_to_submenu($(this));
  });
});


function addSlideshowGroup(group_name) {
  hs.addSlideshow({
    slideshowGroup: group_name,
    interval: 5000,
    repeat: false,
    useControls: true,
    fixedControls: 'fit',
    overlayOptions: {
        opacity: .8,
        position: 'bottom center',
        hideOnMouseOut: true
    }
  });
}
