function OoomG( ss, sb, mvTiOut, txTiOut) {
  this.bp=null;
  this.imgEls=[6];
  this.swEls=[4];
  this.mapIdx=-3; //visible block start index
  this.ibl=3;     //initial Block length
  this.pRead=3;  //array length with loaded pictures
  this.cImIdx=0;  //index of the current picture
  this.r=0;
  this.stPos=-116;
  this.dynFotos=null;
  this.tabsArr=null;
  this.blank4=["","","",""];                   
  this.selUrl=null;
  this.selPict=null;
  this.selSwitchPict=null;
  this.div=null;
  this.switchDiv=null;
  this.smallPSufix=ss;
  this.fullPSufix=sb;
  this.initialTimeOut=200;
  this.movePause=50;
  this.shiftPause=300;
  this.textTO=txTiOut;
  this.sAEl=null;
  this.gfSt=1;
  this.timerPeriod=mvTiOut;
  this.timerHandle=0;
  this.cL2=ps$('skipLeft');
  this.cL=ps$('goLeft'   );
  this.cP=ps$('id_pause' );
  this.cR=ps$('goRight'  );
  this.cR2=ps$('skipRight');  
  this.idUeb=ps$('idUeb');
  this.curBl=0;
  this.nextBlockIdx=null;
} 

OoomG.prototype.callBack=function(){
   ++this.cImIdx;
   if( this.cImIdx<this.pRead)  {
     this.fetchPicture( this.cImIdx);
   } else if(this.cImIdx==this.ibl) {
     if( this.pnrEl) this.pnrEl.nodeValue + " ok";
     this.gfSt=8;
     this.direction="R";
    this.scheduleNextPicture( this.showNextPicture);    
  } 
}

OoomG.prototype.nextPicCB=function(){
  if( this.cImIdx && this.cImIdx==this.pRead )  {
     this.pRead++; // thumbernail fetched, go on with the big one
     this.fetchPicture( this.cImIdx);
} }

OoomG.prototype.fetchPicture=function( pictureIdx)  {
  var source=null;
  var whichpic=null;
  var cbf = this.callBack;
  var fD=this.dynFotos[ pictureIdx][0];
  if( pictureIdx < this.ibl && this.imgEls[ pictureIdx] && this.mapIdx<0 )   {
     whichpic = this.imgEls[ pictureIdx];
     whichpic.pictIdx=pictureIdx;
     source=fD+this.fullPSufix;
  } else if( pictureIdx==this.pRead )  {  // fetch the next thumbernail
     if( this.pnrEl) this.pnrEl.nodeValue = pictureIdx + "s";
     cbf = this.nextPicCB;
     if( pictureIdx < this.dynFotos.length)  {
       this.cImIdx=pictureIdx;
       source=fD+this.smallPSufix;
     }
  } else { // fetch the next ful Picture
       source=fD+this.fullPSufix;
  }
  if( source && typeof source=='string') { 
     new HTTP.ContentLoader( this.path+source, cbf, myerrorRout, 'GET', this); 
} }

OoomG.prototype.showPic=function( whichpic)  {
 if( whichpic && whichpic.src!=this.selUrl)  {
  this.bp.setAttribute( "src", whichpic.src.replace( this.smallPSufix, this.fullPSufix));
  this.remAct(this.selPict);
  this.selPict=whichpic;
  this.markAct(whichpic);
  this.selUrl=whichpic.src;
  this.showTexts(this.blank4);
  if(xDef(whichpic.arrIdx)) {
    var arrEl=this.dynFotos[whichpic.arrIdx];
    this.cSetTO( this.showTexts, this.textTO, this.dynFotos[whichpic.arrIdx]);
 } }
 return false;
}

OoomG.prototype.showTexts=function( linkObj)  {
 setTextOfEl( this.bName,"[" + this.mapIdx.toString() + "}=" + linkObj[0]);
 setTextOfEl( this.sAEl, linkObj[1]);
 setTextOfEl( this.sDEl, linkObj[2]);
 setTextOfEl( this.sBem, linkObj[3]);
}         

OoomG.prototype.remAct=function( whichPic)  {
   cssClass.remove(whichPic.parentNode,"sp");
}
OoomG.prototype.markAct=function( whichPic)  {
   cssClass.add(whichPic.parentNode,"sp");
}

OoomG.prototype.cSetTO=function( mName, timeOut, par1){
  var gaObj=this;
  var fPs=function() {
     mName.call( gaObj,par1);
  }
  this.tOut = setTimeout( fPs, timeOut );    
}

OoomG.prototype.startMoveGallery=function( newEp, whichpic) {
  if( this.r==0)  {
    this.showPic(whichpic);
    this.ep = newEp;
    var cp = parseInt( this.div.style.left);
    this.r = Math.ceil( Math.abs( this.ep - cp) / 2);
    if( this.r > 1)  {
      this.moveGallery();
} } }

OoomG.prototype.moveGallery=function() {
  var cp = parseInt( this.div.style.left);
  var curStep = this.getStep( cp);
  if( Math.abs( this.ep - cp) <= Math.abs(curStep) )  {
    var miDiff;
    if(curStep>0) miDiff=1;
    else          miDiff=-1;
    this.div.style.left=this.ep+"px";
    this.switchPictures( miDiff);
  } else {
    this.div.style.left = (cp + curStep) +'px';
    this.cSetTO( this.moveGallery, this.movePause);
} }


OoomG.prototype.getStep=function( cp)   {
  var alfa =  Math.asin( (Math.abs( cp - this.ep) - this.r) / this.r);
  var step =  Math.ceil(this.r * Math.cos( alfa) / 8);
  if( step == 0) step = 1;
  if( this.ep<cp) step *= -1;
  return step;
}

OoomG.prototype.switchPictures=function( miDiff)  {  
 this.mapIdx+=miDiff;
 var loopMapIdx=this.mapIdx+1;
 if( this.mapIdx==-2)  {
   loopMapIdx=-1;
 } else if( this.mapIdx==-1)  {
    loopMapIdx=0;
 }
 var i=this.mapIdx<-1? 1: 0;
 for( ;i<4; i++)  {
  var arrEl = this.dynFotos[i+loopMapIdx];
  this.swEls[i].src = this.path+arrEl[0]+this.smallPSufix;
  if( this.selUrl==this.swEls[i].src)  {
     this.remAct( this.selSwitchPict);
     this.selSwitchPict=this.swEls[i];
     this.markAct(this.swEls[i]);
  }
 }
 this.switchDiv.style.display='block';
 this.div.style.left=this.stPos+'px';
 this.displayBlockUeb(miDiff);
  this.cSetTO( this.shiftGallery, 300, miDiff);
}

OoomG.prototype.displayBlockUeb=function(miDiff) {
 if( this.mapIdx==this.nextBlockIdx)  {
   var ueb="?";
   if( miDiff==-1)  {
     if( this.curBl>0) this.curBl--;
     this.nextBlockIdx=this.tabsArr[this.curBl][0];
   } else {
     if( this.curBl<this.tabsArr.length-1) this.curBl++;
     this.nextBlockIdx=(this.curBl<this.tabsArr.length-1)? this.tabsArr[this.curBl+1][0]: this.dynFotos.length;
   }
   this.setRadio( this.curBl);
   ueb=this.tabsArr[this.curBl][1];
   setTextOfEl( this.idUeb, ueb);
 }
}

OoomG.prototype.setRadio=function( blNr)  {
   var radioObj=ps$("rdForm").rBlock;
   var rLength=radioObj.length;
   for(var i = 0; i < rLength; i++) {
     if( i==blNr)  {
        radioObj[i].checked = true;
     } else {
			radioObj[i].checked = false;
	  }
   }
}

OoomG.prototype.shiftGallery = function( mapIdxDiff)  {
   var marked=false;
   var i=0;
   var lE=this.imgEls.length-1;
   var notLoopEnd=function( idx) {
      return (idx<lE);
   }
   if( mapIdxDiff==-1)  {
      i=5;
      notLoopEnd=function( idx) { return idx>0;}
   }
   while( notLoopEnd(i))  {
     var wp=this.imgEls[i+mapIdxDiff];
     this.imgEls[i].src=wp.src;
     this.imgEls[i].arrIdx=wp.arrIdx;
     if( !marked && this.selUrl==this.imgEls[i].src)  {
       this.remAct( this.selPict);
       this.selPict=this.imgEls[i];
       this.markAct(this.selPict);
       marked=true;
     }
     i+=mapIdxDiff;
  }
  if( mapIdxDiff==-1 && this.mapIdx>=0)  { // shiftLeft
    this.imgEls[0].src=this.path+this.dynFotos[this.mapIdx][0]+this.smallPSufix;
    this.imgEls[0].arrIdx=this.mapIdx;
  } else if( mapIdxDiff==1 && (i+this.mapIdx)<this.pRead || this.pRead<this.dynFotos.length && i+this.mapIdx>0) {
    this.imgEls[i].src=this.path+this.dynFotos[ i+this.mapIdx][0]+this.smallPSufix;
    this.imgEls[i].arrIdx=i+this.mapIdx;
    if( (i+this.mapIdx)==this.pRead) {
       this.fetchPicture( this.pRead);
    }   
  } else if( mapIdxDiff==-1 && this.mapIdx==-1)  { // shiftLeft
     this.gfSt=1;
     this.setCtrlStatus();
  }
  this.cSetTO( this.switchBack, this.shiftPause );
}
OoomG.prototype.switchBack=function()  {
  this.switchDiv.style.display='none';
  this.r = 0;
  if( this.gfSt==8)  {
    this.scheduleNextPicture( this.showNextPicture);    
  }
}
OoomG.prototype.setCtrlStatus=function()  {
  var st=this.gfSt;
  var l2="ar2Left_32p16.bmp"; 
  var l="arLeft_16p16.bmp"; 
  var p="pause_12p16.bmp"; 
  var r="arRight_16p16.bmp"; 
  var r2="ar2Right_32p16.bmp"; 
  
  if( st&1)  {
   l2="in_"+l2;
   l="in_"+l;
  } else if( st&4)  {
   r2="in_"+r2;
   r="in_"+r;
  }
  if( st&8)  {
   if( this.direction=="L")  {
      l="act_"+l;
   } else if( this.direction=="R")  {
      r="act_"+r;
   }
  } else {
    p="in_"+p; 
  }
 this.cL2.src=this.path+l2;
 this.cL.src=this.path+l;
 this.cP.src=this.path+p;
 this.cR.src=this.path+r;
 this.cR2.src=this.path+r2;
}
 
OoomG.prototype.shiftGalleryRight=function(event) {
  var target=this;
  if( !this.src && window.event) {
     target = window.event.srcElement;
  }
 if(xDef(target.galleryObj)) {
   var ta = target.galleryObj;
   ta.direction="R";
   ta.gfSt=8;
  if( ta.r==0)  {
    ta.scheduleNextPicture( ta.showNextPicture);    
  } else {
    ta.setCtrlStatus();      
  } 
 }
}

OoomG.prototype.isEnd=function( )  {
  var retval=false;
  if( this.mapIdx+this.imgEls.length>this.dynFotos.length) {
     retval=true;
  }
  return retval;
}
   
OoomG.prototype.sgr=function( whichpic )  {
  if( this.mapIdx==-1 && this.imgEls[1].gallery==null)  {
     this.imgEls[1].galleryObj=this;
  } 
  if(!this.isEnd()) {
     this.startMoveGallery( -3, whichpic);
  } else {
    this.gfSt=4;
    this.setCtrlStatus();
  }
  return false;
}

OoomG.prototype.shiftGalleryLeft=function(event) {
   var target=this;
   if( !this.src && window.event) {
      target = window.event.srcElement;
   }
  if(xDef(target.galleryObj)) {
   var ta = target.galleryObj;
   ta.direction="L";
   ta.gfSt=8;
   if( ta.r==0)  {
    ta.scheduleNextPicture( ta.showNextPicture);    
   } else {
    ta.setCtrlStatus();      
  }}
}

OoomG.prototype.sgl=function( whichpic)  {
  if( this.mapIdx>=0)  {
     this.startMoveGallery( -228, whichpic);
  }
  return false;
}

OoomG.prototype.showNextPicture=function()  {
 if( this.gfSt==8) {
   if( this.direction=="R")  {
     this.sgr.call( this, this.imgEls[4]);
   } else if( this.direction=="L")  {
     this.sgl.call( this, this.imgEls[1]);
 } }  
}

OoomG.prototype.scheduleNextPicture=function(mName)  {
  clearTimeout(this.timerHandle);
  var gaObj=this;
  var fPs=function() {
     mName.call( gaObj);
  }
  this.timerHandle = setTimeout( fPs, this.timerPeriod );
  this.setCtrlStatus();
}

OoomG.prototype.onSkipL=function(){
   this.gfSt=8;
   this.direction="L";
   this.mapIdx=this.getLSkipIdx( this.mapIdx);
   this.loadPicts( this.mapIdx, 1);
   this.scheduleNextPicture( this.showNextPicture);    
}

OoomG.prototype.loadPicts=function( mi, actIdx) {
 this.imgEls[0].src=this.path+this.dynFotos[ mi][0]+this.smallPSufix;
 this.imgEls[0].arrIdx=mi;
 for( i=0;i<4;i++) {
  this.imgEls[i+1].arrIdx=(mi+i+1);
  var srcp=this.path+this.dynFotos[ mi+i+1][0]+this.smallPSufix;
  this.imgEls[i+1].src=srcp;
  this.swEls[i].src=srcp;
 }
 this.imgEls[5].arrIdx=mi+5;
 this.imgEls[5].src=this.path+this.dynFotos[ mi+5][0]+this.smallPSufix;
 this.selUrl=this.imgEls[actIdx].src;
 this.showPic( this.imgEls[mi+actIdx]);
}

OoomG.prototype.onGoL=function(){
   this.gfSt=8;
   this.direction="L";
   var i=this.tabsArr.length-1;
   while( i>0 && this.mapIdx<this.tabsArr[i][0])  {
      i--;
   }
   this.nextBlockIdx=this.tabsArr[i][0];
   this.displayBlockUeb( -1);
   this.scheduleNextPicture( this.showNextPicture);    
}
OoomG.prototype.onPause=function(){
   this.gfSt=0;
   this.setCtrlStatus();   
}
OoomG.prototype.onGoR=function(){
   this.gfSt=8;
   this.direction="R";
   var i=0;
   while( i<this.tabsArr.length-1 && this.mapIdx>this.tabsArr[i][0])  {
      i++;
   }
   this.nextBlockIdx=i<this.tabsArr.length? this.tabsArr[i][0]: this.dynFotos.length;
   this.displayBlockUeb(1);
   this.scheduleNextPicture( this.showNextPicture);    
}

OoomG.prototype.onSkipR=function(){
   this.gfSt=8;
   this.mapIdx=this.getRSkipIdx( this.mapIdx);
   this.pRead=this.cImIdx=this.mapIdx+6;
   this.direction="R";
   this.loadPicts( this.mapIdx, 4);
   this.scheduleNextPicture( this.showNextPicture);    
}

OoomG.prototype.getRSkipIdx=function( cMIdx) {
  var retval = this.dynFotos.length-6;
  for( i=0; i<this.tabsArr.length;i++)  {
    if( this.tabsArr[i][0]>cMIdx)  {
       retval=this.tabsArr[i][0];
       this.curBl=i;
       this.setRadio( i);
       var ueb=this.tabsArr[i][1];
       setTextOfEl( this.idUeb, ueb);
       this.nextBlockIdx=(i<this.tabsArr.length-1)? this.tabsArr[i+1][0]: this.dynFotos.length;
       i=this.tabsArr.length;
  }  }
  return retval;
}   

OoomG.prototype.getLSkipIdx=function( cMIdx, add1) {
  var retval = 0;
  for( i=this.tabsArr.length-1; i>=0;i--)  {
    if( this.tabsArr[i][0]<cMIdx)  {
       retval=this.tabsArr[i][0];
       if(!add1)i=i>0? i-1: 0;
       this.nextBlockIdx=this.tabsArr[i][0];
       this.curBl=i;
       this.setRadio( i);
       var ueb=this.tabsArr[i][1];
       setTextOfEl( this.idUeb, ueb);
       i=0;
  }  }
  return retval;
}   

OoomG.prototype.selectRadio=function( blNr)  {
 var bIdx=this.tabsArr[blNr][0];
 if( this.direction=='R')  {
   this.mapIdx=this.getRSkipIdx( bIdx-1 );
   this.pRead=this.cImIdx=this.mapIdx+6;
   this.loadPicts( this.mapIdx, 4);
 } else {
   var blIdx=bIdx;
   if( blNr<this.tabsArr.length-1) {
      blNr++;
      blIdx=this.tabsArr[blNr][0];
   } else {
      blIdx=this.dynFotos.length-6;
   }
  var mIdx=this.getLSkipIdx( blIdx, 1);
  this.mapIdx=blIdx;
   this.pRead=this.cImIdx=this.mapIdx+6;
   this.loadPicts( this.mapIdx, 4);
 }
 if( this.gfSt==8)  {
   this.scheduleNextPicture( this.showNextPicture);    
 }   
}
   
   
OoomG.prototype.init=function() {
 this.bp = ps$( "img_ashs1");
 this.sAEl=ps$('sAsana');
 this.sDEl=ps$('dAsana');
 this.sBem=ps$('bem');

 this.bName=ps$('bname');
 this.div = ps$( "div_smallPictures");
 this.switchDiv = ps$( "div_switchPictures");
 var imgs=this.div.getElementsByTagName( "img");
 var imgsLen = imgs.length-1;
 for( var i=imgsLen; i>=0; i--)  {
    this.imgEls[i]=imgs[imgsLen-i];
    this.imgEls[i].galleryObj=this;
    this.imgEls[i].onclick = function() {
      return this.galleryObj.showPic.call( this.galleryObj, this);
 }  }
 var whichpic = this.imgEls[ 3];
 whichpic.arrIdx=0;
 this.imgEls[ 4].arrIdx=1;
 this.imgEls[ 5].arrIdx=2;
 if( whichpic && whichpic.src && typeof whichpic.src=='string')   {
    var li = whichpic.src.lastIndexOf( '/') + 1;
    this.path=whichpic.src.substring(0, li);
    this.selPict=whichpic;
    this.showPic(whichpic);
 }
 imgs = this.switchDiv.getElementsByTagName( "img");
 this.selSwitchPict=this.swEls[ 0];
 for( var i=imgs.length; i>0; i--)  {
   this.swEls[i-1]=imgs[imgs.length-i];
   this.swEls[i-1].galleryObj=this;
   this.swEls[i-1].onclick = function() {
     return this.galleryObj.showPic.call( this.galleryObj, this);
 }  }
 var div_pnr=ps$('div_pnr');
 if( div_pnr) this.pnrEl=div_pnr.childNodes[ 0];
 if(!this.div.style.left) this.div.style.left = this.stPos + 'px';
 this.cSetTO( this.fetchPicture, this.initialTimeOut, 0);
 this.cL2.galleryObj=this.cL.galleryObj=this.cP.galleryObj=this.cR.galleryObj=this.cR2.galleryObj=this;
 this.cL2.onclick = function() { return this.galleryObj.onSkipL.call( this.galleryObj); }
 this.cL.onclick = function() { return this.galleryObj.onGoL.call( this.galleryObj); }
 this.cP.onclick = function() { return this.galleryObj.onPause.call( this.galleryObj); }
 this.cR.onclick = function() { return this.galleryObj.onGoR.call( this.galleryObj); }
 this.cR2.onclick = function() { return this.galleryObj.onSkipR.call( this.galleryObj); }
 this.setCtrlStatus();
 
 imgs=ps$( "rdForm").getElementsByTagName( "input");
 for( var i=imgs.length-1; i>=0; i--)  {
   imgs[i].galleryObj=this;
   imgs[i].onclick = function() {
     return this.galleryObj.selectRadio.call( this.galleryObj, parseInt( this.id.substring( 5)));
 }  }
 this.setRadio(0);
}

OoomG.prototype.acb=function( responseText)  {
   var scriptEl = document.createElement("script");
   scriptEl.text=responseText;
   document.body.appendChild( scriptEl);
   this.dynFotos=fotosArray;
   this.tabsArr=tabsTArr;
   this.nextBlockIdx=tabsTArr[1][0];
   this.init.call( this); 
}

