﻿window.THESEUSIT = function(elm) {

	var slideItems 	= $(elm).find('li');
	var firstItem 	= $(elm).find('li:first');
	var lastItemID 	= $(elm).find('li:last img').attr('src');
	var currentItemID, teaserLoop;	
	
	firstItem.addClass('cur');			
	var currentItem = $(elm).find(' li.cur');
	
	var showNextElement = function () {
		currentItemID = $(elm).find(' li.cur img').attr('src');
		currentItem.removeClass('cur');
		
		if( currentItemID === lastItemID){
			currentItem = firstItem;
		}else{
			currentItem = currentItem.next();
		}
		currentItem.addClass('cur');
	};
	
	var startTeaserLoop = function ()  {
		teaserLoop = window.setInterval(showNextElement, 3000);
	};
	
	var stopTeaserLoop = function () {
		window.clearInterval(teaserLoop);
	};
	
	$(elm).hover(
        function () {
			stopTeaserLoop();
        },
        function () {
			startTeaserLoop();
        }
    );
	
	startTeaserLoop();
	
};	

$(document).ready(function() {

	$('.imgTeaser').each(function(){
		this.slider =  THESEUSIT(this); 
	})

});	