
// trundles our carousel about...
var latest_slide_in_progress = false;
function latest_slide(direction) {
	if(!latest_slide_in_progress) {
		// get an array of what our slide offsets will be based on the frame heights
		var offsets = new Array();
		var n = 0;
		var max_slide = $("#latest_items").outerHeight(true) - $("#latest_slider").outerHeight(true);
		$("#latest_items > .latest_item").each(function() {
			if(n < max_slide) {
				offsets.push(n * -1);
				n += $(this).outerHeight(true);
			}
			
		});
		
		// get our current offset.
		current = $("#latest_items").position().top;
		
		// see where that offset sits on our array of offsets.
		for(i=0;i<offsets.length;i++) {
			if(offsets[i] == current) {
				break;
			}
		}
		
		// look at the direction they're going and adjust our index accordingly.
		i = (direction == "next") ? (i + 1) : (i - 1);
		i = (i < 0) ? offsets.length - 1 : i;
		i = (i == offsets.length) ? 0 : i;
		
		// slide there already.
		latest_slide_in_progress = true;
		$("#latest_items").animate({"top" : offsets[i]}, "fast", function() { latest_slide_in_progress = false; });
	}
}

// a little function that runs the above every 5 seconds or so
function auto_latest_slide() {
	auto_latest = setInterval("latest_slide('next')", 4000);
}

// set it so that the latest jobs thing slides every 5 seconds or so
$(document).ready(auto_latest_slide);

