// JavaScript Document
	var slidepoint =	{
						state : 'start',
						i : 0,
						stasis: 8000,
						refresh: 333,
						intervalID : null
					};
	
$(document).ready(function(){						
	slidepoint.slideTime = 700;
	slidepoint.currentSlide = 1;
	slidepoint.totalSlides = $("#slideBoard > div").size();
	slidepoint.slideWidth = $('#slideFrame').css('width');
	slidepoint.slideAmount = parseInt(slidepoint.slideWidth);
	$('#slideBoard div:nth-child(' + slidepoint.currentSlide + ')').css('left', slidepoint.slideWidth);

	slidepoint.slideAround = function(callback){
		if(typeof callback !== 'function'){
			callback = function(){}
		}
		var slideNumber = 1;
		var curslide = $('#slideBoard div:nth-child(' + slidepoint.currentSlide + ')');
		var newslide = $('#slideBoard div:nth-child(' + slideNumber + ')');			//alert('go 2');
		var newSlideNumber = 1;
		var newPos = parseInt(slidepoint.slideWidth) * 2;
			//# Then Slide Both Right
			$(newslide).css('left', newPos);
			//# Animate New Slide
			$(newslide).animate({
				left: [slidepoint.slideWidth]
				}, slidepoint.slideTime );
			//# Animate Current Slide
			$(curslide).animate({
				left: [0]
				}, slidepoint.slideTime, 'linear', function(){
					if(typeof callback === 'function')
						callback();
				});
		slidepoint.currentSlide = 1;
	}
	slidepoint.showSlide = function(slideNumber, callback){
		if(typeof callback !== 'function'){
			callback = function(){}
		}
		//#########################
		//# Exit Current Slide
		//# Determine Slide Direction
		//alert(slidepoint.currentSlide);
		//alert(slideNumber);
		slideNumber = parseInt(slideNumber);
		//slidePos = slideNumber -1;
		var curslide = $('#slideBoard div:nth-child(' + slidepoint.currentSlide + ')');
		var newslide = $('#slideBoard div:nth-child(' + slideNumber + ')');
		var newSlideNumber = parseInt(newslide.index()) + 1;
		var newPos = parseInt(slidepoint.slideWidth) * 2;
		//ie++;
		//alert('Slide from '+slidepoint.currentSlide +' to slide '+ newSlideNumber) ;
		if(slidepoint.currentSlide < slideNumber){
			//alert('go 1');
			//# Then Slide Both Left
			$(newslide).css('left', newPos);
			//# Animate New Slide
			$(newslide).animate({
				left: [slidepoint.slideWidth]
				}, slidepoint.slideTime );
			//# Animate Current Slide
			$(curslide).animate({
				left: [0]
				}, slidepoint.slideTime, 'linear', function(){
					if(typeof callback === 'function')
						callback();
				});
		}
		if(slidepoint.currentSlide > slideNumber){
			//alert('go 2');
			//# Then Slide Both Right
			$(newslide).css('left', 0);
			//# Animate New Slide
			$(newslide).animate({
				left: [slidepoint.slideWidth]
				}, slidepoint.slideTime );
			//# Animate Current Slide
			$(curslide).animate({
				left: [newPos]
				}, slidepoint.slideTime, 'linear', function(){
					if(typeof callback === 'function')
						callback();
				} );
		}
		//#########################
		//# Change Slide Number
		slidepoint.currentSlide = slideNumber;
	}
	
	slidepoint.slideLeft = function(callback){
		if(typeof callback !== 'function'){
			callback = function(){}
		}
		if(slidepoint.currentSlide > 1){
			slidepoint.showSlide(slidepoint.currentSlide-1, callback);
		}
	}
	slidepoint.slideRight = function(callback){
		if(typeof callback !== 'function'){
			callback = function(){}
		}
		if(slidepoint.currentSlide < slidepoint.totalSlides){
			slidepoint.showSlide(slidepoint.currentSlide+1, callback);
		}
	}
	
	slidepoint.slideTo = function(slideNumber){
		slidepoint.showSlide(slideNumber);
	}
	$('#slide2Left').click(function(){
		slidepoint.slideLeft();
	});
	
	$('#slide2Right').click(function(){
		slidepoint.slideRight();
		
	});
	/*
	$(document).keydown(function(e){
		 if(e.keyCode == 37){ 
			 //alert( "left pressed" );
			slidepoint.slideLeft();
			return false;
		 }
		 if(e.keyCode == 39){ 
			 //alert( "rigt pressed" );
			slidepoint.slideRight();
			return false;
		 }
	});
	*/
	//# Slide Reference Tool
	
	for(i = 1; i < (slidepoint.totalSlides+1); i++){
		$('#slideReference').append('<div class="slideNumber">'+i+'</div>');
	}
	$('.slideNumber').click(function(){
		slidepoint.slideTo($(this).html());
	});
	$(".slidePoint").touchwipe({
     wipeLeft: function() { 	slidepoint.slideRight(); },
     wipeRight: function() { 	slidepoint.slideLeft(); },
     min_move_x: 20,
     preventDefaultEvents: true
	});
	
	
	
	
	
	
	
	
	
	
	
//#################################################################
//#### Slide iterator
	
///*	

			
	//### create check state function
	//# this allows us to check the state of the slider at any point and decide what to do next.
	slidepoint.checkState = function(){

		if(slidepoint.state === 'start'){
			//# change the state (prevents any other action from occuring based on the state)
			slidepoint.state = 'stepone';
			setTimeout(function(){ slidepoint.slideRight(function(){ 
				if(slidepoint.checkLast() === false){
					slidepoint.state = 'start';
				}else{
					//console.log('last slide');
					slidepoint.state = 'last';
				}
			  })}, slidepoint.stasis);
		}
		if(slidepoint.state === 'last'){
			//# change the state
			slidepoint.state = 'flip';
			setTimeout(function(){ 
				slidepoint.slideAround(function(){
					slidepoint.state = 'start';
				});
			},
			slidepoint.stasis);
		}
	};
	
	slidepoint.goRight = function(){
		slidepoint.slideRight();
		slidepoint.checkLast();
	}
	slidepoint.changeState = function(state){
		slidepoint.state = state;
	}
	slidepoint.checkLast = function(){
		if(slidepoint.currentSlide === slidepoint.totalSlides){
			return true;
		}
		return false;
	}
	if(slidepoint.totalSlides > 1){
		slidepoint.intervalID = setInterval("slidepoint.checkState()", slidepoint.refresh);
	}
	
	
	
//*/	
	
	
	
});

