/**********************************************************************************************************************************
                         JS-скрипт для показа одиночных изображений или галереи
                         (c) Алексей Коростелёв, 2011. Компания Диол (http://diol-it.ru)
                         версия: 1.5.2
**********************************************************************************************************************************/

var temp_b_pic_viewer; // здесь хранится копия объекта класса, доступная для внешних функций

var bImClass = function(param, arr, container_id)
{ // конструктор класса
    if(param==null)
        param=b_img_viewer_init();
        
    
    this.p_width=this.set_param_value(param,'progress_pic_width', 32); // ширина картинки прогресса в пикселях
    this.p_height=this.set_param_value(param,'progress_pic_height', 32); // высота картинки прогресса в пикселях

    this.show_real_size=this.set_param_value(param,'show_real_size', true);  // ужимать изображения которые больше размера экрана?
    this.resize_step=parseInt(this.set_param_value(param,'resize_step', 15));    // в пикселях - шаг изменения размеров при масштабировании
    this.scroll_step=parseInt(this.set_param_value(param,'scroll_step', 15));    // в пикселях - изменение отступа при прокрутке за шаг
    
    this.is_one_pic;
    
    this.use_slow_resize=this.set_param_value(param,'use_slow_resize', true); // использовать плавное масштабирование
    this.use_slow_scroll=this.set_param_value(param,'use_slow_scroll', true); // использовать плавную прокрутку
    
    this.resize_timeout=parseInt(this.set_param_value(param,'resize_timeout', 50)); // шаг масштабирования в млс, т.е. значение 1000 = 1 секунде
    this.scroll_timeout=parseInt(this.set_param_value(param,'scroll_timeout', 50)); // шаг прокрутки в млс
    
    this.is_id_if_no_doctype=this.set_param_value(param,'is_id_if_no_doctype', 0); // id нижнего элемента, если не задан DOCTYPE (для ie)

    this.show_number_picture=this.set_param_value(param,'show_number_picture', true); // показывать номер изображения
    
    this.lang=this.set_param_value(param,'lang', 'ru'); // установка языка отображения
      
    
    
    /***** Служебные параметры *****/
    
    if(arr==null&&container_id!=undefined)
    {  // если не задан входной массив, но задан контейнер с изображениями, массив будет взят из него...
        arr=this.get_gallery_arr_from_html(container_id);
    }
    
    this.img_list; // массив ассоциативных объектов след. вида: 
    if(arr!=undefined)
    {
        this.img_list=arr; // загрузка массива изображений
    }
        
    /*
        img_list[0]['img']="images/..."; // путь до изображения
        img_list[0]['descr']="..."; // подпись под картинок, можно в html, но обязательно экранировать ' (\') и " (\")
        img_list[0]['title']="..."; // title для картинки
        img_list[0]['alt']="..."; // alt для картинки
        ...
    */
    this.iterator=0; // итератор (индекс показываемой картинки)
    this.img_show=false; // если этот флаг установлен, в данных момент разворачивается большое изображение
    this.is_scrolling_now=false; // если этот флаг установлен в данный момент выполняется прокрутка изображения
    this.resize_now=false; // изображение масштабируется в данных момент
     
    this.ids=new Object(); // получение объектов элементов
    this.ids['progress']=document.getElementById('b_pic_viewer_progress'); //  картинка загрузки
    this.ids['background']=document.getElementById('b_pic_viewer_back_div'); // затемненный фон
    this.ids['descr']=document.getElementById('b_pic_viewer_b_img_descr'); // описание
    this.ids['bimage']=document.getElementById('b_pic_viewer_bimage'); // большая картинка
    this.ids['bimage_table']=document.getElementById('b_pic_viewer_table_with_bimage'); // таблица в которой показывается картинка
    this.ids['b_image_div']=document.getElementById('b_pic_viewer_b_image_div'); // div с картинкой, которая показывается в таблице
    //this.ids['b_img_descr_row']=document.getElementById('b_pic_viewer_b_img_descr_row'); // строка с описанием
    //this.ids['b_img_control']=document.getElementById('b_pic_viewer_b_img_control'); // строка с управляющими кнопками
    this.ids['img_counter']=document.getElementById('b_pic_viewer_one_from'); // строка с номером изображения
    this.ids['bimage_cell']=document.getElementById('b_pic_viewer_bimage_cell'); // ячейка с отображаемым изображением
    this.ids['fullscreen']=document.getElementById('b_pic_viewer_fullscreen'); // кнопка полноэкранного размера
    this.ids['fullscreen_one']=document.getElementById('b_pic_viewer_fullscreen_one_picture'); // кнопка полноэкранного размера

    if(this.is_id_if_no_doctype)
    {
        if (window.navigator.userAgent.indexOf ("MSIE") >= 0)
        { // если это IE и не задан DOCTYPE высота документа определяется иначе
            this.ids['document_height_id']=document.getElementById(this.is_id_if_no_doctype);
        }
    }
    
    this.close_enabled=true; // закрытие по клику
    temp_b_pic_viewer=this;
}

//---------------------------------------------------------------------------------------

bImClass.prototype.get_gallery_arr_from_html = function (container_id)
{  // метод для формирования массива изображений из заданного контейнера
    var container=document.getElementById(container_id); 
    var img_list=false;
    var img_counter=0;
    if(container)
    {
        list=container.childNodes;
        for (var i=0; i<list.length; i++) 
        {  // считаем кол-во изображений
            if(list[i].nodeName=="IMG")
            {
                img_counter++;
            }
        }
        
        if(img_counter)
        { // собираем изображения в массив
            img_list=new Array(img_counter);
            for(var i=0, index=0; i<list.length, index<img_counter; i++) 
            {
                if(list[i].nodeName=="IMG")
                {
                    img_list[index]=new Object();
                    img_list[index]['img']=list[i].getAttribute('src');
                    img_list[index]['title']=list[i].title;
                    img_list[index]['alt']=list[i].alt;
                    img_list[index]['descr']=list[i].getAttribute('longdesc');
                    index++;
                }
            }
        }
    }
    return img_list;    // возвращаем этот массив в объект
}

//---------------------------------------------------------------------------------------

bImClass.prototype.set_language_param = function ()
{ // установка языковых констант галереи
    if(temp_b_pic_viewer.lang==this.lang) return;
    if(b_pic_viewer_lang_values!=undefined)
    {
         if(b_pic_viewer_lang_values[this.lang]!=undefined)
         {
              this.set_img_values('b_pic_viewer_left_arrow', b_pic_viewer_lang_values[this.lang]['prev_photo']);
              this.set_img_values('b_pic_viewer_full_screen_button', b_pic_viewer_lang_values[this.lang]['full_screen']);
              this.set_img_values('b_pic_viewer_full_screen_button_one_pic', b_pic_viewer_lang_values[this.lang]['full_screen']);
              this.set_img_values('b_pic_viewer_close_button', b_pic_viewer_lang_values[this.lang]['close']);
              this.set_img_values('b_pic_viewer_close_button_one_pic', b_pic_viewer_lang_values[this.lang]['close']);
              this.set_img_values('b_pic_viewer_right_arrow', b_pic_viewer_lang_values[this.lang]['next_photo']);
         }
    }
}

//---------------------------------------------------------------------------------------

bImClass.prototype.set_img_values = function (img_id, value)
{  // устанавливает alt и title - языковые константы для изображений с заданнымии img_id
    var img=document.getElementById(img_id);
    if(img)
    {
        img.alt=img.title=value;
    }
}

//---------------------------------------------------------------------------------------

bImClass.prototype.set_param_value = function (param, value_key, default_val)
{ // метод для установки параметров полученных в конструктор классов.
    if(param!=undefined)
    {
        if(param[value_key]!=undefined)
            return param[value_key];
    }
    return default_val;
}

//---------------------------------------------------------------------------------------

bImClass.prototype.get_iterator_value = function (path)
{ // определение значения итератора - индекс по значению
    if(this.img_list==undefined) return -1;
    if(this.img_list[this.iterator]['img']==path)
        return this.iterator;

    for(var i=0; i<this.img_list.length; i++)
    {
        if(this.img_list[i]!=undefined&&this.img_list[i]['img']!=undefined)
            if(this.img_list[i]['img']==path) return i;
    }
    return -1;
}

//---------------------------------------------------------------------------------------

bImClass.prototype.prev_img = function()
{    // переключение на предыдущее изображение
    if(this.resize_now||this.is_scrolling_now) return;  
    if(this.img_list==undefined||this.iterator==undefined||this.iterator==0)
        return;
    else this.show_bimage(this.iterator-1);
}

//---------------------------------------------------------------------------------------

bImClass.prototype.next_img = function()
{    // переключение на следующее изображение
    if(this.resize_now||this.is_scrolling_now) return; 
    if(this.img_list==undefined||this.iterator==undefined||this.iterator==(this.img_list.length-1))
        return;
    else 
        this.show_bimage(this.iterator+1);
}

//---------------------------------------------------------------------------------------

bImClass.prototype.switch_visibility = function(id, value)
{ // переключает отображение элемента visible
    var temp=document.getElementById("b_pic_viewer_"+id);
    if(temp)
    {
        if(value)
            temp.style.visibility="visible";
        else temp.style.visibility="hidden";
    } 
}

//---------------------------------------------------------------------------------------

bImClass.prototype.switch_display = function(id, value)
{ // переключает отображение элемента visible
    var temp=document.getElementById("b_pic_viewer_"+id);
    if(temp)
    {
        if(value)
            temp.style.display="";
        else temp.style.display="none";
    }
}

//---------------------------------------------------------------------------------------

bImClass.prototype.slow_resize = function (bimg, width, height)
{ // плавное увеличение
    if(!this.img_show)
        return;
    
    if(!this.resize_now)    
        this.resize_now=true;
        
    if(this.use_slow_resize)
    {
        if(bimg.offsetWidth!=width||bimg.offsetHeight!=height)    
        {
            var temp_new_width=0;
            var temp_new_height=0;
            // изменение ширины
            if(width!=bimg.offsetWidth)
            {            
                if(width>bimg.offsetWidth) // увеличение
                {
                    temp_new_width=bimg.offsetWidth+this.resize_step;
                }
                else if(width<bimg.offsetWidth)
                {
                    temp_new_width=bimg.offsetWidth-this.resize_step;
                }        
                
                if(Math.abs(temp_new_width-width)<this.resize_step)
                {
                    temp_new_width=width;
                }
                bimg.style.width=parseInt(temp_new_width)+"px";
            }
            
            // изменение высоты
            if(height!=bimg.offsetHeight)
            {
                if(height>bimg.offsetHeight) // увеличение
                {
                    temp_new_height=bimg.offsetHeight+this.resize_step;
                }
                else if(height<bimg.offsetHeight)
                {
                    temp_new_height=bimg.offsetHeight-this.resize_step;
                }        
                
                if(Math.abs(temp_new_height-height)<this.resize_step)
                {
                    temp_new_height=height;
                }
                
                bimg.style.height=parseInt(temp_new_height)+"px";
            }            

            this.correct_position(); // выравнивание
        

            setTimeout
            (
                (function(bimg, width, height)
                {
                        return function() 
                        {
                            temp_b_pic_viewer.slow_resize(bimg, width, height);
                        };
                }
                )
                (bimg, width, height), this.resize_timeout
            );
            return;
        }
    }
    else 
    {
        bimg.style.width=parseInt(width)+"px";
        bimg.style.height=parseInt(height)+"px";
    }
  
    if(this.is_one_pic)
    {
        this.switch_display('one_from_line', 0); 
        this.ids['bimage_cell'].style.paddingTop="10px";
    }
    else 
    {
        this.switch_display('one_from_line', 1);
        this.ids['bimage_cell'].style.paddingTop="0px";
    }
    
    this.switch_visibility('one_from', 1); 
    this.switch_visibility('bimage', 1);
    this.switch_visibility('progress', 0);
    this.switch_display('b_img_descr_row', 1);
    this.switch_visibility('b_img_descr', 1);
    
    this.correct_position();
    this.resize_now=false;
}

//---------------------------------------------------------------------------------------

bImClass.prototype.correct_size = function (bimg)
{ // корректировка размеров изображения, для его пропорционального отображения на странице
    
    if(bimg)
    {
        var k_height=Geometry.getViewportHeight()/this.real_height;
        var k_width=Geometry.getViewportWidth()/this.real_width;
    
        if (k_height<=1.1||k_width<=1.1)
        {
            var new_height, new_width;
            if(k_width<k_height)
            {
                new_width=parseInt(this.real_width*k_width*0.8);    
                new_height=parseInt(this.real_height*(new_width/this.real_width));
            }
            else 
            {
                new_height=parseInt(this.real_height*k_height*0.8);    
                new_width=parseInt(this.real_width*(new_height/this.real_height));
            }
        }
        else 
        {
            new_width=this.real_width;    
            new_height=this.real_height;
        }
        //bimg.width=new_width;
        //bimg.height=new_height;
    }
    /*else 
    {
        new_width=this.real_width;    
        new_height=this.real_height;
    }*/
    this.calculated_width=new_width;
    this.calculated_height=new_height;

    this.slow_resize(bimg, new_width, new_height);
}

//---------------------------------------------------------------------------------------

bImClass.prototype.show_bimage = function(path, descr, title, alt)
{ // подготовка к отображению по заданным параметрам
    this.set_language_param();    // установка языковых констант галереи
    temp_b_pic_viewer=this; // заносим во внешний объект текущий для работы с ним...
    this.switch_display("b_image_div_span", 1);
    this.switch_to_start_visible_elements(false); // сброс значений visibility на стартовый

    if(descr==undefined&&title==undefined&&alt==undefined)
    { // отображение по индексу
        var re = /^[0-9]+$/;
        if(path.toString().match(re))    
        { // если задан только один параметр и это число, значит это селектор =)
            var index=parseInt(path);
            this.iterator=index;
            if(this.img_list!=undefined&&this.img_list[index]!=undefined&&this.img_list[index]['img']!=undefined&&this.img_list[index]['img']!="")
            {    
                path=this.img_list[index]['img'];
                descr=this.img_list[index]['descr'];
                title=this.img_list[index]['title'];
                alt=this.img_list[index]['alt'];
            }    
            else
            {
                alert("Ошибка! Неправильный индекс массива изображений или элемент массив не задан!");
                return;
            }
        }
    }
    
    this.iterator=this.get_iterator_value(path);    
    if(this.iterator<0)
        this.is_one_pic=true;
    else this.is_one_pic=false;
    
    
    var offset_height, offset_width;
    var scroll_top=this.getBodyScrollTop();
    this.img_show=true;
    
    offset_width=Geometry.getDocumentWidth();
    offset_height=Geometry.getViewportHeight();

    this.ids['progress'].style.visibility='visible';

    this.correct_position();
    
    // отображение подписи
    if (descr==undefined)
        descr="";

    if(this.ids['descr'])
    {    // отображение описания
        this.ids['descr'].innerHTML=descr;
    }

    
    if(this.iterator>=0&&this.show_number_picture&&this.ids['img_counter'])
    {    // отображение номера изображения
        if(this.ids['bimage_cell'])
            this.ids['bimage_cell'].style.paddingTop=0;
        this.ids['img_counter'].innerHTML=b_pic_viewer_lang_values[this.lang]['img_header']+" <b>"+(this.iterator+1)+"</b> "+ b_pic_viewer_lang_values[this.lang]['img_header_from'] +" <b>"+this.img_list.length+"</b>";
    }
        
    // подготовка большого изображения
    if (this.ids['bimage'])
    {
        this.img = new Image();
        this.img.onload = function() 
        {
            temp_b_pic_viewer.real_width=this.width;
            temp_b_pic_viewer.real_height=this.height;
            
            temp_b_pic_viewer.correct_position();
            
            // просчет размеров и плавное изменение размеров
            temp_b_pic_viewer.correct_size(temp_b_pic_viewer.ids['bimage']);        

            // загрузка изображения
            temp_b_pic_viewer.ids['bimage'].src=path.toString();
        
            // добавление title для картинки
            if(title!=undefined)
                temp_b_pic_viewer.ids['bimage'].title=title;
            else temp_b_pic_viewer.ids['bimage'].title="";

            // добавление alt для картинки
            if(alt!=undefined)
                temp_b_pic_viewer.ids['bimage'].alt=alt;
            else temp_b_pic_viewer.ids['bimage'].alt="";

            // непосредственно отображение на экране
            temp_b_pic_viewer.show_img(); 
        }
        this.img.src=path.toString(); // загрузка изображения
    }
}

//---------------------------------------------------------------------------------------

bImClass.prototype.show_img = function()
{ // отображение изображения на onload
    if(this.show_real_size&&this.real_width>this.calculated_width)
    {
        this.ids['bimage'].style.cursor="move";
        this.ids['fullscreen'].style.visibility="visible";
        this.ids['fullscreen_one'].style.visibility="visible";
    }
    else
    {
        this.ids['bimage'].style.cursor="default";
        this.ids['fullscreen'].style.visibility="hidden";
        this.ids['fullscreen_one'].style.visibility="hidden";
    }

    // подготовка галереи, если задан массив, делаем возможность листания
    
    if (this.iterator<0)
    { // показывается одно изображение (не галерея)
        this.switch_display("one_pic", 1);
        this.switch_display("many_pic", 0);
        this.ids['img_counter'].style.visibility='hidden';
        this.iterator=0;
    }
    else 
    {
        this.switch_visibility('left_arrow', 1);
        this.switch_visibility('right_arrow', 1);
        
        this.switch_display("one_pic", 0);
        this.switch_display("many_pic", 1);
        
        if(this.iterator==0)
            this.switch_visibility("left_arrow", 0);
        if(this.iterator==(this.img_list.length-1))
            this.switch_visibility("right_arrow", 0);
    }
    this.correct_position();
}

//---------------------------------------------------------------------------------------

bImClass.prototype.switch_to_start_visible_elements = function(is_close)
{ // переключение значений отображения элементов в стартовое значение
    if(this.ids['bimage'])
    {    // коррекция размеров изображения, в случае, если оно больше размера экрана
        if(this.ids['bimage'].offsetWidth>Geometry.getViewportWidth())
        {
            this.ids['bimage'].style.width=(Geometry.getViewportWidth()-100)+"px";
        }
        
        if(this.ids['bimage'].offsetHeight>Geometry.getViewportHeight())
        {
            this.ids['bimage'].style.height=Geometry.getViewportHeight()+"px";
        }
    }

    if(is_close)    
    {
        this.switch_visibility("b_image_div",0);
        this.switch_visibility('left_arrow', 0);
        this.switch_visibility('right_arrow', 0);
        this.switch_visibility('progress', 0);
    }
    this.switch_visibility("one_from",0);
    this.switch_visibility("bimage",0);
    this.switch_display("b_img_descr_row", 0);

    this.ids['background'].style.width="1px";
    this.ids['background'].style.height="1px";
}

//---------------------------------------------------------------------------------------

bImClass.prototype.background_correction = function()
{
    // коррекция затемнения
    if (this.ids['background'])
    {
        this.ids['background'].style.width=Geometry.getDocumentWidth()+"px";

        if(this.ids['document_height_id']!=undefined)
        { // для ie без doctype коррекция по div
            this.ids['background'].style.height=this.ids['document_height_id'].offsetTop+this.ids['document_height_id'].offsetHeight+"px";
        }
        else if(Geometry.getDocumentHeight()>Geometry.getViewportHeight())
            this.ids['background'].style.height=Geometry.getDocumentHeight()+"px";
        else this.ids['background'].style.height=Geometry.getViewportHeight()+"px";

        this.ids['background'].style.visibility='visible';
    }
}

//---------------------------------------------------------------------------------------

bImClass.prototype.correct_position = function()
{    // корректировка отображения изображения в процессе масштабирования холста

    var scroll_top=this.getBodyScrollTop();

    this.background_correction();

    // коррекция прогресса
    if (this.ids['progress'])
    {
        var top_img=((Geometry.getViewportHeight()-this.p_height)/2+scroll_top);    
        var left_img=((Geometry.getViewportWidth()-this.p_width)/2);    
        this.ids['progress'].style.margin=parseInt(top_img)+"px 0 0 "+parseInt(left_img)+"px";
    }

    if(temp_b_pic_viewer.ids['bimage'].offsetWidth<Geometry.getViewportWidth()&&temp_b_pic_viewer.ids['bimage'].offsetHeight<Geometry.getViewportHeight())
    {
        if (this.ids['b_image_div'])
        {    // изменение положения элемента
            var temp_top=parseInt((Geometry.getViewportHeight()-this.ids['b_image_div'].offsetHeight)/2);
            if (temp_top<0) temp_top=0;
            this.ids['b_image_div'].style.marginTop=temp_top+scroll_top+"px";
            this.ids['b_image_div'].style.visibility="visible";
            this.ids['b_image_div'].style.width=Geometry.getDocumentWidth()+"px";
        }
    }
}

//---------------------------------------------------------------------------------------

bImClass.prototype.real_size_show = function()
{ // обработка увеличения/уменьшения по клику
    if(this.show_real_size&&this.real_width>this.calculated_width)
    {
        window.scrollTo(0,0);
        if(this.ids['bimage'].offsetWidth==this.calculated_width&&this.ids['bimage'].offsetHeight==this.calculated_height)
        {
            this.ids['b_image_div'].style.marginTop=0;
            this.ids['bimage'].style.width=this.real_width+"px";
            this.ids['bimage'].style.height=this.real_height+"px";
            
            this.background_correction();
        }
        else if(this.ids['bimage'].offsetWidth==this.real_width&&this.ids['bimage'].offsetHeight==this.real_height)
        {
            this.ids['bimage'].style.width=this.calculated_width+"px";
            this.ids['bimage'].style.height=this.calculated_height+"px";
        
            this.ids['background'].style.width="1px";
            this.ids['background'].style.height="1px";
            //window.onscroll();
            this.correct_position();
        }
    }
}

//---------------------------------------------------------------------------------------

bImClass.prototype.close_bimage = function()
{ // закрытие изображения

    if(!this.close_enabled)
    {
        this.close_enabled=true;
        return;
    }

    this.img_show=false;
    if (this.ids['background'])
    {
        this.ids['background'].style.width="1px";
        this.ids['background'].style.height="1px";
    }
    this.switch_to_start_visible_elements(true);
    this.switch_display("b_image_div_span", 0);
}

//---------------------------------------------------------------------------------------

bImClass.prototype.slow_scroll = function ()
{ // плавная прокрутка
    var scroll_top=this.getBodyScrollTop();
    // коррекция прогресса
    /*if (this.ids['progress'])
    {
        var top_img=((Geometry.getViewportHeight()-this.p_height)/2+scroll_top);    
        var left_img=((Geometry.getViewportWidth()-this.p_width)/2);    
        this.ids['progress'].style.margin=parseInt(top_img)+"px 0 0 "+parseInt(left_img)+"px";
        //this.ids['progress'].style.visibility='visible';
    }*/
    
    if(!this.is_scrolling_now)
        this.is_scrolling_now=true;
    if (this.ids['b_image_div'])
    {    // изменение положения элемента
        var desctination_top=parseInt((Geometry.getViewportHeight()-this.ids['b_image_div'].offsetHeight)/2+scroll_top); 
        
        if (desctination_top<0) desctination_top=0;    
        
        var current_top=this.ids['b_image_div'].offsetTop;

        var temp_height=this.ids['b_image_div'].offsetHeight;
        
        if(desctination_top-current_top>temp_height)
            current_top=desctination_top-temp_height-this.scroll_step;

        if(current_top-desctination_top>temp_height)
            current_top=desctination_top+temp_height+this.scroll_step;

        if(current_top!=desctination_top)
        {
            this.scroll_step=Math.sqrt(Math.abs(desctination_top-current_top));


            if(current_top<desctination_top)
            {
                current_top+=this.scroll_step;
            }
            else 
            {
                current_top-=this.scroll_step;
            }
            if(Math.abs(current_top-desctination_top)<this.scroll_step)
            {
                current_top=desctination_top;
            }
            //alert(current_top+" "+desctination_top);
        
            this.ids['b_image_div'].style.marginTop=current_top+"px";

            setTimeout
                (
                    (function()
                    {
                            return function() 
                            {
                                temp_b_pic_viewer.slow_scroll();
                            };
                    }
                    )
                    (), this.scroll_timeout
                );
                return;
        }
        else this.is_scrolling_now=false;        
    }
}
//---------------------------------------------------------------------------------------

bImClass.prototype.getBodyScrollTop = function()
{ // получение высоты прокрутки
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

//---------------------------------------------------------------------------------------

window.onresize = function ()
{  // обработка изменений размеров окна
    if(temp_b_pic_viewer!=undefined)
    {
        if(temp_b_pic_viewer.img_show)
        {
            temp_b_pic_viewer.correct_position();
        }
    }    
}

//---------------------------------------------------------------------------------------

window.onscroll = function ()
{ // обработка прокрутки
    if(temp_b_pic_viewer!=undefined)
    {
        if(temp_b_pic_viewer.img_show)
        {
            if(temp_b_pic_viewer.ids['bimage'].offsetWidth<Geometry.getViewportWidth()&&temp_b_pic_viewer.ids['bimage'].offsetHeight<Geometry.getViewportHeight())
            {
                if(!temp_b_pic_viewer.use_slow_scroll)
                    temp_b_pic_viewer.correct_position();
                else if(!temp_b_pic_viewer.is_scrolling_now)
                    temp_b_pic_viewer.slow_scroll();
            }
        }
    }
}

//---------------------------------------------------------------------------------------

