
;var Carousel = {
	threshold : 3,
	timer:undefined,
	timeout:5000,
	itemWidth:818,
	infoHeight:130,
	titleHeight:50,
	animated:false,
	prev: function(e){
		if (Carousel.animate == true) {return}
		if (e.preventDefault) {
			e.preventDefault();
			if (Carousel.timer) {
				clearTimeout(Carousel.timer);
			}
		}
		var a = $('.reference-item .active');
		if (a.prev().length) {
			Carousel.animate=true;
			a.removeClass('active').animate({left:Carousel.itemWidth+'px'}).prev().addClass('active').animate({left:"0px"});
			$('.reference-info .active').removeClass('active').animate({top:'-'+Carousel.infoHeight+'px'}).prev().addClass('active').animate({top:"0px"});
			$('.reference-title .active').removeClass('active').animate({top:Carousel.titleHeight+'px'}).prev().addClass('active').animate({top:"0px"},function() {Carousel.animate=false});
		}
	},
	next:function(e){
		if (Carousel.animate == true) {return}
		if (e.preventDefault) {
			e.preventDefault();
			if (Carousel.timer) {
				clearTimeout(Carousel.timer);
			}
		} else {
			//Carousel.timer = setTimeout(Carousel.next, Carousel.timeout);
		}
		var a = $('.reference-item .active');
		if (a.next().length) {
			Carousel.animate=true;
			a.removeClass('active').animate({left:'-'+Carousel.itemWidth+'px'}).next().addClass('active').animate({left:"0px"});
			$('.reference-info .active').removeClass('active').animate({top:Carousel.infoHeight+'px'}).next().addClass('active').animate({top:"0px"});
			$('.reference-title .active').removeClass('active').animate({top:'-'+Carousel.titleHeight+'px'}).next().addClass('active').animate({top:"0px"},function() {Carousel.animate=false});
		}
		if ((a.nextAll().length < Carousel.threshold) && ($('.reference-item').children().length < $('#ReferencesTotal').val())) {
			jQuery.get($('#ProjectPath').val() + '/portfolio-images/' + $('#ReferencesId').val() + '/page:' + (Math.ceil($('.reference-item').children().length / $('#ReferencesPageSize').val()) + 1), function(data){
				$('.reference-item').append(data);
			});
		}
	}
};

$(function(){
	$('#Ref-Left').click(Carousel.prev);
	$('#Ref-Right').click(Carousel.next);
});
