var imgSet = [];
var curSet = 0;
var curImgSet = 0;

var fadeInt;

//<img alt="" src="/images/homepage-image-2.jpg" id="homeImage" /> </div>

$(function(){

	$('ul.imgSelect li').click(function(){
	
		clearInterval(fadeInt);
	
		$('ul.imgSelect li').removeClass('active');
	
		var Tmp_ID = $(this).attr("rel");
			Tmp_ID = parseInt(Tmp_ID)-1
		
		curSet = Tmp_ID;
		
		fadeImage(curSet);
		
		$(this).addClass('active');
		
	});
	
	buildImgSet();
	
	fadeInt = setInterval ( "cycleImages()", 5000 );
	
});

function imgSetRec () {

    Img1 = '';
    Txt = '';
	
}

function buildImgSet() {
	
	var newImgSetRec = new imgSetRec;
	newImgSetRec.Img1 = "url(/images/homepage-image-2.jpg)";
	newImgSetRec.Txt = "Supervisor Dashboard";
	$('.fadeText').html( newImgSetRec.Txt );
	imgSet[imgSet.length] = newImgSetRec;
	
	var newImgSetRec = new imgSetRec;
	newImgSetRec.Img1 = "url(/images/homepage-image-3.jpg)";
	newImgSetRec.Txt = "Script Editor";
	imgSet[imgSet.length] = newImgSetRec;
	
	var newImgSetRec = new imgSetRec;
	newImgSetRec.Img1 = "url(/images/homepage-image-1.jpg)";
	newImgSetRec.Txt = "Agent Interface";
	imgSet[imgSet.length] = newImgSetRec;

	var newImgSetRec = new imgSetRec;
	newImgSetRec.Img1 = "url(/images/homepage-image-4.jpg)";
	newImgSetRec.Txt = "Campaign Selector";
	imgSet[imgSet.length] = newImgSetRec;
}

function fadeImage(iImg_ID) {

	try{
	
		// Set faderDiv background to wrapper background
	
		document.getElementById('fadeWrapper').style.backgroundImage = document.getElementById('faderDiv').style.backgroundImage;
		//$('#fadeWrapper').show();
		$('#faderDiv').hide();

		document.getElementById('faderDiv').style.backgroundImage = imgSet[iImg_ID].Img1;
		$('.fadeText').html(imgSet[iImg_ID].Txt);
		
		$('#faderDiv').fadeIn('slow');
		
	}catch(Ex){}


}

function cycleImages() {
	curSet += 1;
	if (curSet >= imgSet.length) {curSet = 0;}
	
	$('ul.imgSelect li').removeClass('active');
	$('ul.imgSelect li').each(function(){
		if ( parseInt($(this).attr("rel")) == parseInt(curSet)+1 ) {
			$(this).addClass('active');
		}
	});
	
	fadeImage(curSet);
}
