var images = {
	intro: [
		{
			id:"schlossMitKirche"
		}
	],
	project: [
		{
			id:"ausbauprojekt1"
		},
		{
			id:"ausbauprojekt2"
		},
		{
			id:"luftaufnahme"
		}
	],
	verwalterhaus: [
		{
			id:"aussenansicht",
			c:"83, 142, 148, 165",
			alt:"Außenansicht"
		},
		{
			id:"wohnzimmer",
			c:"140, 71, 193, 124",
			alt:"Wohnzimmer"
		},
		{
			id:"schlafzimmer11",
			c:"254, 71, 307, 124",
			alt:"eines der vier Schlafzimmer im 1. Stock"
		},
		{
			id:"kueche",
			c:"210, 71, 244, 124",
			alt:"Küche im Erdgeschoss"
		},
		{
			id:"bad0",
			c:"211, 20, 244, 60",
			alt:"Badezimmer im Erdgeschoss"
		},
		{
			id:"schlafzimmer0",
			c:"140, 20, 193, 47",
			alt:"Schlafzimmer im Erdgeschoss"
		},
		{
			id:"flur",
			c:"191, 20, 212, 124",
			alt:"Flur"
		},
		{
			id:"schlafzimmer13",
			c:"254, 20, 307, 47",
			alt:"eines der vier Schlafzimmer im 1. Stock"
		},
		{
			id:"schlafzimmer14",
			c:"325, 20, 358, 47",
			alt:"eines der vier Schlafzimmer im 1. Stock"
		},
		{
			id:"bad1",
			c:"325, 45, 358, 72",
			alt:"Badezimmer im 1. Stock"
		},
		{
			id:"schlafzimmer12",
			c:"305, 71, 358, 124",
			alt:"eines der vier Schlafzimmer im 1. Stock"
		}
	],
	cook: [
		{
			id:"aussenansicht",
			c:"180, 45, 278, 71",
			alt:"Außenansicht"
		},
		{
			id:"schlafzimmer",
			c:"284, 70, 334, 130",
			alt:"Schlafzimmer"
		},
		{
			id:"wohnzimmer",
			c:"251, 70, 286, 112",
			alt:"Wohnraum"
		},
		{
			id:"bad",
			c:"220, 95, 253, 113",
			alt:"Bad"
		},
		{
			id:"kueche",
			c:"169, 70, 220, 97",
			alt:"Küche"
		},
		{
			id:"parkansicht",
			c:"157, 0, 213, 21",
			alt:"Ansicht des Schlosses vom Park aus mit der Wohnung im EG links"
		}
	],
	jvw: [
		{
			id:"aussenansicht",
			c:"104, 173, 172, 187",
			alt:"Außenansicht"
		},
		{
			id:"wohnzimmer",
			c:"238, 52, 322, 111",
			alt:"Wohnbereich"
		},
		{
			id:"schlafzimmer1",
			c:"238, 110, 280, 152",
			alt:"eines der vier Schlafzimmer"
		},
		{
			id:"kueche",
			c:"173, 52, 196, 111",
			alt:"Küche"
		},
		{
			id:"schlafzimmer2",
			c:"279, 111, 321, 152",
			alt:"eines der vier Schlafzimmer"
		},
		{
			id:"bad1",
			c:"218, 111, 240, 152",
			alt:"Bad im 1. Stock"
		},
		{
			id:"sitzecke",
			c:"173, 110, 196, 152",
			alt:"Essecke im Eingangsbereich"
		},
		{
			id:"schlafzimmer3",
			c:"320, 52, 363, 99",
			alt:"eines der vier Schlafzimmer"
		},
		{
			id:"bad0",
			c:"112, 52, 133, 91",
			alt:"Bad im Erdgeschoss"
		},
		{
			id:"schlafzimmer4",
			c:"361, 52, 382, 110",
			alt:"eines der vier Schlafzimmer"
		},
		{
			id:"pool",
			c:"177, 0, 256, 16",
			alt:"Schwimmbecken im Schlossgarten hinter der Wohnung"
		},
		{
			id:"sitzgruppe",
			c:"135, 29, 231, 52",
			alt:"Sitzgruppe im Garten hinter der Wohnung"
		},
		{
			id:"flur",
			c:"133, 51, 176, 112",
			alt:"Flur im Erdgeschoss"
		}
	]
};

var panoCoords = {
	verwalterhaus:"19, 103, 69, 149",
	cook:"47, 114, 97, 157",
	jvw:"0, 132, 49, 180"
};

function Slideshow(fewo) {
	this.action;
	this.fewo = fewo;
	this.imageArray = images[fewo];
	this.currentImage = "";
	
	this.init = function(imageArray) {
		if (typeof imageArray != "undefined") this.imageArray = imageArray;
		if (dojo.byId("map_grundriss")) {
			dojo.forEach(dojo.byId("map_grundriss").childNodes, function(node) {
				dojo.byId("map_grundriss").removeChild(node);
			});
			dojo.forEach(images[this.imageArray], function(imageData) {
				var newArea = dojo.byId("map_grundriss").appendChild(document.createElement("area"));
				newArea.setAttribute("shape","rect");
				newArea.setAttribute("alt",imageData.alt);
				//newArea.setAttribute("href","javascript:slideshow.stop('"+imageData.id+"');");
				newArea.setAttribute("coords", imageData.c);
				newArea.onmouseover = function() { slideshow.stop(imageData.id); };
				newArea.onmouseout = function() { slideshow.start(); };
			});
			// append panorama click area
			if (typeof(panoCoords[this.fewo]) != "undefined") {
				var newArea = dojo.byId("map_grundriss").appendChild(document.createElement("area"));
				newArea.setAttribute("shape","rect");
				newArea.setAttribute("alt","Panorama");
				newArea.setAttribute("href","javascript:NewWindow('./panoramas/panorama.php?fewo="+this.fewo+"','panorama','445','222','no');");
				newArea.setAttribute("coords", panoCoords[this.fewo]);
			}
		}
		this.start();
	}
	
	this.getNextImage = function(currImg) {
		var i;
		for(i=0; i<images[this.imageArray].length; i++) {
			if (currImg.id == images[this.imageArray][i].id) break;
		}
		return (i+1 >= images[this.imageArray].length) ? images[this.imageArray][0] : images[this.imageArray][i+1];
	}
	
	this.start = function() {
		if (typeof this.action != "undefined") window.clearInterval(this.action);
		if (this.currentImage == "") this.currentImage = images[this.imageArray][0];
		var nextImg = this.getNextImage(this.currentImage);
		dojo.byId("img1").setAttribute("src","./images/"+this.imageArray+"/"+nextImg.id+".jpg");
		this.action = window.setInterval(function() { slideshow.toggle(); },3500);
	}
	
	this.toggle = function() {
		var self = this;
		this.currentImage = this.getNextImage(this.currentImage);
		dojo.fadeOut({node: "img2", duration: 500, onEnd:function() {
			dojo.byId("img2").setAttribute("src",dojo.byId("img1").getAttribute("src"));
			// take your time fading in because IE6 would flicker
			dojo.fadeIn({node: "img2", duration: 1500, onEnd:function() {
				var nextImg = self.getNextImage(self.currentImage);
				dojo.byId("img1").setAttribute("src","./images/"+self.imageArray+"/"+nextImg.id+".jpg");
			}}).play();
		}}).play();

		
	}
	
	this.stop = function(id) {
		window.clearInterval(this.action);
		if (typeof id != "undefined") {
			dojo.byId("img2").setAttribute("src","./images/"+this.imageArray+"/"+id+".jpg");
			dojo.byId("img1").setAttribute("src","./images/"+this.imageArray+"/"+id+".jpg");
			dojo.fadeIn({node: "img2", duration: 1}).play();
			for(i=0; i<images[this.imageArray].length; i++) {
				if (id == images[this.imageArray][i].id) {
					this.currentImage = images[this.imageArray][i];
					break;
				}
			}
		}
	}

};