$(document).ready(
	function(){
		$('a').click(function() {
			this.blur();
		});

		$.easing.easeOutQuart = function (x, t, b, c, d) {
			return -c * ((t=t/d-1)*t*t*t - 1) + b;
		};

		var $prev = $('#prev'),$next = $('#next'),$scrollj = $('div#scrolljail'),$items = $('div#scrolljail div.column');

		if($items.length > 1){
			$('#next').removeClass('noclick');
			$('#total').html($items.length);
			$scrollj.serialScroll({
				items:'div.column',
				prev:'#prev',
				next:'#next',
				axis:'x',
				start:0,
				duration:1200,
				force:true,
				stop:true,
				lock:false,
				cycle:false,
				easing:'easeOutQuart',
				jump: false,
				onBefore:function(e, elem, $pane, $items, pos){
					if( pos <= 0 ) {
						$('#next').removeClass('noclick');
						$('#prev').addClass('noclick');
					}
					else if( pos == $items.length-1 ) {
						$('#prev').removeClass('noclick');
						$('#next').addClass('noclick');
					}
					else{
						$('#next').removeClass('noclick');
						$('#prev').removeClass('noclick');
					}
					updateExternalNav(pos);
				}
			});
		}
		//IF GALLERY
		else if($('#mainImageLayer').length){
			$('#total').html(imageArray.length);
			
			$('#next').removeClass('noclick');
			if(loop)$('#prev').removeClass('noclick');
			
			$('#next').click(function () { 
				step(1);
				stopButton();
			});
			$('#prev').click(function () { 
				step(-1);
				stopButton();
			});

		}
		else{
			$('#next').addClass('noclick');
			$('#prev').addClass('noclick');
		}
		
	}
);


function updateExternalNav(pos){
	//alert(currentImage+1);
	$('#current').html(pos+1);
	if(window.headlineArray)$('#headline').html(headlineArray[pos]);
	if(window.captionArray)$('#caption').html(captionArray[pos]);
}
