var current = 1;
var sliderTimer = 4000;
var sliderTimerID = 0;

function slide(showing, next) {
	
	$("#slides p.back").fadeTo("normal", 0);
	$("#s"+showing).fadeOut("normal", function() {
		$("#s"+showing+"-link").removeClass("active");
		$("#s"+next+"-link").addClass("active");
		$("#slides p.back").fadeTo("normal", 0.5);
		$("#slides p.back, #slides p.text").html($("#s"+next+" img").attr("alt"));
		$("#slides-link").attr("href", $("#s"+next+"-link").attr("ref"));
		$("#s"+next).fadeIn("normal");
	});
	
}

function slideStart() {
	
	$("#slides p.back").fadeTo("normal", 0.5);
	
	slideTimer();
	
	$("#s1-link").click(function() {$(this).blur(); slideNext(1); return false;});
	$("#s2-link").click(function() {$(this).blur(); slideNext(2); return false;});
	$("#s3-link").click(function() {$(this).blur(); slideNext(3); return false;});
	$("#s4-link").click(function() {$(this).blur(); slideNext(4); return false;});
	
}

function slideNav(link) {
	
	$(this).blur();
	
	slideNext(link);
	
	return false;
	
}

function slideNext(link) {
	
	var showing = current;
	
	if (link == 0)
		var next = current + 1;
	else
		var next = link;
	
	if (link == 0 && next > 4)
		next = 1;
	
	current = next;
	
	clearTimeout(sliderTimerID);
	
	slide(showing, next);
	 
	slideTimer();
	
}

function slideTimer() {
	
	sliderTimerID = setTimeout("slideNext(0)", sliderTimer);
	
}

$(document).ready(function() {
	slideStart();
});