jQuery.noConflict();
(function($){
	
	$(document).ready(function(){
		var size = $('#carousel').children().size()
		var randomNumber = Math.round(Math.random() * (size +1));
	
		function setNavi( $c, $i ) {
				var title = $i.attr( 'alt' );
				$('#title').text( title );

				var current = $c.triggerHandler( 'currentPosition' );
				$('#pagenumber span').text( current+1 );

				/*var $prev = ($i.is(':first-child')) ? $c.children().last() : $i.prev();
				var small = $prev.attr('src').split('/large/').join('/small/');
				$('#prev').html('<img src="'+small+'" />');

				var $next = $i.next();
				var small = $next.attr('src').split('/large/').join('/small/');
				$('#next').html('<img src="'+small+'" />');*/
			}
		$(function() {
			$("#carousel").carouFredSel({
				width: 500,
				height: 374,
				items: {
					start: randomNumber,
					visible: 1
				},
				auto : {
					/*play: false,*/
					duration: 1000,
					pauseDuration : 40000,
					pauseOnHover: true
				},
				prev: '#prev',
				next: '#next',
				align: 'center',
				pagination: {
					container: '#pager span',
					anchorBuilder: function( nr, $img ) {
						var small = $img.attr('src').split('/large/').join('/small/');
						return '<a href="#" title="Go to image '+nr+'.">'+nr+'</a>';
					}
				},
				scroll: {
					onBefore: function( $oI, $nI ) {
						setNavi( $(this), $nI );
					}
					},
					onCreate: function( $vI ) {
						setNavi( $(this), $vI );
					}
			});
		});
	});
})(jQuery);
