function xenGallery(aID)
{this.id=aID;
 this.count=0;
 this.sel=null;
 this.firstImgId=null;
 this.images=new Array();
 this.currentwidth=400;
 this.currentheight=300;
 this.transspeed=500;
 this.fadespeed=300;
 this.thumbscrollpixels=60;
 this.thumbcount=7;
 this.thumbpos=0;
 this.minthumbpos=0;
 var owol=window.onload;
 var xg=this;
 window.onload=function(){if('function'==typeof(owol))owol();xg.showImage(xg.firstImgId);}
}

xenGallery.prototype.init=function()
{this.imgObj=this.getObj('pg'+this.id+'img');
 this.descObj=this.getObj('pg'+this.id+'desc');
 this.minthumbpos=-(this.thumbscrollpixels*(this.count-this.thumbcount));
 this.setVis('pg'+this.id+'thumbleft',this.thumbpos<0?'visible':'hidden');
 this.setVis('pg'+this.id+'thumbright',this.thumbpos>this.minthumbpos?'visible':'hidden');
}

xenGallery.prototype.addImage=function(aId,aSrc,aW,aH,aTitle,aDesc)
{if(!this.images[aId]) this.count++;
 if(null==this.firstImgId) this.firstImgId=aId;
 this.images[aId]={'src':aSrc,'width':aW,'height':aH,'title':aTitle,'desc':aDesc,'img':null};
}

xenGallery.prototype.loadImage=function(aId)
{if(!this.images[aId]) return false;
 var xg=this;
 if(null==this.images[aId].img)
  {
    this.images[aId].img=new Image()
    this.images[aId].img.onload=function(){imageloaded(xg,aId);}
    this.images[aId].img.src=this.images[aId].src;
  }
 else imageloaded(xg,aId);

 function imageloaded(xg,aId)
  {
    if(null==xg.imgObj) xg.init();
    xg.imgObj.innerHTML='<img src="'+xg.images[aId].src+'" border="0" id="'+aId+'">';
    xg.descObj.innerHTML="<p>"+xg.images[aId].title+"</p>"+xg.images[aId].desc;
    var fader=new Fx.Style('pg'+xg.id+'img','opacity',{duration:xg.fadespeed});
    var fader2=new Fx.Style('pg'+xg.id+'desc','opacity',{duration:xg.fadespeed});
    fader.set(0); fader.start(0,1); fader2.set(1);
    xg.sel=aId;
    xg.images[aId].img=true;
  }
}

xenGallery.prototype.showImage=function(aId)
{if(!this.images[aId]) return false;
 if(this.sel!=aId)
  {var xg=this;
   xg.w=xg.images[aId].width; xg.h=xg.images[aId].height
   var resizeDiv=new Fx.Styles('pg'+xg.id+'image',{duration:xg.transspeed, onComplete: function(){xg.loadImage(aId);xg.currentheight=xg.h;xg.currentwidth=xg.w;}});
   var fader=new Fx.Style('pg'+xg.id+'img','opacity',{duration:xg.fadespeed, onComplete: function(){resizeDiv.start({'height':[xg.currentheight,xg.h],'width':[xg.currentwidth,xg.w]});}});
   var fader2=new Fx.Style('pg'+xg.id+'desc','opacity',{duration:xg.fadespeed});
   fader.start(1,0); fader2.set(0);
  }
}

xenGallery.prototype.scrollThumbs=function(aDelta)
{if(aDelta)
  {
    var np=this.thumbpos-aDelta*this.thumbscrollpixels;
    if(np>0) np=0;
    else if(np<this.minthumbpos) np=this.minthumbpos;
    var anim=new Fx.Styles('pg'+this.id+'thumbgall',{duration:this.transspeed, transition:Fx.Transitions.quadOut});
    anim.start({left:[this.thumbpos,np]});
    this.thumbpos=np;
  }
 this.setVis('pg'+this.id+'thumbleft',this.thumbpos<0?'visible':'hidden');
 this.setVis('pg'+this.id+'thumbright',this.thumbpos>this.minthumbpos?'visible':'hidden');
}


xenGallery.prototype.getObj=function(id,d)
{var i,o,d; if(!d) d=document;
 if(!(o=d[id])&&d.all) o=d.all[id];
 if(!o&&d.getElementById) o=d.getElementById(id);
 for(i=0;!o&&i<d.forms.length;i++) o=d.forms[i][id];
 for(i=0;!o&&d.layers&&i<d.layers.length;i++) o=getObj(id,d.layers[i].document);
 return o;
}

xenGallery.prototype.setVis=function(id,v)
{var obj=this.getObj(id);
 if(null!=obj)
  {
    if (obj.style) obj=obj.style;
    obj.visibility=v;
  }
}



// function xenTabBox_Select(aSel)
// {if(!this.id||!this.count||aSel<1||aSel>this.count) return false;
//  var oTabBL,oTabBR,oTabBody,oTabPanel;
//  if(this.sel>0)
//    {if(!(oTabBL=this.getObj('TabBorder_'+(this.sel-1)))
//      ||!(oTabBR=this.getObj('TabBorder_'+this.sel))
//      ||!(oTabBody=this.getObj('TabBody_'+this.sel))
//      ||!(oTabPanel=this.getObj('TabPanel_'+this.sel))
//       ) return false;
//     oTabBL.className='tbTabBorder'+(this.sel==1?'First':'');
//     oTabBR.className='tbTabBorder'+(this.sel==this.count?'Last':'');
//     oTabBody.className='tbTabBody';
//     oTabPanel.className='tbTabPanel';
//    }
//  this.sel=aSel;
//  if(this.sel>0)
//    {if(!(oTabBL=this.getObj('TabBorder_'+(this.sel-1)))
//      ||!(oTabBR=this.getObj('TabBorder_'+this.sel))
//      ||!(oTabBody=this.getObj('TabBody_'+this.sel))
//      ||!(oTabPanel=this.getObj('TabPanel_'+this.sel))
//       ) return false;
//     oTabBL.className='tbTabBorder'+(this.sel==1?'FirstSel':'Sel');
//     oTabBR.className='tbTabBorder'+(this.sel==this.count?'LastSel':'AfterSel');
//     oTabBody.className='tbTabBodySel';
//     oTabPanel.className='tbTabPanelSel';
//    }
// }
