/*
Lettuce.com.au
         __..--''``\--....___   _..,_
     _.-'    .-/";  `        ``<._  ``-+'~=.
 _.-' _..--.'_    \                    `(^) )
((..-'    (< _     ;_..__               ; `'   
           `-._,_)'      ``--...____..-'
RonDSwan

*/

$(document).ready(function(){
//alert("helloWorld!");
	//bgStretcherInit();

	startFader();
});

function bgStretcherInit()
{
	$('#contentHolder').bgStretcher(
 	{
      images: ['../images/bg01.jpg'], 
            imageWidth: 1920, imageHeight: 1280
  	});
}

function startFader()
{
	//Image fader
		
		// 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
	    $("#rotatorHolder").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(BannerLable) // push then
	           ImageArragEnd = ImageArray.length; // updating the array
	    });
	
	    // test to see if there is 1 or more images ---------------------
	    if(ImageArragEnd == 1){
	           //do nothing!
	           $(".image1").css("display", "inline");
	           }else{
	           fadingFun(); // start the banner fade
	           //$("#fader").children().fadeOut(0); // hides all of the slides
	           $(".image1").fadeIn(0); // hides all of the slides
	
	    }


	    //make the squares for the current image indication
	    if(ImageArragEnd != 1)
	    {
		    for(var i = 1; i<ImageArragEnd; i++)
		    {

		    	$('<div id="indicator' + i + '" class="imageIndicator"></div>').appendTo("#rotatorIndicatorHolder");
		    	$("#indicator1").css('background-color', '#F2C300');
		    	//the first one wont take the colour in the fader loop... so set it here.
		    }
		}
	
	
	    // fading FUNction -----------------------------------------------
	    function fadingFun(){
	
	    ImageArragEnd = (ImageArray.length) + 1; //UPDAT PUT BOTH INTO A FUCNTION as a call back of each....
	            counter ++;
	            //BGcounter ++;
	            
	                   // $("#fader").css("background-image","url("+ ImageArray[BGcounter] +")");      // get this working
				if(counter == ImageArragEnd ){  // check were its upto in the line and if its the last one then *restart*
	                   counter = 1;
	            }
	            
	            //$(".sectionHeading").text(counter); //use this for testing the counter...
	            $(".imageIndicator").css('background-color','#A38816');
	            $("#indicator" + counter).css('background-color','#F2C300');

	            $(".faderItem").fadeOut(1000),
	                 clearTimeout(timer);
	               timer = setTimeout(eval("fadingFun"),"5000");  // rrestart the functions
	                $(".image"+ counter +"").fadeIn(1000); //.. shows box one the hides it so i can be faded in! *failsafe
	            

	
	             // restarter
	    }
}
