//
//  This file is part of clientlogos, based upon Joomla extension briaskISS, Created  March 2008
//   clientlogos is free software: you can redistribute it and/or modify
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
//
//   clientlogos is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with clientlogos.  If not, see <http://www.gnu.org/licenses/>.
//  
//  This module was created on March 3rd 2009
//  By Quinten Bril
//  NowIC Webservices
//
// description clientlogos.prototype:
// initclientlogos: initialization, calls clientlogosnextpic then clientlogosshow
// clientlogosshow: shows picture, calls clientlogosnextpic then clientlogostransition
// clientlogosnextpic: goto next picture
// clientlogostransition: transition between logos, calls clientlogostransition or clientlogosshow
// 


function clientlogos(idModule, random, picInterval, transDelay, picArray)
{
	this.picRandom = random;
	this.picInterval = picInterval;
	this.transDelay = transDelay;
	this.picArray = picArray;
	this.curPic = 0;
	this.nextPic = 0;
	this.numPics = 0;
	this.curOpacity = 99;
	this.nextOpacity = 0;
	this.idModule = idModule;
	this.initclientlogos();
}

clientlogos.prototype.initclientlogos=function()
{
	if (!document.getElementById || !document.createElement) return;
	this.picArray[0]
		= document.getElementById("clientlogos"+this.idModule).getElementsByTagName("img");
	this.numPics = this.picArray[0].length ;
	for(i = 0; i < this.picArray[0].length; i++)
		{
			this.picArray[0][i].opacity = 0;
			this.picArray[0][i].style.MozOpacity = .0;
			this.picArray[0][i].style.filter = "alpha(opacity=0)";
		}
	if (this.picRandom == 3)
	{
		this.clientlogosnextpic();
	}
	this.picArray[0][this.nextPic].style.display = "block";
	this.picArray[0][this.nextPic].style.opacity = .99;
	this.picArray[0][this.nextPic].style.MozOpacity = .99;
	this.picArray[0][this.nextPic].style.filter = "alpha(opacity=" + (.99*100) + ")";
	this.curPic = this.nextPic;
	setTimeout("clientlogosinstance"+this.idModule+".clientlogosshow()", this.picInterval);
}

clientlogos.prototype.clientlogosshow=function()
{
	this.clientlogosnextpic();
	this.curOpacity = 100, this.nextOpacity = 0;
	setTimeout("clientlogosinstance"+this.idModule+".clientlogostransition()", this.transDelay);
}

clientlogos.prototype.clientlogosnextpic=function()
{
	if (this.picRandom < 3)
	{
		if (this.curPic < (this.numPics - 1))
		{
			this.nextPic = this.curPic + 1;
		}
		else
		{
			this.nextPic = 0;
		}
	}
	else
	{
		do
		{
			now = new Date();
			var rndPic = Math.ceil(this.numPics * Math.random(this.idModule)) - 1;
		} 	while (this.curPic == rndPic)
		this.nextPic = rndPic;
	}
}

clientlogos.prototype.clientlogostransition = function ()
{
	this.picArray[0][this.nextPic].style.display = "block";
	this.picArray[0][this.curPic].style.opacity = this.curOpacity/100;
	this.picArray[0][this.curPic].style.MozOpacity = this.curOpacity/100;
	this.picArray[0][this.curPic].style.filter = "alpha(opacity=" + (this.curOpacity) + ")";
	this.picArray[0][this.nextPic].style.opacity = this.nextOpacity/100;
	this.picArray[0][this.nextPic].style.MozOpacity = this.nextOpacity/100;
	this.picArray[0][this.nextPic].style.filter = "alpha(opacity=" + (this.nextOpacity) + ")";

	if (this.curOpacity > 0)
	{
		this.curOpacity -= 4;
		this.nextOpacity += 4;
		setTimeout("clientlogosinstance"+this.idModule+".clientlogostransition()", this.transDelay);
	}
	else
	{
		this.picArray[0][this.curPic].style.display = "none";
		this.curPic = this.nextPic;
		setTimeout("clientlogosinstance"+this.idModule+".clientlogosshow()", this.picInterval);
	}
}
