var style_on = "img_on";
var style_off = "img_off";

// Перестраиваем ширину блока с массивом картинок
var width_img_array = 875;
var img_array_resize = false;
var width_screen = screen.width;

if(width_screen > 1360){
  img_array_resize = true;
  width_img_array += 165;
  var amount_image_visible = 6;
  // Перестраиваем положение элементов
  document.getElementById("menu_top").style.left = '946px';
  document.getElementById("slogon").style.left = '859px';
}
if(width_screen >= 1024 && width_screen < 1280){
  img_array_resize = true;
  width_img_array -= 165;
  var amount_image_visible = 4;
  // Перестраиваем положение элементов
  document.getElementById("menu_top").style.left = '616px';
  document.getElementById("slogon").style.left = '529px';
}

/* ####  КЛАСС - ИНСТРУМЕНТЫ ДЛЯ РАБОТЫ С ИЗОБРАЖЕНИЯМИ ####*/
/* Inetua ImagesTools v2.0 */
function ImagesTools(){
  var _this = this;
  this.image_array = new Array();
  this.suffix = null;                         // Суффикс додаток для обозначения ID изображений
  this.ln = "thmb_" + this.suffix + "0";
  this.Total_Images = 0;                      // Всего изображений в массиве
  this.total_image_select;
  this.amount_image_visible = 5;              // Максимальное количество уменьшенных изображений, видимых в списке
  this.ImageIndex = 0;                        // Текущий индекс картинки
  this.indexFirst = 0;                        // Стартовый индекс видимого изображения
  this.indexLast = 0;                         // Конечный индекс видимого изображения
  this.img_maxheight = 510;                   // максимальная высота картинки
  this.img_maxwidth = 700;                    // максимальная ширина картинки
  this.wnd_maxwidth = 689;                    // максимальная ширина окна
  this.wnd_maxheight = 478;                   // максимальная высота окна
  this.style_on   = "img_on";
  this.style_off  = "img_off";

  /* #### ПОЛЬЗОВАТЕЛЬСКИЕ МЕТОДЫ */
  // Метод перемещающий маленькие изображения в видимом списке
  this.ScrollingImages = function(direct){
    // Формируем массив изображений для 

    var el;
    for(j = 0; j < this.amount_image_visible; j++){
      if(direct < 0){
        // Устанавливаем стартовый индекс изображению
        if(j == 0){ this.ImageIndex = this.Total_Images - this.indexFirst; }
        this.ImageIndex++;  // увеличиваем индекс для сдвига изображений вправо

       // alert(this.ImageIndex);

        // Если стартовый индекс меньше нуля, то приравниваем 0 и все начинаем сначала
        if(this.ImageIndex < 0){ this.ImageIndex = this.Total_Images + this.ImageIndex; this.indexFirst = 0; }

        // Если стартовый индекс равен кол-ву изображений, то приравниваем 0 и все начинаем сначала
        if(this.ImageIndex == this.Total_Images){ this.ImageIndex = 0;}

        // Если стартовый индекс больше кол-ва изображений, то приравниваем 0 и все начинаем сначала
        if(this.ImageIndex > this.Total_Images){ this.ImageIndex = this.ImageIndex - this.Total_Images; }

        // Если последня иттерация цикла, то запоминаем индекс 
        if(j == (this.amount_image_visible - 1)){
          this.indexFirst++;
        }
        //alert(this.indexFirst);


      }else if(direct > 0){
        // Устанавливаем стартовый индекс изображению
        if(j == 0){ this.ImageIndex = this.indexFirst; }
        this.ImageIndex++;  // увеличиваем индекс для сдвига изображений влево

        // Если достигнут конец массива, то индекс приравнивается 0 и все начинается сначала
        if(this.ImageIndex == this.Total_Images){ this.ImageIndex = 0;}

        // Если последня иттерация цикла, то увеличиваем стартовый индекс 
        if(j == (this.amount_image_visible - 1)){
          this.indexFirst++;
          // Если стартовый индекс равен кол-ву изображений, то приравниваем 0 и все начинаем сначала
          if(this.indexFirst == this.Total_Images){ this.indexFirst = 0;}
        }
      }
      // Присваиваем текущему местоположению новое изображение
      el = document.getElementById("thmb_" + this.suffix + j);
      if(el != null){
        el.src = this.image_array[this.ImageIndex].file_s;
      }
      //alert(this.indexFirst + ' - ' + this.ImageIndex);
    }
  }

  // Метод добавляет изображение в массив изображений
  this.addImage = function(id, file_b, file_s, title){
    var next_key = this.image_array.length;
    this.image_array[next_key] = this._createObj(id, file_b, file_s, title);
  }

  // Метод открывает всплывающий windows popup окно при просмотре картинок
  this.ShowBigImg = function(index_place){
    // Вычисляем текущий индекс изображения согласно ее положения в списке отображения.
    index = this.indexFirst + parseInt(index_place);

    // Определяем размеры текущего окна
    var img_width = (this.image_array[index].width != null ? this.image_array[index].width : this.wnd_maxwidth);
    var img_height = (this.image_array[index].height != null ? this.image_array[index].height : this.wnd_maxheight);

    // Вычисляем середину экрана по вертикали и горизонтали
    var left = parseInt((document.body.clientWidth/2) - (img_width/2));
    var top = parseInt((document.body.clientHeight/2) - (img_height/2));

    newWindow = window.open("","imgWindow","width="+img_width+",height="+img_height+",left="+left+",top="+top);
    newWindow.document.open();
    newWindow.document.write('<html><head><title>ФОТО</title>');
    newWindow.document.write('</head><body style="margin:0;">');
    newWindow.document.write('<div><img id="img_big" src="'+ this.image_array[index].file_b +'" width="'+ img_width +'" height="'+ img_height +'" alt="" />');
    newWindow.document.write('</div></body></html>');
    newWindow.document.close();
    newWindow.focus();
  }

  /* #### СЛУЖЕБНЫЕ МЕТОДЫ */
  // Метод создает свойства для двухмерного массива
  this._createObj = function(file_b, file_s, width_big, height_big, title, id){
    var image_obj = new Array();
    image_obj.file_b = file_b;
    image_obj.file_s = file_s;
    image_obj.width = width_big;
    image_obj.height = height_big;
    image_obj.title = title;
    image_obj.id = id;
    return image_obj;
  }
}


function display_object_properties(object_string){
  // Сохранение объекта
  var actual_object = eval(object_string);

  // Инициализация сообщения
  var property_message = "Ниже перечислены значения свойств для объекта " + object_string + ":\n\n"

  // Получение списка значений свойств
  for (var property_name in actual_object) {
    property_message += object_string + "." + property_name + " = " + actual_object[property_name] + "\n"
  }

  // Отображение сообщения

  alert(property_message);
  /*
  newWindow = window.open("","imgWindow","width=500,height=500,left=300,top=100");
  newWindow.document.open();
  newWindow.document.write('<html><head><title>Свойства объекта</title>');
  newWindow.document.write('</head><body style="margin:0;">');
  newWindow.document.write('<div>' + property_message + '</div>');
  newWindow.document.write('</body></html>');
  newWindow.document.close();
  newWindow.focus();
  */
}