
var elewidth_ = 256;
var resinitretries_ = 30;
var resscrollers = new Array ( );

function InitSlideEngine ( objid )
{
	var resourceSlideContent = document.getElementById ( objid.toLowerCase ( ) );
	if ( resourceSlideContent )
	{
		var eles = resourceSlideContent.childNodes;
		var xc = 0;
		var i = 0;
		for ( var a = 0; a < eles.length; a++ )
		{
			if ( !eles[ a ].style ) continue;
			eles[ a ].style.position = 'absolute';
			eles[ a ].style.left = ( i++ * elewidth_ ) + 'px';
			eles[ a ].style.top = '0px';
		}
		
		
		// Fetch arrows from the node above the "content", on classname
		var arRight = getElementsByClassName ( 'ResourceSlideArrowRight', resourceSlideContent.parentNode.parentNode )[0];
		var arLeft = getElementsByClassName ( 'ResourceSlideArrowLeft', resourceSlideContent.parentNode.parentNode )[0];
		
		arRight.obj = resourceSlideContent;
		arLeft.obj = resourceSlideContent;
		
		arRight.onselectstart = function ( ){ return false; }
		arLeft.onselectstart = function ( ){ return false; }
		arRight.onmousedown = function ( )
		{
			this.obj.scroll ( -elewidth_ );
			return false;
		}
		arLeft.onmousedown = function ( )
		{
			this.obj.scroll ( elewidth_ );
			return false;
		}
		
		resscrollers[ objid.toLowerCase ( ) ] = resourceSlideContent;
		resourceSlideContent.i = i;
		resourceSlideContent.ind = objid.toLowerCase ( );
		resourceSlideContent.scroll = function ( vardir )
		{
			if ( i <= 3 )
				return;
			var cleft = parseInt ( this.offsetLeft );
			if ( !vardir ) vardir = 0;
			else
			{
				if ( this.interval ) clearInterval ( this.interval );
				var val = Math.round ( parseInt ( vardir ) / elewidth_ );
				this.target = ( Math.round ( cleft / elewidth_ ) + val ) * elewidth_;
				if ( this.target > 0 ) this.target = 0;
				else if ( Math.round ( this.target / elewidth_ ) <= -( this.i - 3 ) )
					this.target = elewidth_ * -( this.i - 3 );
				this.current = cleft;
			}
			var diff = ( this.current - this.target ) / 3;
			if ( Math.abs ( diff ) < 0.2 )
				this.style.left = this.target + 'px';
			else
			{
				this.current -= diff;
				var newleft = Math.round ( this.current ) + 'px';
				this.style.left = newleft;
				this.interval = setTimeout ( 'resscrollers[\''+this.ind+'\'].scroll ( );', 30 );
			}
		}
		return true;
	}
	else if ( resinitretries_-- ) setTimeout ( 'InitSlideEngine ( \'' + objid + '\' )', 30 );
}
function ResetSlide ( objid )
{
	resscrollers[objid.toLowerCase()].style.left = "0px";
}

