// JavaScript Document
var curGlowBtn = 'cb1';
function gid(id){return document.getElementById(id);}
function bpActive(id){
	if(id != curGlowBtn){
		gid(id).style.backgroundPosition = '0 0';
		gid(curGlowBtn).style.backgroundPosition = '-48px 0';
		curGlowBtn = id;
    }
}

$(document).ready(function () { 
preload();
$(function(){
	$("#cb1").click(function(){
		$("#header-img-container").fadeTo("normal", .001, function(){
			document.getElementById('header-img-container').style.background = 'url(images/header-scroll-image-1.jpg) no-repeat';
			bpActive('cb1');
			clearInterval(intval);
			$("#header-img-container").fadeTo("normal", 1);
		});
	});
});

$(function(){
	$("#cb2").click(function(){
		$("#header-img-container").fadeTo("normal", .001, function(){
			bpActive('cb2');
			document.getElementById('header-img-container').style.background = 'url(images/header-scroll-image-2.jpg) no-repeat';
			clearInterval(intval);
			$("#header-img-container").fadeTo("normal", 1);
		});
	});
});

$(function(){
	$("#cb3").click(function(){
		$("#header-img-container").fadeTo("normal", .001, function(){
			bpActive('cb3');
			document.getElementById('header-img-container').style.background = 'url(images/header-scroll-image-6.jpg) no-repeat';
			clearInterval(intval);
			$("#header-img-container").fadeTo("normal", 1);
		});
	});
});

$(function(){
	$("#cb4").click(function(){
		$("#header-img-container").fadeTo("normal", .001, function(){
			bpActive('cb4');
			document.getElementById('header-img-container').style.background = 'url(images/header-scroll-image-3.jpg) no-repeat';
			clearInterval(intval);
			$("#header-img-container").fadeTo("normal", 1);
		});
	});
});

$(function(){
	$("#cb5").click(function(){
		$("#header-img-container").fadeTo("normal", .001, function(){
			document.getElementById('header-img-container').style.background = 'url(images/header-scroll-image-4.jpg) no-repeat';
			bpActive('cb5');
			clearInterval(intval);
			$("#header-img-container").fadeTo("normal", 1);
		});
	});
});

$(function(){
	$("#cb6").click(function(){
		$("#header-img-container").fadeTo("normal", .001, function(){
			document.getElementById('header-img-container').style.background = 'url(images/header-scroll-img-5.jpg) no-repeat';
			bpActive('cb6');
			clearInterval(intval);
			$("#header-img-container").fadeTo("normal", 1);
		});
	});
});

});


var curImg = 0;
var imgArray = new Array('images/header-scroll-image-1.jpg', 'images/header-scroll-image-2.jpg', 'images/header-scroll-image-6.jpg', 'images/header-scroll-image-3.jpg', 'images/header-scroll-image-4.jpg', 'images/header-scroll-img-5.jpg');
var intval = setInterval("autoScroll()", 6000);

function autoScroll(){
	$("#header-img-container").fadeTo("normal", .001, function(){
		document.getElementById('header-img-container').style.background = 'url('+imgArray[curImg]+') no-repeat';
		bpActive('cb'+(curImg+1));
		curGlowBtn = 'cb'+(curImg+1);
		$("#header-img-container").fadeTo("normal", 1);
	});
	curImg++;
	if (curImg == 6){curImg = 0;}
}


function preload(){
	pic= new Image(983,428); 
    pic.src="images/header-scroll-image-1.jpg";
	pic2= new Image(983,428); 
    pic2.src="images/header-scroll-image-2.jpg";
	pic3= new Image(983,428); 
    pic3.src="images/header-scroll-image-3.jpg";
	pic4= new Image(983,428); 
    pic4.src="images/header-scroll-image-4.jpg";
	pic5= new Image(983,428); 
    pic5.src="images/home-boxes.jpg";
	pic6= new Image(983,428); 
    pic6.src="images/atv_bounce.png";
	pic6= new Image(983,428); 
    pic6.src="images/header-scroll-img-5.jpg";
	pic6= new Image(983,428); 
    pic6.src="images/header-scroll-image-6.jpg";
}


