$(document).ready(function() {
	
	$(".slider .slider-controls a").click(function(){

		var trig = $(this);
		
		if ( !(trig.hasClass("disabled")) && !(trig.closest(".slider").hasClass("active"))  ) {

			var s = trig.closest(".slider");
			var sWidth = s.width();
			var sGroup = s.find(".slider-group");
			var sGroupPos = sGroup.position().left;
			var sGroupNum = sGroup.find("li").length;
			var sGroupWidth = sGroupNum * sWidth;
			
			// establishes the widths of the list items and the parent
			sGroup.width(sGroupWidth);
			sGroup.children("li").width(sWidth);
			
			var index = s.find("a.slider-pick").index(trig);
			var sStop = -(sWidth * index);
			
			if ( trig.hasClass("slider-next") ) {
				var sStop = sGroupPos - sWidth;
			} 
			if ( trig.hasClass("slider-prev") ) {
				var sStop = sGroupPos + sWidth;
			} 

			// prevents multiple clicks
			s.addClass("active");

			// slide the slider group
			sGroup.animate({left:sStop},300,function(){
				s.removeClass("active");
			});
		
			// removes all disabled
			s.find(".slider-controls a").removeClass("disabled"); 
	
			// now figure out what controls should be disabled
			var indexShown  = -sStop / sWidth ;
			s.find(".slider-pick").eq(indexShown).addClass("disabled");

			if ( sStop >= 0 ) { 
				s.find(".slider-prev").addClass("disabled") 
			}
			if ( sStop <= ( sWidth * -(sGroupNum - 1) ) ) { 
				s.find(".slider-next").addClass("disabled") 
			}
			
		}
	
		return false;
	});

});	
