//boolean: whether or not we are fading

var doingFade = true;   	
//use as a handle on the timeout loop  

var timeout;   
	
//variable to hold global opactiy          

var globalOpacity = 0;  
	
var imageNames = "01.jpg 02.jpg 03.jpg 04.jpg 05.jpg 07.jpg 08.jpg 09.jpg 10.jpg 11.jpg 12.jpg 13.jpg 14.jpg 15.jpg 16.jpg 17.jpg 18.jpg 19.jpg 20.jpg 21.jpg 22.jpg".split(" ");
	
//next image index to be faded

var indexValue = Math.floor(Math.random() *imageNames.length-1)+1;
	
//variables for container/controller/target

var containerID = 'fader';

var targetID    = 'fadertarget';

var container   = null;

var target      = null;

function preload()
{

if (document.images)
	{
	   var preload = new Array();
	  //pic1.src="/images/header/01.jpg"; 
	  for (ind = 0; ind < imageNames.length; ind++)
	  {
		  preload[ind] = new Image(800,130);
		  preload[ind].src = myURL + '/au/images/header/' + imageNames[ind] + '';
		  //alert('Just Loaded: ' + preload[ind].src);
	  }
	}


}

function setalpha(opacity) 
    {
      if (document.getElementById ) 
      {    
        //fade next step based onbrowser compatibility
		opacity = (opacity == 100)?99.999:opacity;
        /*if (target.style.MozOpacity!=null) {
           target.style.MozOpacity = (opacity/100);
        } else */if (target.style.opacity!=null) {
           target.style.opacity = opacity/100;
        } else if (target.style.filter!=null) {
           target.style.filter = "alpha(opacity=" + opacity + ")";
    	} else if (target.style.KhtmlOpacity!=null) {
           target.style.KhtmlOpacity = opacity/100;
    	}
      }
    }    

function startPhoto()
{
	if (!document.getElementById) return;	
	
	//set references to container && target ** a href    
	container = document.getElementById(containerID);
	target = document.getElementById(targetID);
		
	setalpha(0) ;
	timeout = window.setTimeout("nextPhoto()", 500);
}

function nextPhoto() 

{
	if (!document.getElementById) return; 
	
	// only one transition at a time, please
	clearTimeout(timeout); 
	
	//flip image and container
	switchContainer();    
	
	//load next image   
	target.src = '/au/images/header/'+imageNames[indexValue];
	
	//get new index differnet from current
	var newvalue = indexValue;
	while(newvalue == indexValue)
	{
		newvalue = Math.floor(Math.random()* imageNames.length);
	}
	indexValue = newvalue;
	//fade image in
	timeout = window.setTimeout("reveal('0')", 300);
	
}

function switchContainer()
{
	if (!document.getElementById) return;
	
	//make container background current image
	container.style.backgroundImage = 'url(' + target.src + ')'; 
	
	//make image 0
	setalpha(0) ;
}

function reveal(opacity) 

{
  if (!document.getElementById) return;


  if (document.getElementById && opacity <= 100 ) 
  {
	setalpha(opacity); 
	opacity += 5;
	
	//store globally fo restart
	globalOpacity = opacity;
	
	//fade next step
	timeout = window.setTimeout("reveal("+opacity+")", 100);
  }
  else
  {
	//we are done .. load next photo in 5 seconds
	timeout = window.setTimeout("nextPhoto()", 3000);
	
	switchContainer();
  }
}

function addEvent(obj, evType, fn)
    { 
        if (obj.addEventListener)
        { 
            obj.addEventListener(evType, fn, true); 
            return true; 
        } 
        else if (obj.attachEvent)
        { 
            var r = obj.attachEvent("on"+evType, fn); 
            return r; 
        } 
        else 
        { 
            return false; 
        } 
    }  
