({   
  load_progect : function() {
    if(Function.call && (this.handlers_method = this.get_register())) {
      if(typeof(small_images_src) != 'undefined' && typeof(big_images_src) != 'undefined') {
        var gallery_length = small_images_src.length;
        this.pre_small = [];
        this.pre_big = [];
        this.wait_status = [];
	(this.loading_img = new Image).src = '/img/loading.gif';
        (this.pre_big[0] = new Image).src = big_images_src[0];					
        for(var i = 0; i < 6; i++) {
          (this.pre_small[i] = new Image).src = small_images_src[i];
        }
        this.event_regist((window.opera) ? document : window, 'load',
          this.apply_func(this, 'init_progect'));
        this.event_regist((window.opera) ? document : window, 'unload',
          this.apply_func(this, 'event_unregist'));
      }
    } 
  },
  get_register : function() {
    this.event_prefix = '';
    this.handlers_list = [];
    return ((document.addEventListener) ?
      ['addEventListener', 'removeEventListener'] :
      ((document.attachEvent) ? (this.event_prefix = 'on',
      ['attachEvent', 'detachEvent']) : false));
  },
  event_regist : function(o, e, f) {
    var h = this.handlers_list;
    o[this.handlers_method[0]](this.event_prefix + e, f, false);
    h[h.length] = [o, e, f];
  },
  event_unregist : function() {
    var i = 0, h = this.handlers_list, l = h.length, c;
    for(; i < l; i++) (c = h[i])[0][this.handlers_method[1]]
      (this.event_prefix + c[1], c[2], false);
  },
  apply_func : function(o, m, a) { return function(e) { o[m](e, a); }},
  init_progect : function() {    
    var 
    large_left   = document.getElementById('large_view_left'),
    large_right  = document.getElementById('large_view_right'),
    large_right1 = document.getElementById('large_view_right1'),
    prev_left    = document.getElementById('preview_left'),
    prev_right   = document.getElementById('preview_right'),
    prev_gallery = document.getElementById('preview_gallery');

    this.large_image   = document.getElementById('large_view');
    this.images_list   = prev_gallery.getElementsByTagName('img');
    this.current_index = this.images_counter = 0;

    this.wait_status[this.temp_status = this.current_index] = true;
    (this.current_review = (this.current_review = this.images_list
      [this.count_diff = this.current_index])).className = 'current_image';
    this.large_image.src = this.pre_big[this.current_index].src;

    this.event_regist(large_left,   'click', this.apply_func(this, 'large_shift',   -1));
    this.event_regist(large_right,  'click', this.apply_func(this, 'large_shift',    1));
    this.event_regist(large_right1, 'click', this.apply_func(this, 'large_shift',    1));
    this.event_regist(prev_left,    'click', this.apply_func(this, 'preview_shift', -1));
    this.event_regist(prev_right,   'click', this.apply_func(this, 'preview_shift',  1));
    this.event_regist(prev_gallery, 'click', this.apply_func(this, 'images_select'    ));
  },
  prevent_default : function(e) {
    (e.preventDefault) ? e.preventDefault() : e.returnValue = false;
  },
  get_index : function(i, d, l) {
    var t = i + d;
    return (i = ((t >= l) ? 0 : (t < 0) ? l - 1 : t));
  },

  large_shift : function(e, d) {
    var list = this.images_list, sl = big_images_src.length, n;
    n = (this.current_index = this.get_index(this.current_index, d, sl));
    this.images_counter = ((n = n - this.count_diff - d) >= 0) ? n : sl + n;
    this.preview_shift(e, d, 1);
  },

  preview_shift : function(e, d, f) {
    var list = this.images_list, sl = small_images_src.length, n, c;
    this.images_counter = this.get_index(this.images_counter, d, sl);
    this.current_review.className = '';
    for(var i = 0, ll = list.length; i < ll; i++) {
      n = ((i + (c = this.images_counter)) >= sl) ? ((i + c) - sl) : (i + c);
      list[i].src = this.prepare_show('pre_small', small_images_src, n, i);
      if(n == this.current_index)
        (this.current_review = list[i]).className = 'current_image';
    }
    if(f) this.prepare_show('pre_big', big_images_src, this.current_index);
    this.prevent_default(e);
  },

  images_select : function(e) {
    var el = e.srcElement || e.target, n = el.tagName.toLowerCase();
    if(n == 'img' && el.src != this.large_image.src) {
      this.current_review.className = '';
      (this.current_review = el).className = 'current_image';
      this.set_index(el);
    }
  },   

  set_index : function(o) {
    var i = 0, list = this.images_list, l = list.length, d = this.pre_small.length, n, c;
    for(; i < l; i++) if(list[i] == o) { this.count_diff = i; break; }
    c = ((n = this.images_counter + i) >= d) ? n - d : n;
    this.prepare_show('pre_big', big_images_src, this.current_index = c);
  },

  prepare_show : function(a, v, i, b) {
    var image, t = this.temp_status, bool = (typeof(b) == 'undefined');
    if(bool) this.wait_status[this.temp_status = i] = !(this.wait_status[t] = false);
    if(!this[a][i]) {
      (image = new Image).host_obj = this;
      image.own_index = i;
      image.own_place = (!bool) ? (image.saved_counter = this.images_counter, b) :
						  (this.large_image.src = this.loading_img.src, null);
      image.onload = this.onload_picture;
						image.src = v[i];
      this[a][i] = image;
      return (bool || this.loading_img.src);
    } 
				else return ((!bool) ? this[a][i].src : this.show_picture(this[a][i].src, i));
  },

  show_picture : function(src, i) {
    if(this.wait_status[i]) 
      this.large_image.src = src;
    i1 = i+1;
    var alt = i1 + " / "+N_all;
    if(image_names[i])
        alt = alt + " - " + image_names[i];
    document.getElementById("img_alt").innerHTML = alt;

    n_pre = small_images_src.length;
    if(n_pre >= 5) n_pre = 5;
    for(j=0; j<n_pre; j++) {
        div_id = "img_div"+ j;
        if(j == this.count_diff)
            eval("document.getElementById('img_div"+j+"').className = 'current_image'");
        else 
            eval("document.getElementById('img_div"+j+"').className = ''");
    }    
  },

  onload_picture : function() {
    var o = this.host_obj;
    if(this.own_place != null) {
      var i = this.own_place - (o.images_counter - this.saved_counter);
      o.images_list[i].src = this.src;
    }
    else o.show_picture(this.src, this.own_index);
  }    
}).load_progect();

