// Easing equation, borrowed from jQuery easing plugin
// http://gsgd.co.uk/sandbox/jquery/easing/
jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

var show_x_image_columns = 5;
function initImages()
{
    $('#images_wrapper').serialScroll({
	    items:'dd',
	    prev:'#in_prev .ir',
	    next:'#in_next .ir',
	    offset:0, //when scrolling to photo, stop 230 before reaching it (from the left)
	    start:0, //as we are centering it, start at the 2nd
	    duration:1200,
	    force:false,
	    stop:true,
	    lock:false,
	    cycle:false, //don't pull back once you reach the end
	    easing:'easeOutQuart', //use this easing equation for a funny effect
	    jump: false, //click on the images to scroll to them
	    step: 1,
	    exclude: 4,
	    constant: false,
		onBefore: function(e, target, scroll, items, index)
		{
		    if(items.length - show_x_image_columns <= index)
		        $('#images_header_wrapper #in_next')[0].style.visibility = "hidden";
		    else
		        $('#images_header_wrapper #in_next')[0].style.visibility = "";
		    
		    if(index <= 0)
		        $('#images_header_wrapper #in_prev')[0].style.visibility = "hidden";
		    else
		        $('#images_header_wrapper #in_prev')[0].style.visibility = "";
		}
    });
}

var show_x_albums = 7;
function initAlbums()
{
	$('#albums_wrapper').serialScroll({
		items:'dd',
		prev:'#albums_wrapper_wrapper .an_prev',
		next:'#albums_wrapper_wrapper .an_next',
		offset:0, //when scrolling to photo, stop 230 before reaching it (from the left)
		start:0, //as we are centering it, start at the 2nd
		duration:1200,
		force:false,
		stop:true,
		lock:false,
		cycle:false, //don't pull back once you reach the end
		easing:'easeOutQuart', //use this easing equation for a funny effect
		jump: false, //click on the images to scroll to them
		step: 1,
		exclude: show_x_albums - 1,
		constant: false,
		onBefore: function(e, target, scroll, items, index)
		{
		    if(items.length - show_x_albums <= index)
		        $('#albums_wrapper_wrapper #an_next')[0].style.visibility = "hidden";
		    else
		        $('#albums_wrapper_wrapper #an_next')[0].style.visibility = "";
		    
		    if(index <= 0)
		        $('#albums_wrapper_wrapper #an_prev')[0].style.visibility = "hidden";
		    else
		        $('#albums_wrapper_wrapper #an_prev')[0].style.visibility = "";
		}
	});
}

jQuery(function( $ ){

    /**
     * No need to have only one element in view, you can use it for slideshows or similar.
     * In this case, clicking the images, scrolls to them.
     * No target in this case, so the selectors are absolute.
     */
	 
    initImages();
    
    initAlbums();
});