/*
var diashow = new Diashow();

$(document).ready(function() {			
	diashow.go();
});
*/
function nextImage(o) {
	return function() {
		o.nextImage();
	}
}

function nextSlogan(o) {
	return function() {
		o.nextSlogan();
	}
}

function Diashow() {
	this.i = 0;
	this.iSlogan = 0;
	this.j = 15;
	this.jMax = 15;
	this.imageArray = new Array();
	this.imgEntryArray = new Array();
};

Diashow.prototype.nextImage = function(){

	if ($(this.imgEntryArray[this.i].img1).css("display") != "none") { 
		// case 1: img above is visible
		//
		
		// Is this the first image in the row?
		//
		if (this.i == 0) {
			// feed in the next image
			//
			this.imgEntryArray[this.i].img2.src = this.imageArray[this.j].src;
			this.j=(this.j==0?this.jMax:--this.j)			
		} else {
			// pick the visible image from the left
			//
			this.imgEntryArray[this.i].img2.src = this.imgEntryArray[this.i-1].img1.src;		
		}
		$(this.imgEntryArray[this.i].img1).fadeOut(2000);
	} else {
		// case 2: img below is visible
		//

		// Is this the first image in the row?
		//
		if (this.i == 0) {
			// feed in the next image
			//
			this.imgEntryArray[this.i].img1.src = this.imageArray[this.j].src;
			this.j=(this.j==0?this.jMax:--this.j)			
		} else {
			// pick the visible image from the left
			//
			this.imgEntryArray[this.i].img1.src = this.imgEntryArray[this.i-1].img2.src;		
		}
		$(this.imgEntryArray[this.i].img1).fadeIn(2000);
	}
	
	this.i = (this.i==3?0:++this.i);
	// $(slogan[0].children[this.i]).fadeIn("slow");
	setTimeout(nextImage(this), 2000);
};

Diashow.prototype.nextSlogan = function(){
	var slogan = $("div#slogan");
	$(slogan[0].children[this.iSlogan]).fadeOut("slow");
	this.iSlogan = (this.iSlogan==4?0:++this.iSlogan);
	$(slogan[0].children[this.iSlogan]).fadeIn("slow");
	setTimeout(nextSlogan(this), 10000);
};

Diashow.prototype.initImageArray = function() {
	for (var i = 1; i < 17; ++i) {
		var img = new Image();
		img.src = "img/head_neu/" + i + ".jpg";
		this.imageArray.push(img);
	}
	var imgEntry = $("div.img_entry");
	for (var i = 0; i < 4; ++i) {
		var img1 = imgEntry[i].children[0];
		var img2 = imgEntry[i].children[1];
		this.imgEntryArray.push({img1:img1, img2:img2});
	}
}

Diashow.prototype.go = function(){
	diashow.initImageArray();
	setTimeout(nextImage(this), 2000);
	setTimeout(nextSlogan(this), 10000);
}

