//====================================================================================================================

	var slideSpeed = 2000;
	var slideDelay = 10000;
	var slideIndex = 1;
	var slideCount;

	var bannerSpeed = 2000;
	var bannerDelay = 10000;
	var bannerTick = 100;
	var bannerTickCount = 0;
	var bannerIndex = 1;
	var bannerCount;
	var bannerTimer;
	var bannerAnimating = false;
	var bannerPlaying = true;
		
//====================================================================================================================

	$(document).ready(initSlides);
	$(document).ready(initBanners);
	
//====================================================================================================================

	function initSlides()
	{
		slideCount = $('.slide').size();
		slideIndex = Math.floor(Math.random()*slideCount+1);
		$('#slide'+slideIndex).css({'display':'block'});
		window.setInterval(showNextSlide,slideDelay);	
	}

//====================================================================================================================

	function initBanners()
	{
		$('#textBlockHolder').fadeTo(0,0.97);
		
		var html = '<div id="textBlockProgress"></div>';
		$('#textBlockControls').prepend(html);
		
		bannerCount = $('.textBlock').size();
		for(i=1; i<=bannerCount; i++)
		{
			html = '<a class="progressDot" href="javascript:showBanner('+i+')"></a>';
			$('#textBlockProgress').prepend(html);
		}
		
		html = '<a id="progressPlayPause" href="javascript:toggleBannerPlaying()"></a>';
		$('#textBlockControls').prepend(html);
		
		html = '<div id="progressBar"><div id="progressBarActive"></div></div>';
		$('#textBlockProgress').append(html);
		$('#progressBar').css('width',(bannerCount*15)-6);
		
		
		showBanner(1);
		
		$('.textBlock').click(toggleBannerPlaying);
		
		bannerTimer = window.setInterval(doBannerTick,bannerTick);	
	}

//====================================================================================================================

	function showNextSlide()
	{
		var nextSlide = slideIndex+1;
		if(nextSlide>slideCount) nextSlide = 1;

		showSlide(nextSlide);
	}
	
//====================================================================================================================

	function showSlide(nextSlide)
	{
		$('#slide'+ slideIndex).css({ 'z-index':0 });
		$('#slide'+ nextSlide).css({ 'display':'none', 'z-index':1 }).fadeIn((slideSpeed), function()
		{
			$('#slide'+ slideIndex).css({ 'z-index':-1 });
			slideIndex = nextSlide;
		});					
	}
	
//====================================================================================================================

	function showNextBanner()
	{
		var nextBanner = bannerIndex+1;
		if(nextBanner>bannerCount) nextBanner = 1;

		showBanner(nextBanner);
	}
	
//====================================================================================================================

	function showBanner(nextBanner)
	{
		if(!bannerAnimating)
		{
			bannerAnimating = true;
			bannerTickCount = 0;

			$('.progressDot').removeClass('active');
			
			$('#textBlock'+ bannerIndex).animate({'top':-180}, bannerSpeed/2, 'easeInBack', function()
			{
				$('#textBlock'+ nextBanner).css({'top':180, 'display':'block'}).animate({'top':0}, bannerSpeed/2, 'easeOutQuad');
				$('.progressDot').eq(bannerCount-nextBanner).addClass('active');
				bannerIndex = nextBanner;
				bannerAnimating = false;
			});
		}
	}
	
//====================================================================================================================

	function doBannerTick()
	{
		if(bannerPlaying && !bannerAnimating)
		{
			bannerTickCount += bannerTick;
			var activeWidth = (bannerTickCount/bannerDelay)*$('#progressBar').width();
			$('#progressBarActive').css('width',activeWidth);
			if(bannerTickCount==bannerDelay)
			{
				showNextBanner();
			}
		}
	}
	
//====================================================================================================================

	function toggleBannerPlaying()
	{
		bannerPlaying=!bannerPlaying;
		$('#progressPlayPause').toggleClass('paused', !bannerPlaying);
	
	}
	
//====================================================================================================================

