// JavaScript Document


//home page functions
function SetAnimationImages(page)
{
	var lRotator = new Rotator();
	
	if (page == 'home')
		{
			lRotator.Images = new Array("images/animation/home/00_home_ani1.jpg","images/animation/home/00_home_ani2.jpg","images/animation/home/00_home_ani3.jpg","images/animation/home/00_home_ani4.jpg","images/animation/home/00_home_ani5.jpg","images/animation/home/00_home_ani6.jpg","images/animation/home/00_home_ani7.jpg","images/animation/home/00_home_ani8.jpg","images/animation/home/00_home_ani9.jpg","images/animation/home/00_home_ani10.jpg","images/animation/home/00_home_ani11.jpg","images/animation/home/00_home_ani12.jpg");
			
		}
	
	if (page == 'nz')
		{
			lRotator.Images = new Array("images/animation/nz/01_nz_ani1.jpg","images/animation/nz/01_nz_ani2.jpg","images/animation/nz/01_nz_ani3.jpg","images/animation/nz/01_nz_ani4.jpg");
		}
	
	if (page == 'australian')
		{
			lRotator.Images = new Array("images/animation/australia/02_aus_ani1.jpg","images/animation/australia/02_aus_ani2.jpg","images/animation/australia/02_aus_ani3.jpg","images/animation/australia/02_aus_ani4.jpg");
		}
	
	if (page == 'online')
		{
			lRotator.Images = new Array("images/animation/online/03_online_ani1.jpg","images/animation/online/03_online_ani2.jpg","images/animation/online/03_online_ani3.jpg","images/animation/online/03_online_ani4.jpg","images/animation/online/03_online_ani5.jpg");
		}
	
	if (page == 'radio')
		{
			lRotator.Images = new Array("images/animation/radio/04_radio_ani1.jpg","images/animation/radio/04_radio_ani2.jpg","images/animation/radio/04_radio_ani3.jpg","images/animation/radio/04_radio_ani4.jpg","images/animation/radio/04_radio_ani5.jpg","images/animation/radio/04_radio_ani6.jpg");
		}
		
    if (page == 'outdoor')
		{
			lRotator.Images = new Array("images/animation/outdoor/image1.jpg","images/animation/outdoor/image2.jpg","images/animation/outdoor/image3.jpg","images/animation/outdoor/image4.jpg","images/animation/outdoor/image5.jpg","images/animation/outdoor/image6.jpg");
		}	
		
	if (page == 'test')
		{
			lRotator.Images = new Array("images/animation/image3.jpg","images/animation/image4.jpg","images/animation/image1.jpg","images/animation/image2.jpg");
		}
		
		if (page == 'home')
		{
		
		lRotator.ImageElementId = "imgAnimation";
	    lRotator.RotateBackGround = true;
	    lRotator.BackgroundElementId = "divRightAnimationHomePage";
	    lRotator.MaxLoop = 0;
	    lRotator.FadeImages = true;
	    lRotator.OpacityIncSpeed = 50;
	    lRotator.OpacityPause100 = 100;
	    lRotator.OpacityPause0 = 100;
	    lRotator.OpacityInc = 2;
	    lRotator.Start();
		
		}
		
		else
		{
		
 	    lRotator.ImageElementId = "imgAnimation";
	    lRotator.RotateBackGround = true;
	    lRotator.BackgroundElementId = "divRightPages";
	    lRotator.MaxLoop = 0;
	    lRotator.FadeImages = true;
	    lRotator.OpacityIncSpeed = 50;
	    lRotator.OpacityPause100 = 100;
	    lRotator.OpacityPause0 = 100;
	    lRotator.OpacityInc = 2;
	    lRotator.Start();
	    
	    }
	
	var lAnimate = new Animator();
	lAnimate.ElementId = "divAnimationPanel1";
	lAnimate.Left = 0;
	lAnimate.LeftMin = 0;
	lAnimate.LeftMax = 295;
	lAnimate.Fade = true;
	lAnimate.FadeLeft = false;
	lAnimate.OpacityMin = 35;
	lAnimate.OpacityMax = 75;
	lAnimate.Start();

	var lAnimate = new Animator();
	lAnimate.ElementId = "divAnimationPanel2";
	lAnimate.Left = 120;
	lAnimate.LeftInc = -5;
	lAnimate.LeftMin = 0;
	lAnimate.LeftMax = 335;
	lAnimate.Fade = true;
	lAnimate.FadeLeft = true;
	lAnimate.OpacityMin = 35;
	lAnimate.OpacityMax = 75;
	lAnimate.Start();

	var lAnimate = new Animator();
	lAnimate.ElementId = "divAnimationPanel3";
	lAnimate.Left = 220;
	lAnimate.LeftInc = -5;
	lAnimate.LeftMin = 0;
	lAnimate.LeftMax = 275;
	lAnimate.LeftIncSpeed = 75;
	lAnimate.Fade = true;
	lAnimate.FadeLeft = true;
	lAnimate.OpacityMin = 15;
	lAnimate.OpacityMax = 50;
	lAnimate.Start();

	var lAnimate = new Animator();
	lAnimate.ElementId = "divAnimationPanel4";
	lAnimate.Left = 345;
	lAnimate.LeftInc = -5;
	lAnimate.LeftMin = 0;
	lAnimate.LeftMax = 345;
	lAnimate.Fade = true;
	lAnimate.FadeLeft = true;
	lAnimate.OpacityMin = 35;
	lAnimate.OpacityMax = 75;
	lAnimate.Start();
	
	

}


//this class animates an element
function Animator() 
{
	//variables
	var me = this;
	this.ElementId = '';	//the html id of the object to rotate
	this.Element = null;
	this.Fade = true;	//if true the elements will fade in and out.
	this.FadeLeft = false;	//if true the elements will fade out to the left.
	this.Opacity = 0;	//the current element opactity
	this.OpacityMin = 0; //the minimum opacity
	this.OpacityMax = 100; //the maximum opacity
	this.MoveTimeOutID = 0;
	this.MaxLoop = 0;	//the maximum number of loops to do. If 0 then loops will be continuous
	this.LoopCount = -1; 	//the number of loops completed
	this.Left = 0;	//the current element left value
	this.LeftInc = 5;	//The amount to increment left by.
	this.LeftIncSpeed = 50; //the speed in which left is incremented in milliseconds
	this.LeftMin = 0;	//the minimum left value
	this.LeftMax = 0;	//the minimum left value
	
	//methods
	
	//starts animation 
	this.Start = function()
	{
		//add this class instance ID to the scope array - use page element Id as this should be unique
		globalScope[ me.ElementId ] = this;
		
		//get page element
		me.Element = document.getElementById(me.ElementId);
		
		//check minimum value
		if (me.OpacityMin < 0)
		{
			me.OpacityMin = 0;
		}
		
		//check maximum value
		if (me.Opacity > 100)
		{
			me.OpacityMax = 100;
		}

		//start image rotation
		me.Animate();
		
	}
	
	//stops animation
	this.Stop = function()
	{
		clearTimeout(me.MoveTimeOutID);
	}
	
	//animates the elements
	this.Animate = function()
	{
		//count loops
		me.LoopCount += 1;
		
		//check if we have passed max loop count
		if (me.MaxLoop != 0)
		{
			if (me.MaxLoop <= me.LoopCount)
			{
				me.Stop();
				return;
			}
		}
		
		//move and fade the element
		me.MoveElement(me.LeftIncSpeed);
		if (me.Fade)
		{
			me.SetOpacity();
		}
	}

	//moves the element
	this.MoveElement = function(MoveSpeed)
	{
	    //get left
	    me.Left += me.LeftInc;
	    if (me.Left <= me.LeftMin)
	    {
	        me.Left = me.LeftMin;
	        me.LeftInc *= -1;
	    }
	    if (me.Left >= me.LeftMax)
	    {
	        me.Left = me.LeftMax;
	        me.LeftInc *= -1;
	    }
	    me.Element.style.left = me.Left + 'px';
	    
		//animate the element
		me.MoveTimeOutID = setTimeout( 'IntervalHandler("' + me.ElementId + '","Animate()")', MoveSpeed );
		
		return;
	}
	
	
	//sets opacity
	this.SetOpacity = function()
	{
        //get opacity
        if (me.FadeLeft)
        {
		    me.Opacity = ((me.Left - me.LeftMin)/(me.LeftMax - me.LeftMin))*(me.OpacityMax - me.OpacityMin) + me.OpacityMin;
		}
		else
		{
		    me.Opacity = me.OpacityMax - ((me.Left - me.LeftMin)/(me.LeftMax - me.LeftMin))*(me.OpacityMax - me.OpacityMin);
		}
		
		//check minimum value
		if (me.Opacity < me.OpacityMin)
		{
			me.Opacity = me.OpacityMin;
		}
		
		//check maximum value
		if (me.Opacity > me.OpacityMax)
		{
			me.Opacity = me.OpacityMax;
		}
		
		// IE/Win
		me.Element.style.filter = "alpha(opacity:" + me.Opacity + ")";
		
		// Safari<1.2, Konqueror
		me.Element.style.KHTMLOpacity = me.Opacity/100;
		
		// Older Mozilla and Firefox
		me.Element.style.MozOpacity = me.Opacity/100;
		
		// Safari 1.2, newer Firefox and Mozilla, CSS3
		me.Element.style.opacity = me.Opacity/100;
		
	}

}