
function fm_slide() {

	var images = new Array();
	var time_ms = new Array();
	var links = new Array();
	var banner_count = 0;		// Anzahl aller Banner
	var banner_position = 0;	// Momentane Position (0-basierend)
	var newI1;					// Image1
	var newI2;					// Image2
	var newC1;					// Container1
	var newC2;					// Container2
	var newL1;					// Link 1
	var newL2;					// Link 2
	var width;
	var height;
	
	var schrittweite = 3;
	var timeperstep = 5;
	
	function setSchrittweite($value) {
		schrittweite = $value;
	}
	
	function setTimePerStep($value) {
		timeperstep = $value;
	}
	
	function addBanner($image, $time_ms, $link) {
		images[banner_count] = $image;
		time_ms[banner_count] = $time_ms;
		links[banner_count] = $link;
		banner_count+=1;
	}
	
	function init($container, $width, $height) {
		// DIV-Container initalisieren
		this.width = $width;	// wird später wieder benötigt
		this.height = $height;	// wird später wieder benötigt
		$container.style.width = $width + "px";
		$container.style.height = $height + "px";
		//$container.style.border = '1px solid red';
		$container.style.position = 'absolute';
		$container.style.backgroundColor = '#EC4412';
		$container.style.overflow = 'hidden';
		
		// Im Container zwei weitere DIVs anlegen. Dort hinein zwei Images anlegen.
		// Container 1 im Hauptcontainer linksbündig positionieren.
		// Container 2 direkt rechts neben dem Hauptcontainer
		this.newC1 = document.createElement("div");
		this.newC1.style.backgroundColor = '#EC4412';
		//this.newC1.style.border = '1px solid green';
		this.newC1.style.width = $width + "px";
		this.newC1.style.height = $height + "px";
		this.newC1.style.textAlign = 'center';
		this.newC1.style.marginTop = "0px";
		this.newC1.style.marginLeft = "0px";
		this.newC1.style.position = 'absolute';
		$container.appendChild(this.newC1);

		this.newC2 = document.createElement("div");
		this.newC2.style.backgroundColor = '#EC4412';
		//this.newC2.style.border = '1px solid blue';
		this.newC2.style.width = $width + "px";
		this.newC2.style.height = $height + "px";
		this.newC2.style.textAlign = 'center';
		this.newC2.style.marginTop = "0px";
		this.newC2.style.marginLeft = ($width + 1) + "px";
		this.newC2.style.position = 'absolute';
		$container.appendChild(this.newC2);
		
		// Links erstellen
		this.newL1 = document.createElement("a");
		this.newL1.target = '_self';
		this.newL2 = document.createElement("a");
		this.newL2.target = '_self';
		
		// Images erstellen und dem Link hinzufügen
		this.newI1 = document.createElement("img");
		this.newI1.border = 0;
		//this.newI1.height = $height;
		this.newL1.appendChild(this.newI1);
		
		this.newI2 = document.createElement("img");
		this.newI2.border = 0;
		//this.newI2.height = $height;
		this.newL2.appendChild(this.newI2);		
		
		// und diese dem Container hinzufügen
		this.newC1.appendChild(this.newL1);
		this.newC2.appendChild(this.newL2);

		// Bild 1 und Bild 2 in die Images laden ...
		this.loadimages();
		
		// ... und Austausch-Timer starten
		thisObj = this;
		setTimeout(function() { thisObj.slide.call(thisObj); }, time_ms[0]);		
	}
	
	function loadimages() {
		var b1 = banner_position;
		var b2 = banner_position + 1;
		if (b2 > (banner_count - 1)) {
			b2 = 0;
		}
		this.newI1.src = images[b1];
		this.newI2.src = images[b2];	
		
		if (links[b1]) {
			this.newL1.href = '?id='+links[b1];
			this.newL1.target = '_self';
		} else {
			this.newL1.href = 'javascript: void(0)';
			this.newL1.target = '';
		}

		if (links[b2]) {
			this.newL2.href = '?id='+links[b2];
			this.newL2.target = '_self';
		} else {
			this.newL2.href = 'javascript: void(0)';
			this.newL2.target = '';
		}
	
	}
	
	function slide() {
		// Die Sliding-Funktion
		var abstand = this.newC2.style.marginLeft;
		abstand = parseInt(abstand);

		if (abstand > 0) {
			// Images sind nicht deckungsgleich, dann um x Pixel nach links schieben
			this.newC2.style.marginLeft = (abstand - schrittweite) + "px";
			this.newC1.style.marginLeft = (abstand - schrittweite) - this.width + "px";
			// Slide-Timer erneut starten
			thisObj = this;
			setTimeout(function() { thisObj.slide.call(thisObj); }, timeperstep);	
		} else {
			// Images sind deckungsgleich (Slide beendet)
			// in Image1 (unten) das Image2 (oben) laden ...
			this.newI1.src = this.newI2.src;
			// ... und Image1 und Image2 wieder nach rechts schieben
			this.newC1.style.marginLeft = 0;
			this.newC2.style.marginLeft = (this.width + 1) + "px";
			
			// Bannerposition erhöhen ...
			banner_position = banner_position + 1
			if (banner_position >= banner_count) { // >= da banner_position 0-basierend
				banner_position = 0;
			}
					
			// Neue Banner laden
			this.loadimages();
			
			//... und wieder Austausch-Timer starten
			thisObj = this;
			setTimeout(function() { thisObj.slide.call(thisObj); }, time_ms[banner_position]);			
		}		
	}
	
	this.addBanner = addBanner;
	this.init = init;
	this.slide = slide;
	this.loadimages = loadimages;
	this.setSchrittweite = setSchrittweite;
	this.setTimePerStep = setTimePerStep;
	
}
