$(document).ready(function () {
	var pos = 0;
	var total = $('#slide').children('div.i').size()-1;
	var gotbeforeafter = 0;
	
	$('a#next').click(function() {		
		pos = slideshowpos(pos, total, 'next');
		$('#slide').dequeue().animate({ marginLeft: pos*(-800) }, 350);
		return false;
	});
	
	$('a#prev').click(function() {
		pos = slideshowpos(pos, total, 'prev');
		$('#slide').dequeue().animate({ marginLeft: pos*(-800) }, 350);
		return false;
	});
	
	$('.beforeafter .i div img').hover( function() { $('#slide').css('margin-top', '-533px'); if(gotbeforeafter == 0) { $('#help').fadeOut(1000); gotbeforeafter = 1; } }, function() { $('#slide').css('margin-top', '0'); } );
});

function slideshowpos(pos, total, direction) { //used when the last picture in slidehow is reached and user presses next. Or when user presses 'prev' on the first picture in slideshow
	if(direction == 'next') {
		if(pos<total) pos++;
		else pos=0;
	}
	else {
		if(pos>0) pos--;
		else pos = total;
	}
	return pos;
}