var showStarted = false;
var showEnded = false;
var activeContainer = 0;
var containersTotal = 0;
var nextWidth = 0;
var nextWidthCurrent = 0;
var previousWidth = 0;
var previousWidthCurrent = 0;
var lastHitNext = true;

(function($) {
	$(function() {
		 if ($('#collections-imageStrip li').length >= 4) {
			$('#collections-next').css('visibility','visible');
		 }
		$('#collections-next').click( function() {
			if(showStarted==false) {
				showStarted=true;
				$('#collections-previous').css('visibility','visible');
			}
			nextWidth = $('#collectionImage-' +  activeContainer).width();
			if(lastHitNext==true) {
				nextWidthCurrent = eval(nextWidthCurrent + nextWidth + 6);
			} else {
				nextWidthCurrent = eval(previousWidthCurrent + nextWidth + 6);
			}
			$("#collections-imageStrip").animate({ 
		        "left": "-" + nextWidthCurrent + "px"
		     }, 750 );
			 activeContainer = activeContainer+1;
			 if (activeContainer == containersTotal) {
			 	$('#collections-next').css('visibility','hidden');
				 showEnded = true;
			 }
			 lastHitNext = true
		});
		
		$('#collections-previous').click( function() {
			if(showEnded==true) {
				showEnded=false;
				$('#collections-next').css('visibility','visible');
			}
			activeContainer = activeContainer-1;
			previousWidth = $('#collectionImage-' +  activeContainer).width();
			if(lastHitNext==true) {
				previousWidthCurrent = eval(nextWidthCurrent - previousWidth - 6)
			} else {
				previousWidthCurrent = eval(previousWidthCurrent - previousWidth - 6);
			}
			$("#collections-imageStrip").animate({ 
				"left": "-" + previousWidthCurrent + "px"
			}, 750 );
			if (activeContainer == 0) {
				$('#collections-previous').css('visibility','hidden');
				showStarted = false;
				nextWidthCurrent = 300;
			}
				
			lastHitNext = false;
		});
	})
})(jQuery);				
