// http://stackoverflow.com/questions/962802/is-it-correct-to-use-javascript-array-sort-method-for-shuffling
if (!Array.prototype.shuffle) {
	Array.prototype.shuffle = function () {
		var tmp, current, top = this.length;
		if(top) while(--top) {
			current = Math.floor(Math.random() * (top + 1));
			tmp = this[current];
			this[current] = this[top];
			this[top] = tmp;
		}
		return this;
	};
}

(function ($) {

	// cnt = the last index number of slides "assets/slides/" folder.
	// limit = the number of slides to show. 
	//
	// You slides should be named "slides_XX.jpg" and all need to be
	// JPEG files. xx should be incremental, in terms of 01-99.
	// example: slide_09.jpg
	//
	// if you have a lot of slides, but only wnat to show X, then
	// you can set "limit" to be the number of slides to show.
	// example: you have 99 slides, but want to show 15,
	// 		cnt = 99, limit = 15
	// The slides are randomized, so only the first "limit" will be shown.
	
	var cnt = 7,
		limit = cnt;
		slides = [];
		
	$.initSlides = function() {
		var i;
		if (cnt && cnt >= 1) {
			for (i = 1; i < cnt; i++) {
				slides.push("slide_0" + i + ".jpg");
			}
			slides.shuffle();
		}
	}
	
	$.addSlides = function() {
		var i, $elm = $('#slideshow');
		if ($elm.length > 0) {
			for (i = 0; i < limit - 1; i++) {
				$elm.append('<img src="assets/slides/' + slides[i] + '"><br />');
			};
		}
	}
	
	$.initSlides();
	$.addSlides();
	$('#slideshow').cjFlashySlideShow({
		preset: "cubism"
	});
	
}(jQuery));
