//Copyright 2002 - DPA Software
//All Rights Reserved
//http://www.frontlook.com/

var flpe_dispheight;
var flpe_dispwidth;
var LastBand20040426174410 = -1;

// check for browser
var flpe_ns4up, flpe_ie4up, flpe_ns6up;

// only if browser is not N3, scan for the other browsers. otherwise N3 shows error
if ( navigator.appName == "Netscape" && parseInt(navigator.appVersion,10) == 3 )
{
	flpe_ns4up = flpe_ie4up = flpe_ns6up = 0;
}
else
{
	flpe_ie4up = (document.all) ? 1 : 0;
	flpe_ns6up = (document.getElementById && !flpe_ie4up)? 1 : 0;
	if ( ! flpe_ie4up && ! flpe_ns6up ) flpe_ns4up = 1;  // browser sniffer
}

flpe_dispheight = 0
flpe_dispwidth = 0

if ( flpe_ns4up || flpe_ie4up || flpe_ns6up )
{
	if (flpe_ie4up)
	{
		flpe_dispheight = document.body.clientHeight;
		flpe_dispwidth = document.body.clientWidth;
	}
	else if(flpe_ns4up)
	{
		flpe_dispheight = self.innerHeight;
		flpe_dispwidth = self.innerWidth;
	}
	else if(flpe_ns6up)
	{
		flpe_dispheight = self.innerHeight;
		flpe_dispwidth = self.innerWidth;
	}
}

//Copyright 2002 - DPA Software
//All Rights Reserved
//http://www.frontlook.com/

function FlpeAnimation20040426174410(Name,LoopSound,MuteSound,SoundFile,BottomMargin,RightMargin,Timeout,MaxObj,ObjEntryDelay,
	StepDelay,Effect,Displacement,Variation,ObjEntryWidth,ObjAtStartup,
	Image1,Image2,Image3,Image4,Image5,
	FlippedImg1,FlippedImg2,FlippedImg3,FlippedImg4,FlippedImg5,ImageCount)
{
	if ( !flpe_ns4up && !flpe_ns6up && !flpe_ie4up )
	{
		return null;
	}
	
	if (Image1 == "" && Image2 == "" && Image3 == "" && Image4 == "" && Image5 == "")
	{
		return null;
	}
	var objname;
	
	//Member variables
	this.ImageArray = new Array();
	this.FlippedImgArray = new Array();
		
	this.name = "pe" + Name;
	this.AudioApplet = "DPAAudio" + Name;
	this.SoundFile = SoundFile;
	this.BottomMargin = BottomMargin;
	this.RightMargin = RightMargin;
	this.MaxObj = MaxObj;
	this.ObjEntryDelay = ObjEntryDelay;
	this.StepDelay = StepDelay;
	this.Effect = Effect;
	this.Displacement = Displacement;
	this.Variation = Variation;
	this.ObjEntryWidth = ObjEntryWidth;
	this.ObjAtStartup = ObjAtStartup;
	this.ImageCount = ImageCount;
	
	this.ImageArray[0] = Image1;
	this.ImageArray[1] = Image2;
	this.ImageArray[2] = Image3;
	this.ImageArray[3] = Image4;
	this.ImageArray[4] = Image5;
	
	this.FlippedImgArray[0] = FlippedImg1; 
	this.FlippedImgArray[1] = FlippedImg2; 
	this.FlippedImgArray[2] = FlippedImg3; 
	this.FlippedImgArray[3] = FlippedImg4; 
	this.FlippedImgArray[4] = FlippedImg5; 
		
	//this.offSet	= 0;
	this.SoundMode = 0;
	
	//Memeber functions
	this.AddAnimationImage = AddAnimationImage20040426174410;
	this.AnimationImage = AnimationImage20040426174410;
	this.Move = Move20040426174410;
	this.StopAnimation = StopAnimation20040426174410;
	this.InitSound = InitSound20040426174410;
	
	if ( MuteSound == 1 )
	{
		this.SoundMode = 0;	// mute sound
	}
	else if ( LoopSound == 0 )
	{
		this.SoundMode = 1;	// play sound in boundry conditions
	}
	else
	{
		this.SoundMode = 2;	// loop sound
	}
	
	if (this.ObjEntryDelay == 0)
	{
		this.ObjAtStartup = this.MaxObj;
	}

	if (this.ObjEntryWidth == 0)
	{
		this.ObjEntryWidth = flpe_dispheight;
	}
		
	for ( i = 0 ; i < this.MaxObj ; i++ )
	{
		objname = this.name + "_" + i;
		if (flpe_ie4up)
		{
			document.write("<div id=\"" + objname +"\" style=\"POSITION: ");
			document.write("absolute; Z-INDEX: " + i +"; VISIBILITY: ");
			document.write("hidden; TOP: 15px; LEFT: 15px;\"><img src=\"");
			document.write(this.ImageArray[i%this.ImageCount]+ "\" name=\"img" + objname + "\" border=\"0\"></div>"); // ##ImageCount##
		}
		else if(flpe_ns4up)
		{
			document.write("<layer name=\"" + objname +"\" left=\"15\" ");
			document.write("top=\"15\" visibility=\"HIDDEN\"><img src=\"");
			document.write(this.ImageArray[i%this.ImageCount]+ "\" name=\"img" + objname + "\" border=\"0\"></layer>"); // ##ImageCount##
		} 
		else if(flpe_ns6up)
		{
			var elm;
			elm = document.createElement('img');
			elm.id = objname;
			elm.style.position = 'absolute';
			elm.src = this.ImageArray[i%this.ImageCount]; // ##ImageCount##
			elm.style.visibility = "hidden";
			elm.style.top = '15px';
			elm.style.left = '15px';
			elm.style.border = '0'
			document.body.appendChild ( elm );
		}
	}
	
	if (this.Effect == 3 || this.Effect == 6) //if the user has selected either top & bottom or left & right type of animation
	{
		for ( i = this.MaxObj ; i < this.MaxObj*2 ; i++ )
		{
			objname = this.name + "_" + i;
			if (flpe_ie4up)
			{
				document.write("<div id=\"" + objname +"\" style=\"POSITION: ");
				document.write("absolute; Z-INDEX: " + i +"; VISIBILITY: ");
				document.write("hidden; TOP: 15px; LEFT: 15px;\"><img src=\"");
				document.write(this.FlippedImgArray[i%this.ImageCount]+ "\" name=\"img" + objname + "\" border=\"0\"></div>"); // ##ImageCount##
			}
			else if(flpe_ns4up)
			{
				document.write("<layer name=\"" + objname +"\" left=\"15\" ");
				document.write("top=\"15\" visibility=\"HIDDEN\"><img src=\"");
				document.write(this.FlippedImgArray[i%this.ImageCount]+ "\" name=\"img" + objname + "\" border=\"0\"></layer>"); // ##ImageCount##
			}
			else if(flpe_ns6up)
			{
				var elm;
				elm = document.createElement('img');
				elm.id = objname;
				elm.style.position = 'absolute';
				elm.src = this.FlippedImgArray[i%this.ImageCount]; // ##ImageCount##
				elm.style.visibility = "hidden";
				elm.style.top = '15px';
				elm.style.left = '15px';
				elm.style.border = '0'
				document.body.appendChild ( elm );
			}
		}
	}
	
	this.Objects = new Array ();
	this.count = 0;
	
	for (i = 0; i < this.ObjAtStartup ; i++)
	{
		this.AddAnimationImage ();
	}

	this.timerCreateObject = setInterval(this.name + ".AddAnimationImage()", this.ObjEntryDelay);
	this.timerMoveObject = setInterval ( this.name + ".Move()", this.StepDelay );

	if (Timeout != 0)
	{
		setTimeout ( this.name + ".StopAnimation()", (Timeout * 60 * 1000) );
	}

	setTimeout ( this.name + ".InitSound()", 3000 );
	
	return this;
}

//Copyright 2002 - DPA Software
//All Rights Reserved
//http://www.frontlook.com/

function GetRandomPos20040426174410 ( w )
{
	var band = w / 10;
	var NewBand ;
	var Gap = 1;
	
	while (1)
	{
		NewBand = parseInt( (Math.random()*10), 10 );
		if (LastBand20040426174410 == -1)
		{
			break;
		}
		if (Math.abs(NewBand-LastBand20040426174410) > Gap )
		{
			break;
		}
	}
	
	LastBand20040426174410 = NewBand;
	return ((NewBand * band) + (Math.random()*band));
}

//Copyright 2002 - DPA Software
//All Rights Reserved
//http://www.frontlook.com/

function AnimationImage20040426174410 ( effect,ObjName, w, h, index, MaxObj, entrywidth )
{
	var ew, imgName;
	
	this.index = index;
	imgName = ObjName + "_" + index;

	if ( flpe_ie4up )
	{
		w -= document.all["img" +imgName].width
		h-= document.all["img" +imgName].height
	}
	else if ( flpe_ns4up )
	{
		w -= eval("document.img" + imgName).width;
		h -= eval("document.img" + imgName).height;
	}
	else if ( flpe_ns6up )
	{
		var elm = document.getElementById(imgName);
		w-= elm.width;
		h-= elm.height;
	}
	
	if (entrywidth == 0)
	{
		ew = h;	
	}
	else
	{
		ew = entrywidth;
	}
	
	var offset = (h - entrywidth) / 2;

	if (effect == 0)
	{
		// Bounded animation
		this.x = Math.round ( GetRandomPos20040426174410(w) );
		this.y = Math.round ( GetRandomPos20040426174410(h) );
		if (Math.random() >= 0.5)
		{
			this.dirX = -1;
			this.dirY = 1;
		}
		else
		{
			this.dirY = -1;
			this.dirX = 1;
		}
	}
	else if (effect == 1)
	{
		// Top animation
		this.dirX = 1;
		this.dirY = 1;
		this.x = GetRandomPos20040426174410 ( w );
		this.y = 0;
	}
	else if (effect == 2)
	{
		// Bottom animation
		this.dirX = 1;
		this.dirY = -1;
		this.x = GetRandomPos20040426174410 ( w );
		this.y = h;
	}
	else if (effect == 3)
	{
		// Top & Bottom animation
		if (Math.random() >= 0.5)
		{
			this.dirY = 1;
			this.y = 0;
		}
		else
		{
			this.dirY = -1;
			this.y = h;
			this.index += MaxObj;
		}
		this.dirX = 1
		this.x = GetRandomPos20040426174410 ( w );
	}
	else if (effect == 4)
	{
		// Left animation
		this.dirX = 1;
		this.dirY = 1;
		this.x = 0;
		this.y = GetRandomPos20040426174410(ew) + offset;
	}
	else if (effect == 5)
	{
		// Right animation
		this.dirX = -1;
		this.dirY = 1;
		this.x = w;
		this.y = GetRandomPos20040426174410(ew) + offset;
	}
	else if (effect == 6)
	{
		//Left & Right
		if (Math.random() >= 0.5)
		{
			this.dirX = 1;
			this.x = 0;
		}
		else
		{
			this.dirX = -1;
			this.x = w;
			this.index += MaxObj;
		}
		this.dirY = 1
		this.y = GetRandomPos20040426174410(ew) + offset;
	}

	return this;
}

//Copyright 2002 - DPA Software
//All Rights Reserved
//http://www.frontlook.com/

function AddAnimationImage20040426174410 ()
{
	var imgName;

	if ( this.count < this.MaxObj )
	{
		this.Objects[this.count] = new this.AnimationImage ( this.Effect,this.name, flpe_dispwidth, flpe_dispheight, this.count, this.MaxObj, this.ObjEntryWidth );

		imgName = this.name + "_" + this.Objects[this.count].index;
		if (flpe_ie4up)
		{
			document.all[imgName].style.visibility = "visible";
			document.all[imgName].style.pixelTop = this.Objects[this.count].y;
			document.all[imgName].style.pixelLeft = this.Objects[this.count].x;
			document.all[imgName].style.pixelWidth = document.all["img"+imgName].width;
			document.all[imgName].style.pixelHeight = document.all["img"+imgName].height;
		}
		else if (flpe_ns4up)
		{
			document.layers[imgName].visibility = "show";
			document.layers[imgName].top = this.Objects[this.count].y;
			document.layers[imgName].left = this.Objects[this.count].x;
		}
		else if(flpe_ns6up)
		{
			var elm = document.getElementById(imgName);
			elm.style.visibility = "visible";
			elm.style.top = this.Objects[this.count].y + 'px';
			elm.style.left = this.Objects[this.count].x + 'px';
		}
		this.count++;
	}
	else
	{
		clearInterval ( this.timerCreateObject );
	}
}

//Copyright 2002 - DPA Software
//All Rights Reserved
//http://www.frontlook.com/

function Move20040426174410 ()
{
	var boundry, oldDirX, oldDirY, obj, hideindex, imgName;
	var AnimWidth, AnimHeight, offset ;

	boundry = 0;
	for ( i = 0 ; i < this.Objects.length ; i++ )
	{
		obj = this.Objects[i];
		AnimWidth = flpe_dispwidth;
		AnimHeight = flpe_dispheight;
		
		imgName = this.name + "_" + obj.index;
		
		if (flpe_ie4up)
		{
			AnimWidth-=document.all["img" +imgName].width;
			AnimHeight-=document.all["img" +imgName].height;
		}
		else if (flpe_ns4up)
		{
			AnimWidth -= eval("document.img" + imgName).width;
			AnimHeight -= eval("document.img" + imgName).height;
		}
		else if(flpe_ns6up)
		{
			var elm = document.getElementById(imgName);
			AnimWidth-= elm.width;
			AnimHeight-= elm.height;
		}
		
		AnimWidth-= 1;
		AnimHeight-= 1;
		offset = (AnimHeight - this.ObjEntryWidth) / 2;
		hideindex = -1;

		if (this.Effect == 0)
		{
			// Bounded animation
			oldDirX = obj.dirX;
			oldDirY = obj.dirY;
			if (obj.x >= AnimWidth)
				obj.dirX = -1;
			else if (obj.x <= 0)
				obj.dirX = 1;
			if (obj.y >= AnimHeight)
				obj.dirY = -1;
			else if (obj.y <= 0)
				obj.dirY = 1;
			if ( oldDirX != obj.dirX || oldDirY != obj.dirY )
			{
				boundry = 1
			}
			obj.y = obj.y + (obj.dirY * (((Math.random() * this.Variation) + this.Variation/2) + this.Displacement));
			obj.x = obj.x + (obj.dirX * (((Math.random() * this.Variation) + this.Variation/2) + this.Displacement));

		}
		else if (this.Effect == 1 || this.Effect == 2 || this.Effect == 3)
		{
			obj.x = obj.x + (Math.random() * this.Variation) - this.Variation/2;
			obj.y = obj.y + (obj.dirY * ((Math.random() * (this.Variation/2)) + this.Displacement));

			if (obj.dirY == 1)
			{
				if (obj.y > AnimHeight)
				{
					if(this.Effect == 3)
					{
						if (Math.random() >= 0.5)
						{
							obj.dirY = 1;
							obj.y = 0;
						}
						else
						{
							obj.dirY = -1;
							obj.y = AnimHeight;
							hideindex = obj.index;
							obj.index += this.MaxObj;
						}
						obj.dirX = 1;
					}
					else
					{
						obj.y = 0;
					}
					boundry = 1;
					obj.x = GetRandomPos20040426174410 ( AnimWidth );
				}
			}
			else if(obj.dirY == -1)
			{
				if (obj.y <= 0)
				{
					if(this.Effect == 3)
					{
						if (Math.random() >= 0.5)
						{
							obj.dirY = 1;
							obj.y = 0;
							hideindex = obj.index;
							obj.index -= this.MaxObj;
						}
						else
						{
							obj.dirY = -1;
							obj.y = AnimHeight;
						}
						obj.dirX = 1
					}
					else
					{
						obj.y = AnimHeight;
					}
					boundry = 1;
					obj.x = GetRandomPos20040426174410 ( AnimWidth );
				}
			}

		}
		else if (this.Effect == 4 || this.Effect == 5 || this.Effect == 6)
		{
			// Left Animation,Right animation,Left-Right animation
			obj.y = obj.y + (Math.random() * this.Variation) - this.Variation/2;
			obj.x = obj.x + (obj.dirX * ((Math.random() * (this.Variation/2)) + this.Displacement));
			if (obj.dirX == 1)
			{
				if (obj.x > AnimWidth)
				{
					if(this.Effect == 6)
					{
						if (Math.random() >= 0.5)
						{
							obj.dirX = 1;
							obj.x = 0;
						}
						else
						{
							obj.dirX = -1;
							obj.x = AnimWidth;
							hideindex = obj.index;
							obj.index += this.MaxObj;
						}
						obj.dirY = 1
					}
					else
					{
						obj.x = 0;
					}
					boundry = 1;
					obj.y = GetRandomPos20040426174410(this.ObjEntryWidth) + offset;
				}
			}
			else if(obj.dirX == -1)
			{
				if (obj.x <= 0)
				{
					if(this.Effect == 6)
					{
						if (Math.random() >= 0.5)
						{
							obj.dirX = 1;
							obj.x = 0;
							hideindex = obj.index;
							obj.index -= this.MaxObj;
						}
						else
						{
							obj.dirX = -1;
							obj.x = AnimWidth;
						}
						obj.dirY = 1;
					}
					else
					{
						obj.x = AnimWidth;
					}
					boundry = 1;
					obj.y = GetRandomPos20040426174410(this.ObjEntryWidth) + offset;
				}
			}
		}

		if ( boundry == 1 )
		{
			boundry = 0;
		}

		imgName = this.name + "_" + obj.index;
		
		if(obj.x > AnimWidth)
		{
			 obj.x= AnimWidth;
		}			
		
		if(obj.y > AnimHeight)
		{
			 obj.y= AnimHeight;
		}			

		if (flpe_ie4up)
		{
			document.all[imgName].style.pixelTop = obj.y;
			document.all[imgName].style.pixelLeft = obj.x;
			if(hideindex != -1)
			{
				document.all[imgName].style.visibility = "visible";
				document.all[this.name + "_" + hideindex].style.visibility = "hidden";
			}
		}
		else if (flpe_ns4up)
		{
			document.layers[imgName].top = obj.y;
			document.layers[imgName].left = obj.x;

			if(hideindex != -1)
			{
				document.layers[imgName].visibility = "Show";
				document.layers[this.name + "_" + hideindex].visibility = "HIDDEN";
			}
		}
		else if(flpe_ns6up)
		{
			var elm = document.getElementById(imgName);
			elm.style.top = obj.y + 'px';
			elm.style.left = obj.x + 'px';
			if(hideindex != -1)
			{
				elm.style.visibility = "visible";
				document.getElementById(this.name + "_" + hideindex).style.visibility = "hidden";
			}
		}
	}
}

//Copyright 2002 - DPA Software
//All Rights Reserved
//http://www.frontlook.com/

function StopAnimation20040426174410 ()
{
	var imgname;
	
	clearInterval ( this.timerCreateObject );
	clearInterval ( this.timerMoveObject );
	for ( var i = 0 ; i < this.Objects.length ; i++ )
	{
		imgname = this.name + "_" + this.Objects[i].index;
		if (flpe_ie4up)
			document.all[imgname].style.visibility = "hidden";
		else if (flpe_ns4up)
			document.layers[imgname].visibility = "HIDDEN";
		else if(flpe_ns6up)
			document.getElementById(imgname).style.visibility = "hidden";
	}
	if ( this.SoundMode == 2 )
	{
		document.applets[this.AudioApplet].StopAudio();
	}
}

//Copyright 2002 - DPA Software
//All Rights Reserved
//http://www.frontlook.com/

function InitSound20040426174410()
{
	if ( document.applets[this.AudioApplet] )
	{
		if ( this.SoundMode != 0 )
		{
			//document.applets[this.AudioApplet].SetAudioFile ( this.SoundFile );
		}

		if ( this.SoundMode == 1 )
		{
			document.applets[this.AudioApplet].PlayAudio ();
		}
		
		if ( this.SoundMode == 2 )
		{
			document.applets[this.AudioApplet].LoopAudio();
		}
	}
}

