// slider system


var slider = (function() {
    var current = 0;
    var WIDTH = 780;
    var sliderContainer, scrollbox, liCount;
    
    
    function init() {
    	sliderContainer = $("#slider");
    	scrollbox = $("#slider-scrollbox");
    	liCount = sliderContainer.find("ul").eq(0).children().length;
    	    	
    	sliderContainer.find("#slider-navbox").css({ display: "block" });
    	
    	goToCurrent();
    };
    
    function goTo(what) {
    	switch (what) {
    		case "previous":
		    	current--;
    		break;
    		case "next":
    			current++;
    		break;
    		case "archive":
    			current = liCount - 1;
    		break;
    		default:
    			if (typeof what === "number") {
    				current = what;
    			}
    		break;
    	}
    	
    	current = Math.max(0, Math.min(liCount - 1, current));
    	
    	goToCurrent();
    };
    
    function goToCurrent() {
    	var visible = [];
    	if (!current) {
			visible = ['archive-l', 'next'];
    	}
    	else if (current == liCount - 2) {
			visible = ['previous', 'archive-r'];
    	}
    	else if (current >= liCount - 1) {
			visible = ['previous'];
			
    	}
    	else {
			visible = ['previous', 'next'];
    	}
    	$("#slider-navbox *").css({ display: "none" });
    	$("#slider-navbox ." + visible.join(', #slider-navbox .')).css({ display: "" });
    	
    	if (current >= liCount - 1) {
    		sliderContainer.find("h3").html("Overzicht");
    	}
    	else {
    		sliderContainer.find("h3").html("Impressies");
    	}
    	
    	scrollbox.animate({ left: (-WIDTH * current) + "px" });
    };

    return {
    	init: init,
    	goTo: goTo
    }
})();


$(slider.init);


