/*
RSG Home Splash Slide Show :: Horizontal With Numbered Controls
Created By: Mitch Gohman
Date: 2011-09-19
With much love to JQuery - the javaScript browser equalizer
My first attempt used positioning and loaded all images at once.
	IE had issues with overflow:hidden and the front load of all BIG images was a tremnendous strain on the
	initial loading of the page.
	
	My new goal is to load images as needed
	Use positioning, but use less vertical real estate
	I also want to use CSS to control the appearance more - so assigning classes as opposed to JS CSS Styles
	
*/
var homeSplash_slideChosen = 0; //second slide :: first slide starts with 0
var homeSplash_slideWidth = 882;
var homeSplash_loopHandle;
var homeSplash_slideshowPause = 6000;
var homeSplash_slideTransSpeed = 2000;

function homeSplash_slideshow() {
	//console.log('looping');
	
	homeSplash_slideChosen++;
	var getSlides = $('#splashSlide ol.slider li');
	var numSlides = getSlides.length;
	
	if (homeSplash_slideChosen == numSlides)
		{
		homeSplash_slideChosen = 0;	
		}
	
	homeSplash_slide(homeSplash_slideChosen);
	homeSplash_selectLI(homeSplash_slideChosen);
	
	homeSplash_loopHandle = setTimeout(homeSplash_slideshow,homeSplash_slideshowPause);
	
}
function homeSplash_slideselect() {
	clearTimeout(homeSplash_loopHandle);
	var whichSlide = $(this).attr('value');
	homeSplash_slide(whichSlide);
	homeSplash_selectLI(whichSlide);
	
	homeSplash_loopHandle = setTimeout(homeSplash_slideshow,(homeSplash_slideshowPause*1.25));
}
function homeSplash_slide(whichSlide) {
	homeSplash_slideChosen = whichSlide;
	var slideToWhat = homeSplash_slideChosen * homeSplash_slideWidth;
	$('#splashSlide ol.slider').animate({'left':'-' + slideToWhat + 'px'},homeSplash_slideTransSpeed);
}
function homeSplash_selectLI(liIndex) {
	$('#splashSlide ol.nav li').removeClass('selected').css({'opacity':'.4'});
	var whichLI = $('#splashSlide ol.nav li');
	$(whichLI[liIndex]).addClass('selected').css({'opacity':'1'});
}

function homeSplash_setHeadings() {
	$('#splashSlide ol.slider img').each(function(i) {
		var getParentLI = $(this).parent();
		var getAlt = $(this).attr('alt');
		var newHeading = $('<h2>'+getAlt+'</h2>').prependTo(getParentLI);
	});	
}


$(document).ready(function() {
	//homeSplash_setHeadings();
	homeSplash_selectLI(0);
	homeSplash_loopHandle = setTimeout(homeSplash_slideshow,homeSplash_slideshowPause);
	$('#splashSlide ol.nav li').click(homeSplash_slideselect);
});
