//WRAP Wall of Fame selector

(function($) {                                          // Compliant with jquery.noConflict()
$.fn.jCarouselEvenLiter = function(o) {
	o = $.extend({
		btnPrev: null,
		btnNext: null,
		speed: 200,
		easing: null,

		start: 0,
		scroll: 1
	}, o || {});

	return this.each(function() {                           // Returns the element collection. Chainable.

		var running = false, sizeCss="width";
		var div = $(this), ul = $("> ul", div), originalItemCount = $("li", ul).size(), v = 1;

		// duplicate first/last items on opposite sides
		var lastItemCopy = $('li:last', ul).clone();
		var firstItemCopy = $('li:first', ul).clone();
		ul.prepend(lastItemCopy).append(firstItemCopy);
		o.start += 1;

		var li = $("> li", ul), itemCount = li.size(), curr = o.start;
		div.css("visibility", "visible");

		li.css({overflow: "hidden", float: "left"});
		ul.css({margin: "0", padding: "0", position: "relative", "list-style-type": "none", "z-index": "1"});
		div.css({overflow: "hidden", position: "relative", "z-index": "2", left: "0px"});

		var liSize = width(li);   // Full li size(incl margin)-Used for animation
		var ulSize = liSize * itemCount;                   // size of full ul(total length, not just for the visible items)
		var divSize = liSize;                           // size of entire div(total length for just the visible items)

		li.css({width: li.width(), height: li.height()});
		ul.css(sizeCss, ulSize+"px").css('left', -(curr*liSize));

		div.css(sizeCss, divSize+"px");                     // Width of the DIV. length of visible images

		if(o.btnPrev)
			$(o.btnPrev).click(function() {
				return go(curr-1);
			});

		if(o.btnNext)
			$(o.btnNext).click(function() {
				return go(curr+1);
			});

		function vis() {
			return li.slice(curr).slice(0,v);
		};
		
		function go(to) {
			if(!running) {
				if(to < 0) { // wrap around to last one before animating
					ul.css('left', -(originalItemCount*liSize)+"px");
					curr = originalItemCount + to;
				} else if(to>=itemCount) { // wrap around to first one before animating
					ul.css('left', -liSize + "px" );
					curr = to - originalItemCount;
				} else curr = to;

				running = true;

				ul.animate(
					{ left: -(curr*liSize) }, o.speed, o.easing,
					function() {
						running = false;
					}
				);
			}else{
				ul.stop();
				running=false;
				go(to);
			}
			return false;
		};
	});
};

function css(el, prop) {
	return parseInt($.css(el[0], prop)) || 0;
};
function width(el) {
	return  el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');
};
function height(el) {
	return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom');
};

})(jQuery);

$(function () {
	
	$("#carousel").jCarouselEvenLiter({
		speed: 500,
		btnNext: "#carousel .next a",
		btnPrev: "#carousel .previous a",
		start: Math.floor( Math.random() * $('#carousel .belt li').length )
	});

});

