function GalNav(elGal, elCont, wid, pos)
{
    this.galleryDiv = document.getElementById( elGal );
    this.galleryContainer = document.getElementById( elCont );
    var imgs = this.galleryDiv.childNodes;
    this.maxRight = ((imgs.length - 2) * wid) + wid;
    this.step = (Math.round(this.galleryContainer.offsetWidth / wid) - 1) * wid;
    this.foot = this.step / 30;
    this.speed = 0;
    this.togo = 0;
    this.dir = 0;
    this.accel = false;

    if( pos > 0 ) {
	if( (pos * wid) > this.step )
	    this.galleryContainer.scrollLeft = (pos  * wid);
    }
}

GalNav.prototype.onMove = function()
{
    this.galleryContainer.scrollLeft += (this.foot * this.dir);
    this.togo --;

    if( this.togo != 0 ) {
	if( this.togo <= 10 )
	    this.accel = false;

	this.speed = (this.accel) ? this.speed/1.3 : this.speed*1.3;
	window.setTimeout( "gnav.onMove()", this.speed );
    }
}

GalNav.prototype.left = function()
{
    if( this.togo != 0 ) return;

    if( this.galleryContainer.scrollLeft > 0 ) {
	this.togo = 30;
	this.dir = -1;
	this.speed = 100;
	this.accel = true;
	window.setTimeout( "gnav.onMove()", this.speed );
    }
}

GalNav.prototype.right = function()
{
    if( this.togo != 0 ) return;

    if( (this.galleryContainer.scrollLeft + this.step) < this.maxRight ) {
	this.togo = 30;
	this.dir = 1;
	this.speed = 100;
	this.accel = true;
	window.setTimeout( "gnav.onMove()", this.speed );
    }
}
