// set variable for total width
var totalWidth = 0;


// Requires JQuery

// on window load
$(window).load(function() {

	// set up the slideshow
	//$('#photos ul').addClass('slideshow');
	
	// position elements
	$('div.feature_molecule_slide ul li').each(function() {
	
		totalWidth += $(this).outerWidth() + 10;
		
		if($(this).prev('li').position()) {
		
			var prevPosition = $(this).prev('li').position();
			var prevWidth = $(this).prev('li').width();
			
			$(this).css({ left: prevPosition.left + prevWidth + 50 + 'px' });
		}
	});

	// set width of ul
	$('div.feature_molecule_slide ul').width(totalWidth - 20);
	
	// scroll images
	$('.slideRight').click(function() {
		
		var i = Math.round(10000*Math.random());
		// + '/?a=' + i
		
		if ($('div.feature_molecule_slide ul').is(':animated')) {
			// do nothing
			} else {
			scrollImages('left');
			};
		
		
		return false;
	});
	
	
	$('.slideLeft').click(function() {
		
		if ($('div.feature_molecule_slide ul').is(':animated')) {
		} else {
		scrollImages('right');
		};
		
		return false;
	});
	

});


// animates images
function scrollImages(direction) {

	var distance = $('div.feature_molecule_slide').width();
	var position = $('div.feature_molecule_slide ul').position();
	var visibleWidth = $('div.feature_molecule_slide').width();
	
	if(direction == "left") {
	
		var spaceRemaining = totalWidth - (visibleWidth - position.left);
		var increment = '-=';
	}
	else {
	
		var spaceRemaining = position.left * -1;
		var increment = '+=';
	}
	
	if(spaceRemaining > 0 && spaceRemaining < distance) {
	
		distance = spaceRemaining;
	}
	else if(spaceRemaining == 0) {
	
		distance = 0;
	}
	
	$('div.feature_molecule_slide ul').animate({ left: increment + distance + 'px' }, {
		duration: 2000,
		easing: 'easeInOutQuad'
	});
}




