$(document).ready(function() {

  /**
   * Слайдер.
   */
  var SLIDER_COUNT = $('#header_slider .slide').length;
  var SLIDER_WIDTH = 990;
  var SLIDE_LINK_WIDTH = 21;
  var SLIDE_WIDTH = SLIDER_WIDTH - (SLIDE_LINK_WIDTH * SLIDER_COUNT);
  var slider_in_action = false;
  function slider_move(i, timeout) {
    setTimeout(
      function() {
        if (slider_in_action === false) {
          slider_in_action = true;
          if ($('#header_slider .slide:nth-child('+(i+1)+')').attr('rel') != 'open') {
            $('#header_slider .slide[rel=open] .link .bg_blue').show();
            $('#header_slider .slide[rel=open] .link .bg_green').hide();
            $('#header_slider .slide[rel=open] .content').hide();
            $('#header_slider .slide[rel=open]').animate(
              {marginRight: '0', width: SLIDE_LINK_WIDTH+'px'}
            ).removeAttr('rel');
            $('#header_slider .slide:nth-child('+(i+1)+') .link .bg_blue').hide();
            $('#header_slider .slide:nth-child('+(i+1)+') .link .bg_green').show();
            $('#header_slider .slide:nth-child('+(i+1)+') .content').show();
            $('#header_slider .slide:nth-child('+(i+1)+')').animate(
              {marginRight: '-5px', width: SLIDE_WIDTH+'px'},
              'normal',
              'swing',
              function() {
                slider_in_action = false;
              }
            ).attr('rel', 'open');
          }
        }
      },
      timeout
    );
  }
  $('#header_slider .slide').click(function() {
    if ($(this).attr('rel') == 'open') {
      window.location.href = $(this).attr('href');
    }
  });
  $('#header_slider .slide').css({width: SLIDE_LINK_WIDTH+'px'});
  $('#header_slider .slide').each(function(i) {
    $('#header_slider .slide:nth-child('+(i+1)+') .link').click(function() {
      slider_move(i, 0);
    });
    $('#header_slider .slide:nth-child('+(i+1)+') .link').hover(function() {
      //slider_move(i, 500);
    });
    if (URL_CURRENT_PARENT == $('#header_slider .slide:nth-child('+(i+1)+')').attr('href')) {
      slider_move(i, 0);
    }
  });
  $('#header_slider .slide:nth-child('+1+') .link .bg_blue').hide();
  $('#header_slider .slide:nth-child('+1+') .link .bg_green').show();
  $('#header_slider .slide:nth-child('+1+') .content').show();
  $('#header_slider .slide:nth-child('+1+')').css({marginRight: '-5px', width: SLIDE_WIDTH+'px'}).attr('rel', 'open');

  /**
   * Просмотр фотографий.
   */
  $('a.photo_view').lightBox({
    overlayBgColor: 	  	'#03192F',
    overlayOpacity:	  		0.8,
    fixedNavigation:  		false,
    imageLoading:		    	URL_BASE+'media/js/jquery/lightbox-0.5/images/lightbox-ico-loading.gif',
    imageBtnPrev:		    	URL_BASE+'media/js/jquery/lightbox-0.5/images/custom-btn-prev.gif',
    imageBtnNext:		    	URL_BASE+'media/js/jquery/lightbox-0.5/images/custom-btn-next.gif',
    imageBtnClose:	  		URL_BASE+'media/js/jquery/lightbox-0.5/images/custom-btn-close.gif',
    imageBlank:				    URL_BASE+'media/js/jquery/lightbox-0.5/images/lightbox-blank.gif',
    containerBorderSize:	10,
    containerResizeSpeed:	400,
    txtImage:				      'Изображение',
    txtOf:					      'из',
    keyToClose:				    'c',
    keyToPrev:			     	'p',
    keyToNext:			     	'n',
    activeImage:	     		0
  });
});
