var _showcase;

function ShowCase(strWindowDiv, iWindowWidth, strContentDiv, iContentWidth, iItemWidth, fnEndPlayCB)
{
	// attach us to the global
	_showcase = this;
	
	// store members
	this.fnEndPlayCB = fnEndPlayCB;

	// get elements
	this.divWindow = document.getElementById(strWindowDiv);
	this.divContent = document.getElementById(strContentDiv);

	// set constraints
	this.minX = (iContentWidth - iWindowWidth) * -1;
	this.maxX = 0;
	this.iItemWidth = iItemWidth;
	this.iStopPoint = 0;
	this.bPlaying = false;

	this.play = function(iDir)
	{
		this.bPlaying = true;
		return this.scroll(iDir);
	}
	
	this.pause = function()	{ this.bPlaying = false; this.stopScroll(); }

	this.scroll = function(iDir)
	{
		this.iDir = iDir * -1;
		
		// check boundaries
		if ((this.iDir == -1 && this.iStopPoint == this.minX) || (this.iDir == 1 && this.iStopPoint == 0)) { return false; }

		// calculate next stop point
		var iX = parseInt(this.divContent.style.left);
		if (Math.abs(this.iStopPoint - iX) < 5 || (this.iDir == -1 && this.iStopPoint > iX) || (this.iDir == 1 && this.iStopPoint < iX))
		{
			this.iStopPoint += this.iItemWidth * this.iDir;
		}
		
		// start scroll
		this.hInterval = window.setInterval("_showcase.doScroll()", 10);
		return true;
	}
	
	this.doScroll = function()
	{
		var iX = parseInt(this.divContent.style.left);
		
		// have we scrolled far enough yet?
		if ((this.iDir == -1 && iX <= this.iStopPoint) || (this.iDir == 1 && iX >= this.iStopPoint))
		{
			// are we in play mode & not at the boundary?
			if (this.bPlaying && this.iStopPoint > this.minX && this.iStopPoint < 0)
			{
				// set new stop point an continue
				this.iStopPoint = this.iStopPoint + (this.iDir * this.iItemWidth);
			}
			else
			{
				// stop
				this.bPlaying = false;
				this.stopScroll();
				return;
			}
		}

		// scroll a bit
		iX = iX + this.iDir * 2;
		if (iX >= this.minX && iX <= this.maxX)
		{
			this.divContent.style.left = iX + "px";
		}
		else
		{
			this.stopScroll();
		}
	}
	
	this.stopScroll = function()
	{
		clearInterval(this.hInterval);
		this.fnEndPlayCB(this.iStopPoint >= 0, this.iStopPoint <= this.minX);
	}
} // end class

