$(function() {
	var gallery = $('#glider_images');
	var items = gallery.find('li');
	var width = items.outerWidth(true);
	var n = items.length;
	var text = gallery.html();
	text += text + text;
	text += text + text;
	gallery.html(text);
	
	gallery.css('margin-left', -n * width* 3);
	
	$('#glider_left').click(function() {
		if (gallery.is(':animated')) return false;
		var left = parseInt(gallery.css('margin-left'));
		gallery.animate({
			'margin-left': '+=' + width * 3
		}, 500, function() {
			if (left == -width * 3) gallery.css('margin-left', -n * width * 3);
		});
		return false;
	});
	
	$('#glider_right').click(function() {
		if (gallery.is(':animated')) return false;
		var left = parseInt(gallery.css('margin-left'));
		gallery.animate({
			'margin-left': '-=' + width * 3
		}, 500, function() {
			if (left == -2*width*3*n + width*3) gallery.css('margin-left', -n * width * 3);
		});
		return false;
	});
	
});
