$(function(){
	$('#slideshow').cycle({ 
		fx: 'fade', 
		speed: 500,
		timeout: 0,
		pager: '#footer',
		startingSlide: Math.ceil(Math.random( $('#slideshow li').length ))-1,
		pagerAnchorBuilder: function(index, DOMelement) {
			if( index == 0 ){
				return '<span><a href="#" class="first">'+(index+1)+'</a>|</span>'
			}else if( index+1 ==  $('#slideshow li').length  ){
				return '<span><a href="#" class="last">'+(index+1)+'</a></span>';
			}else{
				return '<span><a href="#">'+(index+1)+'</a>|</span>';
			}
			
		},
		before: function() {
			var tekst = $('#slideshow li:eq('+$('#slideshow li').index( $(this) )+') img').attr('alt');
			if( $('.content div').length ) {
				$('.content div').fadeOut( 500 , function(){
					$('.content div').remove();
					$('.content').append($('<div>'+ tekst +'</div>').hide());
					$('.content div').fadeIn();
				});
			}else{
				$('.content').append($('<div></div>').html(tekst).hide());
				$('.content div').fadeIn();
			}
		}

	});
	if($('#slideshow li').length == 1){
		$('.content').append($('<div>'+ $('#slideshow li img').attr('alt') +'</div>'));
	}
	var ss = 0;
	if($('div#sidebar ul a.selected').length > 0){
		ss = $('div#sidebar ul').index( $('div#sidebar ul a.selected').parents('ul') );
	}
	$('div#sidebar').cycle({ 
		fx: 'scrollVert', 
		speed: 500,
		timeout: 0,
		startingSlide: ss,
		slideExpr: 'ul',
		next: 'a.nav-down', 
    	prev: 'a.nav-up'
	});
});

