// image rotation function for the green tips banner

function init(){
	
	
	increment=1;
	
	banners = Array('green_tip1.jpg','green_tip2.jpg','green_tip3.jpg','green_tip4.jpg','green_tip5.jpg');
	
	
	//randomise the array to avoid repetition
	var i = banners.length;
	  if ( i == 0 ) return false;
	  while ( --i ) {
		 var j = Math.floor( Math.random() * ( i + 1 ) );
		 var tempi = banners[i];
		 var tempj = banners[j];
		 banners[i] = tempj;
		 banners[j] = tempi;
	   }
	   
	//write in the image tag
	
	greenTip();
	
	//start the interval for the rotation
	
	rotation = setInterval("rotateTip()",5000);
	
	
	
}



function greenTip(){
	
	//writes in the banner
	if(!document.write) return false;
	html = '<img src="../images/'+banners[0]+'" id="greenTipBanner" alt="Green tips" />';
	
	document.write(html);
	
	
}


function rotateTip(){
	
	
	//rotate the image banner to the next image in the array
	
	//if the end of the array has been reached rotate back to the first
	if(increment>(banners.length-1)) increment=0;
	
	if(!document.getElementById) return false;	
	if(!document.getElementById('greenTipBanner')) return false;	
	
	var imageRef = document.getElementById('greenTipBanner');
	
	imageRef.setAttribute("src",'../images/'+banners[increment]);
		
	increment++;
}


init();