function imageGalery(){
  var imagesx;
  var positionx;
  var imgDiv;
  var imgX;
  var prev;
  var closep;
  var next;
  var added=false;
  var controlPanel;
  var oldh=null;
  var newh=null
  var interval=0;
  var minwidth=200;
  var minheight=100;
  
  this.init=init;
  this.getParam=getParam;
  this.setinit=setinit;

  
  function getScImgSize(images){
       for(i=0;i<images.length;i++){
         images[i][1]=(images[i][1]>minwidth)?images[i][1]:minwidth;
         images[i][2]=(images[i][2]>minheight)?images[i][2]:minheight;
       }
       return images;
  }
  
  function setinit(images,position,addedx){
       imagesx=getScImgSize(images);
       positionx=position;
       added=false;
  }
  

  
  function init(){
    if(!imgX){
     imgX = document.createElement('img');
    }
    if(!added){
     controlPanel = document.createElement('div');
     imgDiv = document.createElement('div');
     prev = document.createElement('div');
     next = document.createElement('div');
     closep = document.createElement('div');
     controlPanel.style.width=minwidth+'px';
     controlPanel.style.height=minheight+'px';
     imgDiv.style.width=minwidth+'px';
     imgDiv.style.height=minheight+'px';
     msngr.setWidth(minwidth);
    } 
     addControls();

     
     controlPanel.style.position='absolute';
     controlPanel.style.zIndex='201';
    // controlPanel.style.width=imagesx[positionx][1]+'px';
     //controlPanel.style.height=imagesx[positionx][2]+'px';
     controlPanel.cursor="pointer";
     //controlPanel.style.backgroundColor="blue";
     showControls(false);
     //
     /**/
     
     //imgDiv.style.width=imagesx[positionx][1]+'px';
     //imgDiv.style.height=imagesx[positionx][2]+'px';
     imgDiv.style.background="transparent url('/images/loading.gif') no-repeat scroll center center";
     //imgDiv.style.backgroundColor="green";
     imgX.src=imagesx[positionx][0];
     imgX.style.display='none';
     controlPanel.id="IG.controlPanel";
     imgX.id="IG.imgX";
     imgDiv.id="IG.imgDiv";
     if(!added){
       msngr.setText("");
       msngr.addElementX(controlPanel);
       msngr.addElementX(imgX);
       msngr.addElementX(imgDiv);
       added=true;
     }
     window.addEvent('domready', function() {
        var imgDivE = new Fx.Morph($('IG.imgDiv'), {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
        var text_place_cE = new Fx.Morph($('text_place_c'), {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
        var text_place_fE = new Fx.Morph($('text_place_f'), {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
        var text_placeE = new Fx.Morph($('text_place'), {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
        var controlPanelE = new Fx.Morph($('IG.controlPanel'), {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
        
        $('IG.imgX').addEvent('load',function (e){ 
          if(e)e.stop();
          
          text_place_cE.start({
              'width' : (imagesx[positionx][1]+69),
              'maxWidth' : (imagesx[positionx][1]+47)
          });
          text_place_fE.start({
              'width' : (imagesx[positionx][1]+44),
              'maxWidth' : (imagesx[positionx][1]+22)
          });
          text_placeE.start({
              'width' : (imagesx[positionx][1]+22),
              'maxWidth' : (imagesx[positionx][1])
          });
          controlPanelE.start({
              'height': imagesx[positionx][2],  //Morphs the width from the current to 300px.
              'width' : imagesx[positionx][1]
          });
          imgDivE.start({
              'height': imagesx[positionx][2],  //Morphs the width from the current to 300px.
              'width' : imagesx[positionx][1]
          });
          $('IG.imgDiv').setStyles({
            background: "transparent url('"+$('IG.imgX').src+"') no-repeat scroll center center",
            opacity: '0.01'
          });
          $('IG.imgDiv').fade(1);

          showControls(true);
        });
      })

  }
  
  /*function faster(){
    //interval = window.setInterval(imgGaleryX.heightResize,100);
    for(i=1;i<1000;i++){
      //alert(i*50);
      window.setTimeout(
        function(){
          
          window.setInterval(imgGaleryX.heightResize,1);
        }
      ,i*50
      );
    }
  }*/
  
  function showControls(show1){
    if(show1){
      
          controlPanel.style.opacity = 1;
	        controlPanel.style.filter = 'alpha(opacity=' + 100 + ')';
    }else{
          controlPanel.style.opacity = 0.01;
	        controlPanel.style.filter = 'alpha(opacity=' + 1 + ')';
    }
    last=!(positionx<imagesx.length-1);
    first=!(positionx>0);
    prev.onmouseover=function(){
          prev.style.opacity = 0.3;
	        prev.style.filter = 'alpha(opacity=' + 30 + ')';
        
    }
    prev.onmouseout=function(){
          prev.style.opacity = 0.01;
	        prev.style.filter = 'alpha(opacity=' + 1 + ')';
    }
    if(!first){
          prev.style.background="white url('/images/prev1.gif') no-repeat scroll center center";
          prev.onclick=function(){
            positionx--;
            init();
  
          }
    }else{
          prev.onclick=null;
          prev.style.background="white url('/images/stop1.gif') no-repeat scroll center center";
    }
    
    closep.onmouseover=function(){
          closep.style.opacity = 0.3;
	        closep.style.filter = 'alpha(opacity=' + 30 + ')';
        
    }
    closep.onmouseout=function(){
          closep.style.opacity = 0.01;
	        closep.style.filter = 'alpha(opacity=' + 1 + ')';
    }
    closep.onclick=function(){
          msngr.close();
    }
    
    next.onmouseover=function(){
          next.style.opacity = 0.3;
	        next.style.filter = 'alpha(opacity=' + 30 + ')';
        
    }
    next.onmouseout=function(){
          next.style.opacity = 0.01;
	        next.style.filter = 'alpha(opacity=' + 1 + ')';
	        
    }
    
    if(!last){
          next.style.background="white url('/images/next1.gif') no-repeat scroll center center";
          next.onclick=function(){
            positionx++;
            init();

          }
    }else{
          next.onclick=null;
          next.style.background="white url('/images/stop1.gif') no-repeat scroll center center";
    }
    
    
  }
  
  function addControls(){
    if(imagesx.length==1)percent=[0,100,0];else percent=[30,40,30];
    
    opacity=1;
    prev.style.width=percent[0]+"%";
    prev.style.height="100%";
    prev.style.cssFloat="left";
    prev.style.styleFloat="left";
    prev.style.background="white url('/images/prev1.gif') no-repeat scroll center center";
    prev.style.opacity = opacity/100;
    prev.style.cursor="pointer";
	  prev.style.filter = 'alpha(opacity=' + opacity + ')';
    
	  closep.style.width=percent[1]+"%";
    closep.style.height="100%";
    closep.style.cssFloat="left";
    closep.style.styleFloat="left";
    closep.style.cursor="pointer";
    closep.style.background="white url('/images/closep.gif') no-repeat scroll center center";
    closep.style.opacity = opacity/100;
	  closep.style.filter = 'alpha(opacity=' + opacity + ')';
   
    next.style.width=percent[2]+"%";
    next.style.height="100%";
    next.style.cssFloat="left";
    next.style.styleFloat="left";
    next.style.cursor="pointer";
    next.style.background="white url('/images/next1.gif') no-repeat scroll center center";
    next.style.opacity = opacity/100;
	  next.style.filter = 'alpha(opacity=' + opacity + ')';

    if(!(imagesx.length==1))controlPanel.appendChild(prev);
    controlPanel.appendChild(closep);
    if(!(imagesx.length==1))controlPanel.appendChild(next); 
  }
  

  function getParam(paramName){
    eval("node = " + paramName);
    return node;
  }
}