(function($){ 
//Super simple carousel, modified for vertical scrolling
$.fn.sscarouselvert = function(visible) {
	var $this = $(this),
		thisId = (function(){
				if ($($this).attr('id').length>0) {
					return $($this).attr('id');
				} else {
					alert ('Each carousel must have a unique ID. Plug-in terminating.');
					return false;
				}
			})(),
		clickcounter = {thisId: 0},
		slides = $('#'+thisId+' li'),
		carouselId = thisId+'_wrapper',
		btnsId = thisId+'_btns',
		carouselWrapper = document.createElement('div'),
		totalslides = parseInt($(slides).length,10),
		visibleslides = parseInt(visible,10);
		
	$(slides).css('float','left');
	var slideHeight = parseInt($(slides).outerHeight(),10);
	
	
	$(carouselWrapper).css({'position':'relative','height':'247px','overflow':'hidden'}).attr('id',carouselId).insertBefore($this).append($this);
//	$('#ssc_controls').append('<div id="'+btnsId+'" style="position:relative; float:left"><a href="javascript:void(0)" class="ssc_next"></a><a href="javascript:void(0)" class="ssc_prev disabled"></a></div>').customFadeIn(500, function(){ });
	$('#ssc_controls').customFadeIn(500, function(){ });

	$($this).css({
		'float':'left',
		'list-style':'none',
		'margin':'0',
		'padding':'0',
		'position':'relative',
		'height':'90000px'
	});



	function setBtnState () {
		var prev = $('#ssc_controls .ssc_prev'),
			next = $('#ssc_controls .ssc_next');

		switch (clickcounter.thisId) {
			case 0:
				prev.addClass('disabled');
				if (next.hasClass('disabled')) {
					next.removeClass('disabled');
				}
				break;
			case 1:
				prev.removeClass('disabled');
				if (totalslides-visibleslides === 1) {
					next.addClass('disabled');
				} else {
					if (next.hasClass('disabled')) {
						next.removeClass('disabled');
					}
				}
				break;
			case (totalslides-visibleslides-1):
				next.removeClass('disabled');
				break;
			case (totalslides-visibleslides):
				next.addClass('disabled');
				break;
		}
	}
	
	if (totalslides <= visibleslides) {
		$('#ssc_controls .ssc_next').addClass('disabled');
	}
	
	function moveSlides(top,callback) {
		$($this).animate({
			top: top
		},250,callback);	
	}
	
	$('#ssc_controls').click(function(e){
		var tg = e.target;
		
		if ($(tg).hasClass('ssc_next') || $(tg).hasClass('ssc_prev')) {
			var top = null;
				
			if($(tg).hasClass('ssc_next') && clickcounter.thisId < (totalslides-visibleslides)) {
				top = '-='+slideHeight;
				clickcounter.thisId++;
			} else if($(tg).hasClass('ssc_prev') && clickcounter.thisId > 0) {
				top = '+='+slideHeight;
				clickcounter.thisId--;
			} 
			moveSlides(top);
			setBtnState();
			return false;
		}
	});
};

})(jQuery);  

