// JavaScript Document

//a global variable for all database queries.

// first lets make a slide show viewer for the front page...

var autoTO; // placeholder for TimeOut

function autoShow () {
	// clear out the to is if still exists
	clearTimeout(autoTO);
	if(slideShow.auto_pace > 0) {
		autoTO = setTimeout('slideShow.showNextSlide()', slideShow.auto_pace * 1000 );
	}
}


						   
var slideShow = {
	
	data:null
	,
	
	curSlide:0
	,
	
	rootURL:"/img/slides_v2/"
	,
	
	screen_img_top:null
	,
	screen_img_bottom:null
	,
	screen_caption_top:null
	,
	screen_caption_bottom:null
	,
	
	topToggle:true // begins in a visible state.
	,
	
	toggleTop: function( p_Bool_state){
		this.topToggle = p_Bool_state;
	}
	,
	
	auto_pace : -1   // -1 means NO AUTO SHOW... otherwise numbers = seconds per slide
	,
	
	
	loadSlide: function(){
		if(this.topToggle){  // the top is covering so load the bottom...
			this.screen_img_bottom.attr("src",this.rootURL + this.data[this.curSlide].src);
			this.screen_caption_bottom.html(this.data[this.curSlide].caption);
			this.screen_img_bottom.load(function() {
				slideShow.newSlide();
				autoShow();
			});
		}else {
			this.screen_img_top.attr("src",this.rootURL + this.data[this.curSlide].src);
			this.screen_caption_top.html(this.data[this.curSlide].caption);
			this.screen_img_top.load(function() {
				slideShow.newSlide();
				autoShow();
			});
		}
		
	}
	,

	newSlide: function(){
		// if the top is fading out to reveal, then fade out.
		if(this.topToggle) {
			this.screen_caption_top.fadeOut(600);
			this.screen_caption_bottom.fadeIn(600);
			this.screen_img_top.fadeOut(600, function(){
				slideShow.toggleTop( false );
				
			});
		}else{
			//this.screen_caption_top.html(this.data[this.curSlide].caption);
			this.screen_caption_top.fadeIn(600);
			this.screen_caption_bottom.fadeOut(600);
			this.screen_img_top.fadeIn(600, function(){
				slideShow.toggleTop( true );
				
			});
		}
	}
	
	, 
	
	showSlide: function(p_id) {
		var tmpIndex = this.getIndexByID( p_id);
		this.curSlide = tmpIndex;
		this.loadSlide();

	}
	,
	
	stopAutoShow: function(){
		this.auto_pace = -1;
	}
	,
	
	navSlideShow:function (p_dir ){
		this. stopAutoShow();
		if(p_dir < 0){
			this.showPrevSlide();
		}else{
			this.showNextSlide();
		}
	}
	,
	showNextSlide: function () {
		this.curSlide = ((this.curSlide + 1) < this.data.length) ? this.curSlide + 1 : 0;
		this.loadSlide();
	}
	,
	showPrevSlide: function () {
		this.curSlide = (this.curSlide <= 0) ? this.data.length - 1 : this.curSlide - 1;
		this.loadSlide();
	}
	,
	getIndexByID : function( p_id ){
		for(var nn=0; nn < this.data.length; nn++){
			if(this.data[nn].src == p_id){
				return nn;
			}
		}
		return nn;
	}

}

/*
/* add this to any page you want a slide show... 
/* set the screenIMG to the image to change
/* set the screenCaption to the text div to show thecaption
/* set the data in the format below and assign the index reference to your buttons
/*
/*
$(document).ready(function(){
	// set the slideShow
	slideShow.screenIMG = $("#slideIMG");
	slideShow.screenCaption = $("#slideCaption");
	slideShow.data = [ {src:"slide_01.jpg",caption:"Playing games together increases the learning opportunity.", uiBtn: $("#uiBtn_01")},
		   {src:"slide_02.jpg",caption:"Make decisions around buying cars and using credit cards.", uiBtn: $("#uiBtn_02")},
		   {src:"slide_03.jpg",caption:"The choice is yours to start a business or go to school.", uiBtn: $("#uiBtn_03")},
		   {src:"slide_04.jpg",caption:"\"Money is a life skill - and as parents, grandparents, interested adults - it's up to us to make sure our children are prepared for the financial world they are going to face.\" <br />Sharon Lechter<br /> - Author<br /> - Founder of Pay Your Family First, LLC<br /> - Member of the President's Advisory Council on Financial Literacy", uiBtn: $("#uiBtn_04")}
		   ];
});

*/