/***********************************************
* This script is mash of two scripts on Dynamic Drive by Nicholas Murray
* Based on:
* Fading Scroller- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* And:
* Gradual Element Fader- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use
* Version 2 5/2011 - preload images.
***********************************************/

var delay = 3500; //set delay between message change (in miliseconds)
var maxSteps=50; // number of steps to take to change from start color to endcolor
var stepDelay=30; // time in miliseconds of a single step
//**Note: maxsteps*stepdelay will be total time in miliseconds of fading effect
var startOpacity = 0;    // 0 = totally transparent
var endOpacity  = 1.0;    // 1 = not opacic



//These two lines do the Random header images  
  var randomNum=Math.floor(Math.random()*4)
  var imgLocation = "img/theme/ABCHeader"+randomNum+".jpg";
  document.getElementById("header").style.backgroundImage="url("+imgLocation+")" ;

///No need to edit below this line/////////////////
 

var index = 0;
var step = 0;

var images = new Array();

function bgFullHeight(){         
   if(!isIE())
   {    
        if( document.getElementById('pagewidth').offsetHeight   < window.innerHeight)
          document.getElementById('pagewidth').style.height = window.innerHeight + 'px';
   }   
   //can't be bothered fixing for IE.
} 


function afterLoad()
{  
images[0] = "img/s/blokart.png"
images[1] = "img/s/bunnings.png"
images[2] = "img/s/tyres.jpg"
images[3] = "img/s/flame.jpg"
images[4] = "img/s/ecc.png"

var preloadImg = new Image();

       var i = 0;
       for(i=0; i<=images.length; i++) 
         preloadImg.src = images[i];
        
      bgFullHeight();

   document.getElementById('support').style.visibility = 'visible';      
   sequence();      
}
  

/*Nicholas Murray created this function
/ it is more obvious how it works than the fading scroller. But probaly not as verbose*/
function sequence()  
{
 var targetDivObj =   document.getElementById("support");
 var opacity;
 if( step == 0)
 {
 //change content
 changecontent(targetDivObj);
 setTimeout("sequence()", stepDelay);
 }
 else if ( step == maxSteps)
 {     //totally faded in
  setOpacity(targetDivObj, endOpacity);
  setTimeout("sequence()", delay);
 // return; //comment out to enable script image swapping
 }
 else if ( step > maxSteps)
 {    //display time done. Set maxSteps negative to start fade out.

  step = -maxSteps;
  setTimeout("sequence()", stepDelay);
 }
 else
 {  //calc & apply opacity transistion effect.
  opacity = startOpacity + ((Math.abs(step)/maxSteps)*(endOpacity-startOpacity));  //% progress of steps * difference in opacity added to start Opacity. 
  setOpacity(targetDivObj, opacity );
  setTimeout("sequence()", stepDelay);
 }
 step++;
}
  

//function to change content
function changecontent(obj){
 var targetDivObj = obj;  
    var imgDest = document.getElementById('supImg');
  	imgDest.setAttribute("src", images[index]);
    obj = document.getElementById('psb');
obj.setAttribute("height", "20px");
 
    index++;
    if (index>=images.length)
    {
     index=0;
    }
 
  
}
 
function setOpacity(obj, value){ //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)
	var targetobject=obj;
	if (targetobject && targetobject.filters && targetobject.filters[0]){ //IE syntax
		if (typeof targetobject.filters[0].opacity=="number") //IE6
			targetobject.filters[0].opacity=value*100;
		else //IE 5.5
			targetobject.style.filter="alpha(opacity="+value*100+")"
		}
	else if (targetobject && typeof targetobject.style.MozOpacity!="undefined") //Old Mozilla syntax
		targetobject.style.MozOpacity=value;
	else if (targetobject && typeof targetobject.style.opacity!="undefined") //Standard opacity syntax
		targetobject.style.opacity=value;
	targetobject.currentopacity=value;
}

//break out of iframes for easy link posting in blog.
if (top.location!=self.location)
{
  top.location = self.location.href;
}

function isIE()
{
 return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

/*stuff to do now - else do after page load in afterLoad()*/
document.getElementById("support").style.visibility = 'hidden';


if (window.addEventListener)
window.addEventListener("load", afterLoad, false)
else if (window.attachEvent)
window.attachEvent("onload", afterLoad)
else if (document.getElementById)
window.onload=afterLoad;

window.onresize = function() {
bgFullHeight();

}



