$(document).ready(function() {
	
	// Enable brochure carousel only if there are 3 or more items
	var brochures = $("#brochures ul li").size();
	
	if(brochures>2){
		
		$("#brochures").jCarouselLite({
				start: 0,
				btnNext: "#brochure-next",
				btnPrev: "#brochure-prev",
				mouseWheel: true,
				afterEnd: function(a){
					// keeping the focus on the element in the middle after every scroll
					setCurrent($(a[1]));
				}
		});
		
		setCurrent($('#brochures ul li').get(4));
		
	}else{
		// Disable left / right buttons
		$('#brochure-next,#brochure-prev').attr('class','disabled').unbind('click');
		setCurrent($('#brochures ul li').get(0));
	}
	
	// Mouse over actions for items
	$("#brochures li").bind({
		mouseover: function(){
			setCurrent($(this));
		}
	})
	
});

function setCurrent(target){
	$("#brochure-description").text($(target).find("img").attr('title'));
	$("#brochures img").removeClass('current');
	$(target).find("img").attr('class','current');
}
