function startSlideshow(){
	
	// CHECKS THE IMAGE GALLERY, LAUNCHES A ASYNCHRONOUS SLIDESHOW
	var i = 1;       
	var n = images_full.length;	
	var indeximages = n - 1;
	var nextimage = '';

	if (indeximages > 0){
		// MULTIPLE IMAGES
		jQuery.whileAsync({
        	delay: 5000, // 1sec = 1000
        	bulk: 0,
        	test: function() { return i <= n },
        	loop: function()
        	{ 
                nextimage = i - 1;
                showImage(nextimage);
                if (i == n){
                i = 1;
                } else {i++;}
                
        	},
       	 	end: function()
        	{ 
			// nothing to do..	
        	}
		});
	} else {
	showImage(0);
	}
};

function showImage(id) {
	// LOAD/CREATE IMG
	$('#imgplaceholder').addClass('loading');
	$('#imgplaceholder img').fadeOut("fast");
	$('#imgplaceholder img').remove();
	var img = new Image();
	$(img).load(function () {
		$(this).hide();
		var iwidth = this.width;
		var iheight = this.height;
		$(this).css({width: iwidth,height: iheight});
		$('#imgplaceholder').removeClass('loading')
		$('#imgplaceholder').append(this)
		$(this).fadeIn();
	}).error(function () {
		// nothing to do..	
	}).attr('src', images_full[id]);
};

function makeMenuActive(the_cat){
$("#menu li.cat-item-"+the_cat).addClass('active');
}


function checkNextButton(the_cat){
	var appel = $(".next a").length;
	if (appel == 0){
		
		var nextcat;
		if (the_cat == 3){
			var nextcat = "http://www.centomani.nl/cms/portfolio/illustratie";
		}
		if (the_cat == 4){
			var nextcat = "http://www.centomani.nl/cms/portfolio/webdesign";
		}
		if (the_cat == 5){
			var nextcat = "http://www.centomani.nl/cms/portfolio/overig-werk";
		}
		if (the_cat == 6){
			var nextcat = "http://www.centomani.nl/cms/contact";
		}		

			var nextbutton = '<a href="'+nextcat+'">Volgende&nbsp;&nbsp;&nbsp;></a>';
			$("#navi .next").html(nextbutton);
	}
}

function checkPrevButton(the_cat){
	var appel = $(".prev a").length;
	if (appel == 0){

		var prevcat;

		if (the_cat == 3){
			var prevcat = "http://www.centomani.nl/cms/";
		}			
		if (the_cat == 4){
			var prevcat = "http://www.centomani.nl/cms/portfolio/grafisch-ontwerp";
		}
		if (the_cat == 5){
			var prevcat = "http://www.centomani.nl/cms/portfolio/illustratie";
		}
		if (the_cat == 6){
			var prevcat = "http://www.centomani.nl/cms/portfolio/webdesign";
		}
				var prevbutton = '<a href="'+prevcat+'"><&nbsp;&nbsp;&nbsp;Vorige</a>';
				$("#navi .prev").html(prevbutton);
	}
}

function alignNext(){
	
	var appel = $(".prev a").length;
	if (appel == 0){
		$("#navi .prev").remove();
		$("#navi").addClass("onlynext");
	}
}

function fixContentWidth(){
	$("#content").css({width: 210});
}


// *********** ON HTML DOM READY ***********
$(document).ready(function(){
	startSlideshow();
});
