(function($){
	$.fn.home = function()
	{
		this.each(function(){

			$(this).find('ul').children().find('a.teaser').mouseenter(show);
			$(this).find('ul').children().find('a.teaser').mouseleave(hide);

			var current = 0;
			var images = $(this).find('div.hometeaser_images a');
			var interval_id = 0;
			var ref = this;

			if (images.length > 1) {
				interval_id = setInterval(next_image, 5200);
			}

			function next_image() {
				var next;
				if (current >= images.length - 1) {
					next = 0;
				} else {
					next = current + 1;
				}
				//$(images[current]).fadeTo(1200, 0);
				$(images[current]).fadeOut(1200);
				$(images[next]).fadeTo(2500, 1);
				current = next;
			}


			function show() {
                //console.log('enter');
				// slideshow stop
				clearInterval(interval_id);
				// verlauf
				$(this).parent().find('img').stop(1).fadeTo(300, 1);
				// alle
				$(images).stop(1).fadeTo(300, 0);
				// neues
				var id = this.id.split('-').pop();
				$('#hometeaser_image-'+id).stop(1).fadeTo(600, 1);
				
			}

			function hide() {
                //console.log('leave');
				// verlauf
				$(this).parent().find('img').stop(1).fadeTo(100, 0);
				// alle
				//$(images).stop(1).fadeTo(900, 0);
				$(images).stop(1).fadeOut(500);
				// default rein
				$('#hometeaser_image-default').stop(1).fadeTo(1100, 1);
				// slideshow starten
				current = 0;
				interval_id = setInterval(next_image, 3260);
			}
			

		})

	}
})(jQuery);
