$(function(){
	$('a.noscript').removeClass('noscript').parent().hover(function(){
		$(this).find('a').stop().animate({opacity: 0}, 200);
	}, function(){
		$(this).find('a').stop().animate({opacity: 0.9}, 200);
	});
	$('#directory .slideshow').each(function(i){
		var slideshow = $(this);
		$(this).data('index', 0).data('length', $(this).find('ol li').length).append('<div class="disabled previous"><a href="#"><span>Back</span></a></div><div class="disabled next"><a href="#"><span>Next</span></a></div>').bind('slide', function(){
			$(this).find('ol').animate({marginLeft: (-898 * $(slideshow).data('index'))}, 750, 'easeOutCirc', function(){
				if($(slideshow).data('index') == 0){
					$(slideshow).find('.next, .previous').removeClass('disabled');
					$(slideshow).find('.previous').addClass('disabled');
				}else{
					if($(slideshow).data('index') == ($(slideshow).data('length') - 1)){
						$(slideshow).find('.next, .previous').removeClass('disabled');
						$(slideshow).find('.next').addClass('disabled');
					}else{
						$(slideshow).find('.next, .previous').removeClass('disabled');
					}				
				}
				$(slideshow).parent().find('.ticks ol li').removeClass('selection').parent().find('li').eq($(slideshow).data('index')).addClass('selection');
			});
		}).find('ol').width($(slideshow).find('ol li').length * 898);
		$(this).parent().find('.navigate a').each(function(){
			$(this).click(function(){
				if($(this).parent().hasClass('arrow-up')){
					var scrollTo = (i - 1);
				}else{
					var scrollTo = (i + 1);
				}
				$.scrollTo($('#directory .story').eq(scrollTo < 0 ? 0 : scrollTo), {duration: 1000});
				return false;				
			});
		});
		
		$(this).find('.next a').click(function(){
			var index = (($(slideshow).data('index') + 1) < ($(slideshow).data('length') - 1)) ? ($(slideshow).data('index') + 1) : ($(slideshow).data('length') - 1);
			$(slideshow).data('index', index).trigger('slide');
			return false;
		});
		
		$(this).find('.previous a').click(function(){
			var index = (($(slideshow).data('index') - 1) > 0) ? ($(slideshow).data('index') - 1) : 0;
			$(slideshow).data('index', index).trigger('slide');
			return false;			
		});

		for(tick=0; tick < $(slideshow).data('length'); tick++){
			$(slideshow).parent().find('.ticks ol').append('<li'+(tick == 0 ? ' class="selection"' : '')+'><a href="#!/"><span>'+tick+'</span></a></li>');
		}
		
		$(slideshow).parent().find('.ticks li a').click(function(){
			$(slideshow).data('index', $(this).find('span').html()).trigger('slide');
		});
		
		if($(slideshow).data('length') > 1){
			$(slideshow).find('.next').removeClass('disabled');
		}
	})
	
	//$('#container #content #directory ol li.story .excerpt div.text').highlightlines({ backgroundColor: '#ffffff', color: '#000000'});
	
	
	$('#share>li>ul').hide(); // needed to prevent CSS-only behaviour on first contact
$('#share>li').hover(
  function() {
    $(this).find('>ul').stop().height('auto').slideDown(250); // the height('auto') prevents the menu from memorizing an incorrect height-value forever when leaving the menu while the animation is running
  },
  function() {
    $(this).find('>ul').stop().slideUp(150);
  }
);


$(window).load(function() {
    $('#slider').nivoSlider({
        effect:'random', //Specify sets like: 'fold,fade,sliceDown'
        slices:15,
        animSpeed:500, //Slide transition speed
        pauseTime:3000,
        startSlide:0, //Set starting Slide (0 index)
        directionNav:true, //Next & Prev
        directionNavHide:true, //Only show on hover
        controlNav:true, //1,2,3...
        controlNavThumbs:false, //Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, //Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', //Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
        keyboardNav:true, //Use left & right arrows
        pauseOnHover:true, //Stop animation while hovering
        manualAdvance:false, //Force manual transitions
        captionOpacity:0.8, //Universal caption opacity
        beforeChange: function(){},
        afterChange: function(){},
        slideshowEnd: function(){}, //Triggers after all slides have been shown
        lastSlide: function(){}, //Triggers when last slide is shown
        afterLoad: function(){} //Triggers when slider has loaded
    });
});


$(document).ready(function(){
        $('#ticker').list_ticker({
                speed:7000,
                effect:'fade'
        })              
})

	
});
