// (c) 2007 by Rob Jansman, http://www.xs4all.nl/~rjansman/ict/
//
// requires an object called: browser, with properties: ie4win and ie55win! (false or true)
//
// overlap 1.0 - volledige overlap
// overlap 0.0 - geen overlap (eerste fade volledig uit, dan pas fade de tweede in)
// overlap 0.4 - 30% van de gegeven tijd alleen uitfaden eerste, 40% uitfaden eerste + infaden tweede, 30% infaden tweede


function CLoadPictureArray(path, idCounter)
{
	this.path = path;
	if (idCounter)
		this.idCounter = idCounter;
	this.a = new Array();
	this.nIndex = -1;

	this.ref = "CLoadPictureArray_" + ++CLoadPictureArray.nEntityCount;
	eval(this.ref + "=this");
}
CLoadPictureArray.nEntityCount = 0;
CLoadPictureArray.prototype.Add = function(sSrc, sName, bTransferOnload, nFadeTime, nOverlap)
							{ this.a[this.a.length] = new CCacheImg(sSrc, sName, bTransferOnload, nFadeTime, nOverlap); };
CLoadPictureArray.prototype.GetCount = function() { return this.a.length; };
CLoadPictureArray.prototype.PicIsComplete = function(nIndex) { return this.a[nIndex].IsComplete(); };
CLoadPictureArray.prototype.TransferPic = function(nIndex) { this.a[nIndex].Transfer(this.path); };
CLoadPictureArray.prototype.Transfer = function() { this.TransferPic(this.nIndex); };
CLoadPictureArray.prototype.LoadAll = function(action)
{
	if (action)
		this.action = action;

	if (this.LoadNext())
		this.CheckLoaded();
	else if (this.action)
		eval(this.action);

	if (this.idCounter)
	{
		var obj;
		if (document.getElementById)	// version 6 browsers
			obj = document.getElementById(this.idCounter);
		else if (document.all)
			obj = document.all[this.idCounter];
		if (obj && obj.innerHTML)
			obj.innerHTML = (this.a.length - this.nIndex);
	}
}
CLoadPictureArray.prototype.LoadNext = function()
{
	if (++this.nIndex >= this.a.length)
		return false;

	this.a[this.nIndex].Load(this.path);
	return true;
}
CLoadPictureArray.prototype.CheckLoaded = function()
{
	if (!this.a[this.nIndex].IsComplete())
		setTimeout(this.ref + ".CheckLoaded()", 50);
	else
	{
		if (this.a[this.nIndex].bTransferOnload)
			this.Transfer();
		this.LoadAll();
	}
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function CCacheImg(sSrc, sName, bTransferOnload, nFadeTime, nOverlap)
{
	this.src = sSrc;
	if (sName)
		this.name = sName;
	if (bTransferOnload)
		this.bTransferOnload = true;
	if (nFadeTime)
		this.nFadeTime = nFadeTime;
	this.nOverlap = ((nOverlap || nOverlap === 0) ? nOverlap : 1);
}
CCacheImg.prototype.Load = function(sPath) { this.img = new Image(); this.img.src = sPath + this.src; };
CCacheImg.prototype.IsComplete = function() { return (this.img && this.img.complete); };
CCacheImg.prototype.Transfer = function(sPath)
{
	if (this.name && document[this.name])
	{
		if (this.nFadeTime && browser.ie4win)
		{
			document[this.name].style.filter = (browser.ie55win ?
				("progid:DXImageTransform.Microsoft.Fade(duration=" + this.nFadeTime + ", overlap=" + this.nOverlap + ")") :
				("blendTrans(duration=" + this.nFadeTime + ")"));
			document[this.name].filters[0].apply();
		}
		document[this.name].src = sPath + this.src;
		if (this.nFadeTime && browser.ie4win)
			document[this.name].filters[0].play();
	}
}

