// JavaScript Document
/*************************************************\
Crossfade images with ids element and element2
XFade takes 1 second in 20 steps
This could be changed in the Xfade function
There is a 5 second wait between xfades, set in the fade function where the recursive timeout call is made
\*************************************************/

/*function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
	
MM_preloadImages('');*/

/**********************************************************\

	EDIT HERE

\*********************************************************/

var hold=5000 // the time between transitions (milliseconds)
var id1='bannerimage' // the id of the initial image
var id2='swapimage' // the id of the other image
var a_image=new Array('display.jpg', 'linda-senior.jpg', 'scout-manplustwo.jpg', 'steps2.jpg', 'tania-sue-carol.jpg', 'tanya-steps.jpg', 'three-steps-women.jpg') // the images
var a_title=new Array('People showing their awards', 'Linda Williams and a friend at the STEPS awards', 'People talking over a cuppa at an Alliance Coffee morning', '', '', '', '') // alts and titles for the images
var ptdir="assets/image/layout/banners/" // the path to the images
var highOp=1 // highest level opacity 1=opaque 0=transparent
var lowOp=0 // 
var transTime=1 // transition time (seconds)
var smoothness=20 // number of steps to change in

/**********************************************************\

	LEAVE ALONE AFTER HERE

\*********************************************************/
var wait=0
var inc=transTime/smoothness
var frameTime=inc*1000
var ua=navigator.userAgent;
var version=get_IE_version();
if(version>5.5){
			highOp=highOp*100
			lowOp=lowOp*100
			inc=inc*100
	}
var div_opacities=new Array();
var div_timers=new Array();
var slidemax=a_image.length-1
var nCurrentSlide=0

// ****************************	
// Browser version
// ****************************

function init_slides(){
setTimeout(nextSlide, hold)
}

function get_IE_version(){
	var offset=ua.indexOf("MSIE ");
	return parseFloat(ua.substring(offset+5, ua.indexOf(";", offset)));	
	}
	

function fade(d, startOp, endOp, inc){
		if(typeof(div_opacities[d])=='undefined') div_opacities[d]=startOp
		
		if(endOp>startOp){
				div_opacities[d]+=inc;
				if(div_opacities[d]>endOp){
					clearInterval(div_timers[d])
					clearTimeout(wait)
					wait=setTimeout(nextSlide, hold)
				}else{
						if(version>5.5){
								inc_fade_ie(d);
						}else{
								inc_fade_ff(d);
							}
					}
		}else{
				div_opacities[d]=div_opacities[d]-inc;//changed
				if(div_opacities[d]<(endOp-inc)){// changed
					clearInterval(div_timers[d])
					clearTimeout(wait)
					wait=setTimeout(nextSlide, hold)
					/*div_opacities[d]=endOp*/
				}else{
						if(version>5.5){
								inc_fade_ie(d);
						}else{
								inc_fade_ff(d);
							}
					}
		}
}

function inc_fade_ff(d){
	document.getElementById(d).style.opacity=div_opacities[d];
	}
	
function inc_fade_ie(d){	
	document.getElementById(d).style.filter ="progid:DXImageTransform.Microsoft.Alpha(opacity="+div_opacities[d]+")"
}


function xFade(nC){
		obj1=document.getElementById(id1)
		obj2=document.getElementById(id2)
		if(version>5.5){
				startOp1=obj1.filters.item("DXImageTransform.Microsoft.Alpha").Opacity
				startOp2=obj2.filters.item("DXImageTransform.Microsoft.Alpha").Opacity			
		}else{
				var style1 = document.defaultView.getComputedStyle(obj1, '');	
				var style2 = document.defaultView.getComputedStyle(obj2, '');	
				startOp1=style1.opacity
				startOp2=style2.opacity		
		}

		if(startOp1>startOp2){
							obj2.src=ptdir+a_image[nC]
							obj2.title=a_title[nC]
							obj2.alt=a_title[nC]								
							div_timers[id1]=setInterval("fade('"+id1+"', "+highOp+", "+lowOp+", "+inc+")", frameTime);
							div_timers[id2]=setInterval("fade('"+id2+"', "+lowOp+", "+highOp+", "+inc+")", frameTime);
		}else{
							obj1.src=ptdir+a_image[nC]
							obj2.title=a_title[nC]
							obj2.alt=a_title[nC]								
							div_timers[id1]=setInterval("fade('"+id1+"', "+lowOp+", "+highOp+", "+inc+")", frameTime);
							div_timers[id2]=setInterval("fade('"+id2+"', "+highOp+", "+lowOp+", "+inc+")", frameTime);						
			}
	}


/*************************

		SLIDE SWAP
		
**********************************/

function nextSlide(){
		nCurrentSlide++
		if(nCurrentSlide>slidemax) nCurrentSlide=0	
		xFade(nCurrentSlide)
}





