
jQuery(function($) { // maybe change to doc ready?

// fading vars -------------------------------------------------

var ImageArray = []; // array to hold the src of the backgroun img

var ImageArragEnd = ImageArray.length;

var BannerLable = 0; // use to lable everything

var counter = 0; // counts were the banner is upto

var BGcounter = 0; // counts were the banner background src is upto

var timer; // timer val

// -- start functions ------------------------------------------     

//fading labler
$("#fader").children().each(function(){ // lables everything and add to array so can be use for fading. 
	var BannerSRC = $(this).children().attr("src"); 
	BannerLable ++; // jsut a counter for the class adder
	$(this).addClass("image"+ BannerLable +""); // adds class like "image1", "image2"
	ImageArray.push(BannerSRC) // push then 
	ImageArragEnd = ImageArray.length; // updating the array

});
     

// test to see if there is 1 or more images ---------------------
if(ImageArragEnd == 1){ 
	//do nothing!
	}else{
	fadingFun(); // start the banner fade
	$("#fader").children().fadeOut(0); // hides all of the slides
}


// fading FUNction -----------------------------------------------
function fadingFun(){ 

ImageArragEnd = (ImageArray.length) + 1; //UPDAT PUT BOTH INTO A FUCNTION as a call back of each....

	 counter ++;
	 BGcounter ++;
	 if(counter == ImageArragEnd ){  // check were its upto in the line and if its the last one then *restart*
		counter = 1;
	 }
	 if(BGcounter == [ImageArragEnd -1]){  // check were its upto in the line and if its the last one then *restart*
		BGcounter = 0;
	 }
	 $("#fader").css("background-image","url("+ ImageArray[BGcounter] +")");	// get this working
	 $("#fader").children().fadeOut(0), // restarter 
     $(".image"+ counter +"").fadeIn(0).fadeOut(2000), //.. shows box one the hides it so i can be faded in! *failsafe
     clearTimeout(timer);
    timer = setTimeout(eval("fadingFun"),"5000");  // rrestart the functions
    
}





});
