//TESTING VARIABLES
var currentSlide = 0;
//END OF TESTING VARIABLES

var slides = [
				[
					'images/akali_banner0.jpg',
					'<span class="h2">AKALI</span><span class="reg">&reg;</span> Advance Performance Supplement',
					'Revolutionary alkalizing glacier water formulated with Alka-PlexLiquid<span class="reg">&trade;</span>'
				],
				[
					'images/akali_banner1.jpg',
					'',
					'This is a next generation functional water utilizing cutting edge aquaceutical technology to enhance energy levels, increase endurance, speed recovery and boost performance levels.'
				],
				[
					'images/akali_banner2.jpg',
					'Accelerated recovery.',
					'With the addition of Alka-Plex liquid<span class="reg">&trade;</span>, AKALI<span class="reg">&reg;</span> supports peak physical performance and health by effectively countering metabolic acidosis and acidic stress in the body. This has been shown to dramatically reduce recovery time and help eliminate muscle sorenes and fatigue from strenuous excersize.'
				],
				[
					'images/akali_banner3.jpg',
					'<span class="h2">Increased endurance.</span>',
					'Pure Glacier Water from Mt. Rainier, rich in trace minerals and processed with proprietary technology provides a highly efficient suspension for Alka-Plex Liquid\'s natural alkalizing compounds, allowing them to be absorbed more readily by the body. The result is a super-combination of increased blood-oxygen level and decreased acid build-up as it happens! This can provide an athlete with dramatically improved endurance. '
				],
				[
					'images/akali_banner4.jpg',
					'<span class="h2">Not an "ADE"</span>',
					'...a professional performance supplement. AKALI\'s formulation neutralizes acids contained in many popular sports drinks while enhancing electrolite uptake by the body.'
				],
				[
					'images/akali_banner5.jpg',
					'<span class="h2">AKALI</span><span class="reg">&reg;</span><span class="h2"> will give you the edge.</span>',
					'AKALI<span class="reg">&reg;</span> is a cutting-edge aquaceutical glacial water, rich in natural trace minerals, naturally structured and infused with the patented and FDA approved ingredients of Alka-Plex Liquid<span type="reg">&trade;</span> This is the ultimate performance beverage. No calories, no carbs, no sugar, no caffeine... nothing but results!'
				]
			 ];

var textWindowTransitioning = false, loading = false, bannerTransitioning = false, bannerSliderTimeOut;
var akaliLogo = new Image();
akaliLogo.src = 'images/akaliLogo.png';

//Variable speeds for animations in 1/1000's of a sec.
var textWindowSlidingSpeed = 500;		//text window sliding in and out speed
var transitionBannersSpeed = 400;		//fade of the banners in and out
var bannerTransitionPause = 2000;		//pause between banners (blank banner time)
var bannerDisplayTime = 7000;

for( var x = 0; x < slides.length; x++ ) {
	var img = new Image();
	img.src = slides[x][0];
}


//Onload function
$(document).ready(function() {
	$('#banners').append('<div id="textWindow"><span id="filler"></span><div id="textWindowContent"><div class="textWindowParagraph"><p class="phead" id="phead"></p><p id="pbody"></p></div><img src="images/akaliLogo.png"></div></div>');
	nextSlide();
});


function transitionBanners() {
	if( bannerTransitioning !== true ) {
		bannerTransitioning = true;
		hideTextWindow();
		$('#banners').animate({opacity: '0'}, transitionBannersSpeed, function() {
			$('#bannerImg').replaceWith('<img id="bannerImg" src="'+slides[currentSlide][0]+'">');
			setTimeout(function() {
				$('#banners').animate({opacity: '1'}, transitionBannersSpeed, function() {
					setTimeout(function() { 
						bannerTransitioning = false;
						showTextWindow();
						currentSlide++;
						if( currentSlide > slides.length-1 )
							currentSlide = 0;
						setTimeout(function() {nextSlide()}, bannerDisplayTime); }, 100 );
				});
			}, bannerTransitionPause);
		});
	}
	else {
		//troubleshooting only
		alert(bannerTransitioning);
	}
}

function nextSlide() {
	var image = new Image();
	image.src = slides[currentSlide][0];
	if( image.complete ) {
		transitionBanners();
	}
	else
		image.onload = transitionBanners;
	
}



function showTextWindow() {
	if( textWindowTransitioning !== true ) {
		textWindowtextWindowTransitioning = true;
		//Replace text
		var pHeader = '<p id="phead" class="phead">'+slides[currentSlide][1]+'</p>';
		var pbody = slides[currentSlide][2];
		if( pbody.length > 420 ) {
			pbody = '<span style="font-size: 11px;">'+pbody+'</span>';
		}
		else if( pbody.length > 181 ) {
			pbody = '<span style="font-size: 12px;">'+pbody+'</span>';
		}
		$('#phead').replaceWith(pHeader);
		$('#pbody').replaceWith('<p id="pbody">'+pbody+'</p>');
		$('#textWindow').animate({left: '0px'}, textWindowSlidingSpeed, function() { textWindowTransitioning = false; } );
	}
}

function hideTextWindow() {
	if( textWindowTransitioning !== true ) {
		textWindowTransitioning = true;
		$('#textWindow').animate({left: '-551px'}, textWindowSlidingSpeed, function() { textWindowTransitioning = false; } );
	}
}