var bannerArray = new Array();
var currentBanner = 0;
var myInterval = setInterval ( 'moveBannerAuto()' , 10000 ); 

function bannerData(_bimg , _btext , _bLinkCap , _bLink)	{
	this.bImg = _bimg;
	this.bText = _btext;
	this.bLinkCap = _bLinkCap;
	this.bLink = _bLink;
}

function updateCurrentBanner(bannerArrayIndex, cancelAutoScroll)	{

	if (cancelAutoScroll)	{	clearInterval(myInterval);	}

	// Make sure we have at least one banner to show
	if (bannerArray.length != 0)	{
		currentBanner = bannerArrayIndex;
		ba = bannerArray[currentBanner];

		$('#BannerBgImg').attr('src', ba.bImg);
		$('#bannerText').html(ba.bText);
		$('#bannerLink').html(ba.bLinkCap);

		if (ba.bLinkCap == '')	{
			$('#bannerLink').css('display', 'none');
		}
		$('#bannerLink').attr('href' , ba.bLink);

		// Change menu bullet thing
		$('#bannerNav a.on').removeClass('on');
		$('.bannerNav' + bannerArrayIndex ).addClass('on');
	}else{
		$('#bannerNav').css('display', 'none');
	}
}

function initBannerScroller()	{
	updateCurrentBanner(0, false);

	//console.log(bannerArray.length);

	// Build the little radio list
	//console.log(bannerArray.length);
	if (bannerArray.length > 1)	{


		var radBut = '';
		radBut += '<a href="javascript:void(0)" onclick="moveBanner(\'last\', true)" id="last">&lt;</a>';
		for (i=0 ; i < bannerArray.length ; i++ )	{
			radBut += '<a href="javascript:void(0)" onclick="updateCurrentBanner(' +i+ ', true)" class="bannerNav' +i+ ' bannerNavRad">' +(i + 1) + '</a>';
		}
		radBut += '<a href="javascript:void(0)" onclick="moveBanner(\'next\', true)" id="first">&gt;</a>';
		$('#bannerNav').html(radBut);
	}else{
		$('#bannerNav').html('');
	}


}

function moveBannerAuto()	{
	moveBanner('next', false);
}

function moveBanner(dir, cancelAutoScroll)	{

	if (cancelAutoScroll)	{	clearInterval(myInterval);	}

	tempBannerIndex = currentBanner;
	if (dir == 'next')	{
		tempBannerIndex++;
		if ( tempBannerIndex >= bannerArray.length )		{
			tempBannerIndex = 0;
		}
		updateCurrentBanner(tempBannerIndex);
	}else{
		
		tempBannerIndex--;
		if ( tempBannerIndex < 0 )		{
			tempBannerIndex = (bannerArray.length - 1);
		}
		updateCurrentBanner(tempBannerIndex);
	}
}


