// JavaScript Document
function objCustImage(aImg,aContainer,aIndex,aStartDelay)
{
	this.Container = aContainer;
	this.Index = aIndex;
	this.ElemImage = aImg;
	this.Opacity = 100; //percent  0 - 100
	this.StartDelay = aStartDelay;
	this.FadeOutPercent = 3;
	this.FadeOutInterval = 30;		
	this.FadeInPercent = 3;
	this.FadeInInterval = 30;				
	this.RepeatDelay = 8000;
	this.Status = "FadeOut"
	this.photoNumber = 0;
	
	this.SetOpacity = SetOpacity;
	function SetOpacity()
	{
		//Function to handel opcity for cross-browser copatiblity	
		
				// IE/Win
			this.ElemImage.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+ this.Opacity + ");";
		
			// Safari<1.2, Konqueror
			this.ElemImage.style.KHTMLOpacity = this.Opacity/100;
		
			// Older Mozilla and Firefox
			this.ElemImage.style.MozOpacity = this.Opacity/100;
		
			// Safari 1.2, newer Firefox and Mozilla, CSS3
			this.ElemImage.style.opacity = this.Opacity/100;
	}
	
	this.SetNewPhoto = SetNewPhoto;
	function SetNewPhoto()
	{
		PhotoCount = this.Container.Photos.length;
		ImageCount = this.Container.Images.length;
		if (PhotoCount > 0)
		{
			if (PhotoCount > 1)
			{
				found = true
				while (found == true)
				{
					found = false;
					photoNumber = Math.floor(PhotoCount * Math.random());
					for (i = 0; i < ImageCount; i++)
					{
						if (this.Container.Images[i].photoNumber == photoNumber)
							found = true
					}
				}
			}
			else
				photoNumber = 0;
			
			this.ElemImage.src = this.Container.Photos[photoNumber].src;
			this.photoNumber = photoNumber;
		}			
	}
	
	this.FadeOut = FadeOut;
	function FadeOut()
	{
		if (this.Opacity < 0)
		{
			return true;
		}			
		this.Opacity = this.Opacity - this.FadeOutPercent			
		this.SetOpacity();
		return false;
	}

	this.FadeIn = FadeIn;
	function FadeIn(AFadePercent)
	{
		if (this.Opacity > 100)
		{
			return true;;
		}				
		this.Opacity = this.Opacity + this.FadeInPercent;
		this.SetOpacity();
		return false;
	}
	
	this.AnimateImage = AnimateImage;
	function AnimateImage()
	{
		ContainerInstanceName = this.Container.InstanceName;
		if (this.StartDelay > 0)
		{
			setTimeout(ContainerInstanceName+".Images["+this.Index+"].AnimateImage()",this.StartDelay);
			this.StartDelay = 0;
			return;
		}
		
		
		//FadeOut
		if (this.Status == "FadeOut")
			if (this.FadeOut())
				this.Status = "SetNewPhoto";
			else
			{
				setTimeout(ContainerInstanceName+".Images["+this.Index+"].AnimateImage()",this.FadeOutInterval);
				return;
			}


		//Change Photo
		if (this.Status == "SetNewPhoto")
		{
			this.SetNewPhoto();
			this.Status = "FadeIn";
		}

		//FadeIn
		if (this.Status == "FadeIn")
			if (this.FadeIn())
			{
				this.Status = "FadeOut";
				setTimeout(ContainerInstanceName+".Images["+this.Index+"].AnimateImage()",this.RepeatDelay);
				return;
			}
			else
			{
				setTimeout(ContainerInstanceName+".Images["+this.Index+"].AnimateImage()",this.FadeInInterval);				
				return;
			}
	} //AnimateImage

	this.AnimateImage = AnimateImage2;
	function AnimateImage2()
	{
		ContainerInstanceName = this.Container.InstanceName;
		if (this.StartDelay > 0)
		{
			setTimeout(ContainerInstanceName+".Images["+this.Index+"].AnimateImage()",this.StartDelay);
			this.StartDelay = 0;
			return;
		}
		
		
		//FadeOut
		if (this.Status == "FadeOut")
			if (this.FadeOut())
				this.Status = "SetNewPhoto";
			else
			{
				setTimeout(ContainerInstanceName+".Images["+this.Index+"].AnimateImage()",this.FadeOutInterval);
				return;
			}


		//Change Photo
		if (this.Status == "SetNewPhoto")
		{
			this.SetNewPhoto();
			this.Status = "FadeIn";
		}

		//FadeIn
		if (this.Status == "FadeIn")
			if (this.FadeIn())
			{
				this.Status = "FadeOut";
				setTimeout(ContainerInstanceName+".Images["+this.Index+"].AnimateImage()",this.RepeatDelay);
				return;
			}
			else
			{
				setTimeout(ContainerInstanceName+".Images["+this.Index+"].AnimateImage()",this.FadeInInterval);				
				return;
			}
	} //AnimateImage2


}



function objImagesBanner(APhotos,aInstanceName)
{	
	this.InstanceName = aInstanceName;
	this.Images = new Array();	
	this.Photos = APhotos;
		
	this.AddImage = AddImage;
	function AddImage(aImgId,aStartDelay)
	{
		Index = this.Images.length;
		this.Images[Index] = new objCustImage(document.getElementById(aImgId),this,Index,aStartDelay);
		this.Images[Index].SetNewPhoto();
	}
	
	this.StartAnimation = StartAnimation;
	function StartAnimation()
	{
		ImagesCounr = this.Images.length;
		for (i = 0; i < ImagesCounr; i++)
		{
			this.Images[i].AnimateImage();
		}
	}//StartAnimation

	this.StartAnimation2 = StartAnimation2;
	function StartAnimation2()
	{
		ImagesCounr = this.Images.length;
		for (i = 0; i < ImagesCounr; i++)
		{
			this.Images[i].AnimateImage2();
		}
	}//StartAnimation2


}