/**
 *	linjeSlideshow
 *
 *	NB! krever jQuery & modernizr!
 *
 */
var linjeSlideshow = {
	current: 0,
	total: 5,
	delay: 4000,
	interval: null,
	validate: function (index) {
		while (index < 0) {
			index += this.total;
		}
		index %= this.total;
		return index;
	},
	go: function (index) {
		index = this.validate(index);
		$('#linje-slideshow .thumb, #linje-slideshow .slide').removeClass('current');
		$('#linje-slideshow .thumb-' + index + ', #linje-slideshow .slide-' + index).addClass('current');
		this.current = index;
	},
	next: function () {
		this.go(this.current+1);
	},
	prev: function () {
		this.go(this.current-1);
	},
	play: function () {
		try {
			clearInterval(this.interval);
		} catch (e) {}
		this.interval = setInterval(function () { linjeSlideshow.next(); }, this.delay);
	},
	pause: function () {
		try {
			clearInterval(this.interval);
		} catch (e) {}
	}
};

$(document).ready(function () {
	
	linjeSlideshow.play();
	$('#linje-slideshow .thumb').hover(function(){
		linjeSlideshow.pause();
		var index = this.className.match(/thumb-\d+/).toString().substr(6);
		linjeSlideshow.go(index);
	
	},function(){
	
		linjeSlideshow.play();
		
	});
	
	// mobile touch screen (no hover, so use click (touch) instead)
	$('#linje-slideshow .thumb').click(function(){
		linjeSlideshow.pause();
		var index = this.className.match(/thumb-\d+/).toString().substr(6);
		linjeSlideshow.go(index);
	});
	
}); 
