jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

jQuery(function( $ ){
	
	var $prev = $('a.prev'), 
		$next = $('a.next'); //next & prev button
	
	$('#featuredwrapper').serialScroll({
		target:'#featured',
		items:'li',
		prev:'a.prev',
		next:'a.next',
		axis:'x',
		duration:500,
		force:true,
		easing:'easeOutQuart',
		navigation:'#buttons li a',
		interval:5000, // It's the number of milliseconds to automatically go to the next
		onBefore:function( e, elem, $pane, $items, pos ) {
			
			e.preventDefault();
			
			if( this.blur ) {
				this.blur();
				}
			
			//$prev.add($next).fadeIn();
			
			if( pos == 0 ) {
				//$prev.fadeOut();
				}
			else if( pos == $items.length-1 ) {
				//$next.fadeOut();
				}
			
			$("#buttons ul li").removeClass('selected');
			$("#buttons ul li").eq(pos).addClass('selected');
			
			},
		
		onAfter:function( elem ) {
			
			}
		});
	
	
	$('.gallerywrapper').serialScroll({
		target:'.photo',
		items:'li',
		prev:'a.prev',
		next:'a.next',
		axis:'x',
		duration:500,
		force:true,
		easing:'easeOutQuart',
		//navigation:'#buttons li a',
		interval:0, // It's the number of milliseconds to automatically go to the next
		onBefore:function( e, elem, $pane, $items, pos ) {
			
			e.preventDefault();
			
			if( this.blur ) {
				this.blur();
				}
			
			//$prev.add($next).fadeIn();
			
			if( pos == 0 ) {
				//$prev.fadeOut();
				}
			else if( pos == $items.length-1 ) {
				//$next.fadeOut();
				}
			
			//$("#buttons ul li").removeClass('selected');
			//$("#buttons ul li").eq(pos).addClass('selected');
			
			},
		
		onAfter:function( elem ) {
			
			}
		});
		
		
	$(document).keyup(function(e){
        switch( e.keyCode ){
        	case 39://right (->)
        		$('#featuredwrapper').trigger('next');
        	break;
        	case 37://left (<-)
        		$('#featuredwrapper').trigger('prev');
        	break;
        }
    });
});
