/*
var mask_id = null;
function menu_mask_hide() {
  if ($('#header_menu_mask_'+mask_id).html() == '' && (mask_id >= 1 || mask_id <= 10)) {
    setTimeout(
      function() {
        $('#header_menu_mask_'+mask_id).hide();
        $('#header_menu_mask_'+(mask_id+1)).show().css({opacity: 100 / (10 - 1) * (10 - mask_id) / 100});
        mask_id = (mask_id == 10) ? null : mask_id + 1;
        menu_mask_hide();
      },
      150
    );
  }
}
function menu_mask_show() {
  if ($('#header_menu_mask_'+mask_id).html() == '' && (mask_id >= 1 || mask_id <= 10)) {
    setTimeout(
      function() {
        if (mask_id > 1) $('#header_menu_mask_'+mask_id).hide();
        $('#header_menu_mask_'+(mask_id-1)).show().css({opacity: 100 / (10) * (10 - mask_id) / 100});
        mask_id = mask_id - 1;
        menu_mask_show();
      },
      150
    );
  }
}
function menu_hover(menu_item_id) {
  if (mask_id == null) mask_id = 1;
  menu_mask_hide();
  $('#header_menu_peoples .peoples1').fadeOut(1500);
  $('#header_menu_peoples .peoples2').fadeIn(1500);
  $('#header_menu .menu_item').addClass('menu_item_opacity');
  $('#header_menu #'+menu_item_id).removeClass('menu_item_opacity');
  $('#header_menu .menu_item_opacity').animate({opacity: 0.25}, 1500);
}
function menu_out(menu_item_id) {
  if (mask_id == null) mask_id = 10;
  menu_mask_show();
  $('#header_menu_peoples .peoples1').fadeIn(1500);
  $('#header_menu_peoples .peoples2').fadeOut(1500);
  $('#header_menu .menu_item_opacity').animate({opacity: 1}, 1500);
  $('#header_menu .menu_item').removeClass('menu_item_opacity');
}
*/

var header_menu = {
  current_mask_id: 0,
  show_timeout_id: null,
  hide_timeout_id: null,
  init: function() {
    $('#header_menu')
      .mouseover(function() {
        header_menu.animate_out($(this).parents('.menu_item').attr('id'));
      })
      .mouseout(function() {
        header_menu.animate_in($(this).parents('.menu_item').attr('id'));
      });
    $('#header_menu a')
      .mouseover(function() {
        if ($('#header_menu #'+$(this).parents('.menu_item').attr('id')).attr('id') != $('#header_menu .menu_item_active').attr('id')) {
          $('#header_menu .menu_image').fadeOut(1000);
          $('#header_menu_image_'+$(this).parents('.menu_item').attr('id').replace('header_menu_item_', '')).fadeIn(1000);
        }
        $('#header_menu .menu_item').removeClass('menu_item_active').addClass('menu_item_opacity');
        $('#header_menu #'+$(this).parents('.menu_item').attr('id')).removeClass('menu_item_opacity').addClass('menu_item_active');
        $('#header_menu .menu_item_opacity').animate({opacity: 0.45/*, filter: 'progid:DXImageTransform.Microsoft.Alpha(opacity=45)'*/}, 'high');
      })
      .mouseout(function() {
        $('#header_menu .menu_item_opacity').animate({opacity: 1/*, filter: 'progid:DXImageTransform.Microsoft.Alpha(opacity=100)'*/}, 'high');
        $('#header_menu .menu_item').removeClass('menu_item_opacity');
      });
    for (i = 1; i <= $('#header_menu .menu_mask_opacity').length; i++) {
      var opacity_value = 100 / (10 - 1) * (10 - i);
      //alert($('#header_menu_mask_'+i).attr('rel'));
      $('#header_menu_mask_'+i).attr('style', 'opacity: '+(opacity_value / 100)+';');
    }
  },
  animate_in: function(item_id) {
    if (header_menu.current_mask_id < 1 || header_menu.current_mask_id > 10) {
      header_menu.current_mask_id = 10;
    }
    header_menu.show_mask();
  },
  animate_out: function(item_id) {
    if (header_menu.current_mask_id < 1 || header_menu.current_mask_id > 10) {
      header_menu.current_mask_id = 1;
    }
    header_menu.hide_mask();
  },
  hide_mask: function() {
    clearTimeout(header_menu.hide_timeout_id);
    if ($('#header_menu_mask_'+header_menu.current_mask_id).html() == '' && (header_menu.current_mask_id >= 1 || header_menu.current_mask_id <= 10)) {
      //$('body').append(header_menu.current_mask_id+'<br />');
      header_menu.show_timeout_id = setTimeout(
        function() {
          $('#header_menu_mask_'+header_menu.current_mask_id).hide();
          $('#header_menu_mask_'+(header_menu.current_mask_id+1)).show();
          //var opacity_value = 100 / (10 - 1) * (10 - header_menu.current_mask_id);
          //$('#header_menu_mask_'+(header_menu.current_mask_id+1)).show().css({opacity: opacity_value / 100, filter: 'progid:DXImageTransform.Microsoft.alpha(opacity='+opacity_value+')'});
          header_menu.current_mask_id = header_menu.current_mask_id + 1;
          header_menu.hide_mask();
        },
        100
      );
    } else {
      clearTimeout(header_menu.show_timeout_id);
    }
  },
  show_mask: function() {
    clearTimeout(header_menu.show_timeout_id);
    if ($('#header_menu_mask_'+header_menu.current_mask_id).html() == '' && (header_menu.current_mask_id >= 1 || header_menu.current_mask_id <= 10)) {
      //$('body').append(header_menu.current_mask_id+'<br />');
      header_menu.hide_timeout_id = setTimeout(
        function() {
          if (header_menu.current_mask_id > 1) $('#header_menu_mask_'+header_menu.current_mask_id).hide();
          $('#header_menu_mask_'+(header_menu.current_mask_id-1)).show();
          //var opacity_value = 100 / (10 - 1) * (10 - header_menu.current_mask_id);
          //$('#header_menu_mask_'+(header_menu.current_mask_id-1)).show().css({opacity: opacity_value / 100, filter: 'progid:DXImageTransform.Microsoft.alpha(opacity='+opacity_value+')'});
          header_menu.current_mask_id = header_menu.current_mask_id - 1;
          header_menu.show_mask();
        },
        100
      );
    } else {
      clearTimeout(header_menu.hide_timeout_id);
    }
  }
}

$(document).ready(function() {

  /**
   * Меню.
   **/
  //$('#header_menu a').attr('onmouseover', 'menu_hover($(this).parents(\'.menu_item\').attr(\'id\'));');
  //$('#header_menu a').attr('onmouseout', 'menu_out($(this).parents(\'.menu_item\').attr(\'id\'));');
  header_menu.init();

  /**
   * Блок с вакансиями.
   */
  $('.block_jobs ul li a').mouseover(function() {
    if ($('#'+$(this).attr('rel')).css('display') == 'none') {
      $('.block_jobs .job_bg').fadeOut('high');
      $('#'+$(this).attr('rel')).fadeIn('high');
    }
  });

  /**
   * Блок с категориями каталога.
   */
  $('.block_catalog ul li a').mouseover(function() {
    if ($('#'+$(this).attr('rel')).css('display') == 'none') {
      $('.block_catalog .category_bg').fadeOut('high');
      $('#'+$(this).attr('rel')).fadeIn('high');
    }
  });

  /**
   * Просмотр фотографий.
   **/
  $('a.photo_view').lightBox({
    overlayBgColor: 	  	'#AEB7CA',
    overlayOpacity:	  		0.8,
    fixedNavigation:  		false,
    imageLoading:		    	'/media/js/jquery/lightbox-0.5/images/lightbox-ico-loading.gif',
    imageBtnPrev:		    	'/media/js/jquery/lightbox-0.5/images/custom-btn-prev.gif',
    imageBtnNext:		    	'/media/js/jquery/lightbox-0.5/images/custom-btn-next.gif',
    imageBtnClose:	  		'/media/js/jquery/lightbox-0.5/images/custom-btn-close.gif',
    imageBlank:				    '/media/js/jquery/lightbox-0.5/images/lightbox-blank.gif',
    containerBorderSize:	10,
    containerResizeSpeed:	400,
    txtImage:				      'Изображение',
    txtOf:					      'из',
    keyToClose:				    'c',
    keyToPrev:			     	'p',
    keyToNext:			     	'n',
    activeImage:	     		0
  });

});
