<!--
// Окно проигрывателя галереи
wpGallery=
 {
  curGallery:0,                             // ion текущей отображаемой галереи
  jGallery:-1,                              // индекс текущей галереи
  jImage:-1,                                // индекс текущего изображения
  arrGalleries:[],                          // массив данных галерей
  
  flagInit:0,                               // флаг инициализации
  
  objWin:null,                              // окно просмотра изображения
  objLinkImg:null,                          // ссылка на самом изображении
  objLinkPrev:null,                         // ссылка перехода на предыдущее изображение
  objLinkNext:null,                         // ссылка перехода на следующее изображение
  objColPrev:null,                          // колонка ссылки перехода на предыдущее изображение
  objColNext:null,                          // колонка ссылки перехода на следующее изображение
  objImg:null,                              // изображение
  objImgClose:null,                         // изображение ссылки закрытия
  objDescr:null,                            // поле для вывода комментария
  objCnt:null,                              // поле для вывода количеств
  objOverlay:null,                          // подложка
  

  // Задание текущей галереи
  setGallery:function(ion)
   {
    if(this.curGallery==ion)
     return;
     
    this.jGallery=this.getJGallery(ion);
    if(this.jGallery==-1)
     this.addGallery(ion);
    
    this.curGallery=ion;
   },
   

  // Задание текущего индекса
  setIndex:function(num)
   {
    var cntAll;

    num--;
    
    if(num<0)
     num=0;

    if(this.jGallery!=-1)
     if(this.arrGalleries[this.jGallery].arrImages.length==0)
       num=-1;
      else
     if(num>=this.arrGalleries[this.jGallery].arrImages.length)
      num=this.arrGalleries[this.jGallery].arrImages.length;
     
    this.jImage=num;
   },
   
   
  // Получение индекса галереи по ion
  getJGallery:function(ion)
   {
    var i,rc=-1;

    if(this.curGallery==ion)
     return(this.jGallery);
     
    for(i=0;i<this.arrGalleries.length;i++)
     if(this.arrGalleries[i].ion==ion)
      {
       rc=i;
       break;
      }
      
    return(rc);  
   },  
   
   
  // Добавление новой галереи
  addGallery:function(ion)
   {
    this.jGallery=this.arrGalleries.length;
    this.arrGalleries[this.jGallery]={ion:ion,
                                      arrImages:[]};
   }, 
   

  // Добавление данных об изображении
  addImage:function(ionGallery,uriImage,strDescr)
   {
    this.setGallery(ionGallery);
    this.arrGalleries[this.jGallery].arrImages[this.arrGalleries[this.jGallery].arrImages.length]={uri:uriImage,
                                                                                                   descr:strDescr,
                                                                                                   img:null}; 
   },
   
   
  // Инициализация
  init:function()
   {
    if(this.flagInit)
     return true;
     
    this.objWin=document.getElementById("id_wp_gal_win");
    if(!this.objWin)
     return false;
     
    this.objImg=document.getElementById("id_wp_gal_img");
    if(!this.objImg)
     return false;
     
    this.objImgClose=document.getElementById("id_wp_gal_img_close"); 
    if(jisIE6
    && this.objImgClose 
    && this.objImgClose.filters)
     {
      this.objImgClose.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.objImgClose.src+"', sizingMethod='scale')";
      this.objImgClose.src="/img/no.gif";
     }
     
    this.objLinkImg=document.getElementById("id_wp_gal_link_img");
    this.objLinkPrev=document.getElementById("id_wp_gal_link_prev");
    this.objLinkNext=document.getElementById("id_wp_gal_link_next");
    this.objColPrev=document.getElementById("id_wp_gal_col_prev");
    this.objColNext=document.getElementById("id_wp_gal_col_next");

    this.objDescr=document.getElementById("id_wp_gal_descr");

    this.objCnt=document.getElementById("id_wp_gal_cnt");

    this.objOverlay=document.getElementById("id_wp_overlay");
    
    this.flagInit=1; 
    
    return true;
   }, 
   
   
  // Открытие окна просмотра галереи
  open:function(ionGallery,num)
   {
    // Инициализируем объект
    if(!this.init())
     return;
     
    this.setGallery(ionGallery);
    this.setIndex(num);
    

    // Подкладываем подложку
    if(this.objOverlay)
     {
      var h=jscGetPageHeight();
      if(h<window.screen.height)
       h=window.screen.height;

      var w=jscGetPageWidth();
      if(w<window.screen.width)
       w=window.screen.width;

      this.objOverlay.style.width=w+"px";
      this.objOverlay.style.height=h+"px";

      // Для IE6 убираем select
      if(jisIE6)
       jscHideSelect(1);
      
      jscShowOpacity(this.objOverlay,30,500,10);
     }
    
    
    // Для IE6 устанавливаем координаты окна вручную
    if(jisIE6)
     {
      var offY=jscGetScreenOffsetY()+Math.ceil(window.screen.availHeight*0.4);
      this.objWin.style.position="absolute";
      jscSetPosY(this.objWin,offY);
     }


    // Открываем окно
    this.objWin.style.display="block";
    
    
    // Загружаем фотографию
    this.loadImage();
    
    // Обновляем управленческую информацию
    this.update();
   },
   
   
  // Закрытие окна просмотра галереи
  close:function()
   {
    // Закрываем окно
    this.objWin.style.display="none";
    
    // Убираем подложку
    if(this.objOverlay)
     {
      // Для IE6 восстанавливаем select
      if(jisIE6)
       jscHideSelect(0);

      this.objOverlay.style.display="none";
     }
   },
   

  // Загрузка изображения с кешированием
  loadImage:function()
   {
    if(this.jGallery<0)
     return;
     
    if(this.jImage<0)
     return;

    if(!this.arrGalleries[this.jGallery].arrImages[this.jImage].img)
     {
      var objPic=new Image();
      var objImg=this.objImg;
      objPic.onload=function()
                     {
                      objImg.src=objPic.src;
                      objImg.style.display="inline";
                      objImg.onload='';
                     };
      objPic.src=this.arrGalleries[this.jGallery].arrImages[this.jImage].uri;
      this.arrGalleries[this.jGallery].arrImages[this.jImage].img=objPic;
     }
     else
     {
      this.objImg.src=this.arrGalleries[this.jGallery].arrImages[this.jImage].uri;
     }
   },
   
      
  // Переход к следующему изображению
  nextImage:function()
   {
    if(this.jGallery<0)
     return;
     
    if(this.jImage<0)
     return;
     
    if(this.arrGalleries[this.jGallery].arrImages.length<2)
     return;

    // Устанавливаем номер следующего изображения
    this.jImage++;
    if(this.jImage>=this.arrGalleries[this.jGallery].arrImages.length)
     this.jImage=0;
     
    // Загружаем изображение
    this.loadImage();
    
    // Обновляем интерфейс
    this.update();
   },    
   
   
  // Переход к предыдущему изображению
  prevImage:function()
   {
    if(this.jGallery<0)
     return;
     
    if(this.jImage<0)
     return;
     
    if(this.arrGalleries[this.jGallery].arrImages.length<2)
     return;

    // Устанавливаем номер следующего изображения
    this.jImage--;
    if(this.jImage<0)
     this.jImage=this.arrGalleries[this.jGallery].arrImages.length-1;
     
    // Загружаем изображение
    this.loadImage();
    
    // Обновляем интерфейс
    this.update();
   }, 
   
   
  // Обновление параметров навигации 
  update:function()
   {
    // Ссылка назад
    if(this.jImage<1)
     {
      if(this.objColPrev)
       this.objColPrev.className="galColNavD";
      if(this.objLinkPrev)
       this.objLinkPrev.style.visibility="hidden";
     }
     else
     {
      if(this.objColPrev)
       this.objColPrev.className="galColNav";
      if(this.objLinkPrev)
       this.objLinkPrev.style.visibility="visible";
     }
   
    // Ссылка вперед
    if(this.jImage>=this.arrGalleries[this.jGallery].arrImages.length-1)
     {
      if(this.objColNext)
       this.objColNext.className="galColNavD";
      if(this.objLinkNext)
       this.objLinkNext.style.visibility="hidden";
     }
     else
     {
      if(this.objColNext)
       this.objColNext.className="galColNav";
      if(this.objLinkNext)
       this.objLinkNext.style.visibility="visible";
     }
     
    if(this.objCnt)
     this.objCnt.innerHTML="№ "+(this.jImage+1)+" из "+this.arrGalleries[this.jGallery].arrImages.length; 
     
    if(this.objDescr)
     this.objDescr.innerHTML=this.arrGalleries[this.jGallery].arrImages[this.jImage].descr;
   
    if(this.objLinkImg)
     this.objLinkImg.focus();
   }
 };
// -->
