
var daInterval = null;
$.fn.onearticlerotator = function() {


	/* ----------------------------- MOUSE ABSOLUTE-MODE

	//hide em
	$("img", this).hide();
	$($("img", this)[0]).show();


	$(this).bind("mousemove", function(e) {

		var imgs = $("img", this);

		//get subimages
		var c = imgs.length;

		//get pos
		var x = e.pageX - $(this).offset().left;

		//get size
		var w = $(this).width()

		//get actual
		var a = Math.floor(x/(w/c));

		var newimg = imgs[a];

		var visimg = $("img:visible", this)[0];

		if ( visimg != newimg ) {
			imgs.each(function() {

				if (this == visimg) {
					$(this).css("z-index", 2);
					$(this).fadeOut(300);
				} else	if (this == newimg) {
					$(this).css("z-index", 1);
					$(this).show();
				} else {
					$(this).hide();
				}

			});
		}


	}); */

	/* ----------------- MOUSE-ROLL-MODE --------------------- */


	
	$(this).each(function(){

		var changetime = 900;

		var actual = 0;
		var node = this;

		var autoswitcharticle = function() {
			var imgs = $("img", node);

			if (imgs.length > 1) {
				var newidx = actual + 1;
				if (newidx >= imgs.length) { newidx = 0; }

				var oldimg = $(imgs[actual]);
				var newimg = $(imgs[newidx]);

				newimg.css("z-index", 1);
				oldimg.css("z-index", 2);

				newimg.show();
				oldimg.fadeOut(300);

				actual = newidx;
			}
		};

		$(this).bind("mouseenter", function(e) {
			clearInterval(daInterval);			
			daInterval = setInterval( function() { autoswitcharticle() }, changetime );
			
		});



		
		$(this).bind("mouseleave", function(e) {
			clearInterval(daInterval);			

			/*/fade zurück zum anfang
			if ( actual != 0 ) {
				var imgs = $("img", node);

				if($(imgs[0]).css("display") != "block") {

					var oldimg = $(imgs[actual]);
					var newimg = $(imgs[0]);

					newimg.css("z-index", 1);
					oldimg.css("z-index", 2);

					newimg.show();
					oldimg.fadeOut(300);

				}
			
				actual = 0;
			}*/

			
			$("img", node).each(function(i) {

				if (i == 0) {
					$(this).stop();
					$(this).css({ "opacity": 1 });
					$(this).show();
				} else {
					$(this).fadeOut(300);
				}				
			});
			
			actual = 0;
			


		});

		

	});

    return this;
};

