// SET THIS VARIABLE FOR DELAY, 1000 = 1 SECOND
var delayLength = 6000;
var iteration = 1;
var numPanels = $(".slide").length;
	
function doMove() {

	$(".slide").fadeOut();
	$("#slide-"+iteration).fadeIn();
	
	/*var height = 0;
	var ctnr = 0;
	$(".slide p").each(
		function()
		{
			if(ctnr == iteration && $(this).height() > height)
			{
				height = $(this).height()+20;
			}
			ctnr++;
		}
	);
	
	if(height < 425)
	{
		height = 425;
	}
	
	$("#slider").css("height", height+"px");
	$("#sliderPretender").animate(
		{
			height: height+"px"
		},
		1000,
		function() {
			// Animation complete.
		}
	);*/
	
	iteration++;
	if(iteration >= numPanels)
	{
		iteration = 0;
	}
}

$(function(){
	/*var height = 0;
	var ctnr = 0;
	$(".slide p").each(
		function()
		{
			if(ctnr == 0 && $(this).height() > height)
			{
				height = $(this).height()+20;
			}
			ctnr++;
		}
	);
	if(height < 425)
	{
		height = 425;
	}
	$("#slider").css("height", height+"px");
	$("#sliderPretender").css("height", height+"px");*/
	
    var $slide1 = $("#slide-0");
	
	

	
	
	if(numPanels > 1)
	{
		$("#slider").append('<a href="#" id="slider-stopper" class="stop"><image id="slider-stopper-img" src="images/stop.png" style="border:none; width:15px;" alt=""/></a>');
		
		sliderIntervalID = setInterval(function(){
			doMove();
		}, delayLength);
		
		$("#slider-stopper").click(function(){
			if ($(this).attr("class") == "stop") {
				clearInterval(sliderIntervalID);
			 	$(this).attr("class", "start");
			 	$("#slider-stopper-img").attr("src", "images/start.png");
			}
			else {
				sliderIntervalID = setInterval(function(){
					doMove();
				}, delayLength);
				$(this).attr("class", "stop");
			 	$("#slider-stopper-img").attr("src", "images/stop.png");
			}
			 
		});
	}

});
