// Editable variables
var max = 4;
var delay = 3000;

// Do not edit past here
var d = 1;
var s = 1;
var bScroll = false;
var t;
var width = 0;

$(document).ready(function(){
	loadContent();
	t = setTimeout("scrollContent();", delay);
});

function loadContent(){
	var content = null;
	
	if(d == 1){ s--; }else{ s++; }
	if(s < 1){ s = max; }else if(s > max){ s = 1; }
	
	$.ajax({
		type: "GET",
		url: "/inc/slides/" + s + ".asp.inc",
		success: function(data){
			content = data;
		},
		error: function(){
			content = "<h1>Slide could not be found</h1>";
		},
		complete: function(){
			content = "<div id=\"Slide" + s + "\" class=\"new\">" + content + "</div>";
			
			$("#contentScroller .current").after(content);			
			$("#contentScroller .current").css("left", 0);		
			width = $("#contentScroller .current").width();
			width += parseInt($("#contentScroller .current").css("paddingLeft"), 10) + parseInt($("#contentScroller .current").css("paddingRight"), 10);
			
			if(d == 1){
				$("#contentScroller .new").css("left", "-" + width + "px");
			}else{
				$("#contentScroller .new").css("left", width + "px");
			}
			
		}
	});
}

function scrollContent(){
	if($("#contentScroller .new").length > 0){	
		if(d == 1){
			$("#contentScroller .current").animate({ left: width + "px" }, 1000);
		}else{
			$("#contentScroller .current").animate({ left: "-" + width + "px" }, 1000);
		}
			
		$("#contentScroller .new").animate({ left: "0px"}, 1000, 
			function(){ 
				$("#contentScroller .current").remove();
				$("#contentScroller #Slide" + s).removeClass("new").addClass("current");
				 
				bScroll = false;
				loadContent();
				t = setTimeout("scrollContent();", delay);
			});
	}
}
