// ----------------------------------------------------------------------------------------------------
// cms.js - CMS JavaScript Part
// ----------------------------------------------------------------------------------------------------
var GALLERY = {
	id : null,
	current : 0,
	images : null,
	details : null,
	width : null,
	height : null,
	// ------------------------------
	init : function(id,images,details) {
	// ------------------------------
		GALLERY.id = id;
		GALLERY.images = images;
		GALLERY.details = details;
	},
	// ------------------------------
	getImage : function() {
	// ------------------------------
		return document.getElementById("GalleryImage" + GALLERY.id);
	},
	// ------------------------------
	getText : function() {
	// ------------------------------
		return document.getElementById("GalleryText" + GALLERY.id);
	},
	// ------------------------------
	getBackButton : function() {
	// ------------------------------
		return document.getElementById("GalleryBackButton" + GALLERY.id);
	},
	// ------------------------------
	getNextButton : function() {
	// ------------------------------
		return document.getElementById("GalleryNextButton" + GALLERY.id);
	},
	// ------------------------------
	getLoopButton : function() {
	// ------------------------------
		return document.getElementById("GalleryLoopButton" + GALLERY.id);
	},
	// ------------------------------
	back : function() {
	// ------------------------------
		if (GALLERY.current > 0)
  				GALLERY.show(GALLERY.current - 1);
		return false;
	},
	// ------------------------------
	next : function() {
	// ------------------------------
		if (GALLERY.current < GALLERY.images.length - 1)
			GALLERY.show(GALLERY.current + 1);
		return false;
	},
	// ------------------------------
	loop: function() {
	// ------------------------------
		if (GALLERY.current < GALLERY.images.length - 1)
			GALLERY.show(GALLERY.current + 1);
		else
			GALLERY.show(0);
		return false;
	},
	// ------------------------------
	show : function(index) {
	// ------------------------------
		if (index > -1 && index < GALLERY.images.length &&
						  index != GALLERY.current) {
			GALLERY.current = index;
			if (img = GALLERY.getImage()) {
				img.src = GALLERY.images[GALLERY.current];
				// tbi img.onreadystatechange = {} und dann alles
				// untere im Eventhandler machen, sonst sind Texte 
				// und Knopfänderungen sichtbar, bevor das Bild geladen wurde!
				img.alt = GALLERY.details[GALLERY.current];
			}
			if (txt = GALLERY.getText())
				txt.innerHTML = GALLERY.details[GALLERY.current];
			if (but = GALLERY.getBackButton())
				but.style.display = (GALLERY.current < 1 ? 'none' : '');
			if (but = GALLERY.getNextButton())
				but.style.display = (GALLERY.current >= GALLERY.images.length - 1 ? 'none' : '');

		}
		return false;
	},
	// ------------------------------
	thumbOver : function(imageRef,src) {
	// ------------------------------
		imageRef.src = src;
	},
	// ------------------------------
	thumbOut : function(imageRef,src) {
	// ------------------------------
		imageRef.src = src;
	},
	// ----------------------------------------------------------------
	DIASHOW : {
	// ----------------------------------------------------------------
		imageRef : null,
		parentRef : null,
		images : null,
		currentIndex : 0,
		opacity : 1.0,
		pause : 5000,
		steps : 0.05,
		delay : 60,
		random : false,	// not implemented yet :(
		infinite : true,
		// ------------------------------
		next : function() {
		// ------------------------------
			if (!GALLERY.DIASHOW.images)
				return null;
				if (++GALLERY.DIASHOW.currentIndex >= GALLERY.DIASHOW.images.length) {
				if (!GALLERY.DIASHOW.infinite)
					return null;
				GALLERY.DIASHOW.currentIndex = 0;
			}
			return GALLERY.DIASHOW.images[GALLERY.DIASHOW.currentIndex];
		},
		// ------------------------------
		setOpacity : function(value) {
		// ------------------------------
			if (GALLERY.DIASHOW.imageRef) {
				GALLERY.DIASHOW.imageRef.style.filter = 'alpha(opacity=' + (value * 100) + ')';	// IE
				GALLERY.DIASHOW.imageRef.style.opacity = value;									// Gecko
			}
		},
		// ------------------------------
		fadeOut : function() {
		// ------------------------------
				if (GALLERY.DIASHOW.opacity > 0.0) {
				GALLERY.DIASHOW.setOpacity(GALLERY.DIASHOW.opacity -= GALLERY.DIASHOW.steps);
				window.setTimeout("GALLERY.DIASHOW.fadeOut()",GALLERY.DIASHOW.delay);
			}
			else if ((src = GALLERY.DIASHOW.next()) != null) {
				GALLERY.DIASHOW.setOpacity(GALLERY.DIASHOW.opacity = 0.0);
				GALLERY.DIASHOW.imageRef.src = src;
				window.setTimeout("GALLERY.DIASHOW.fadeIn()",GALLERY.DIASHOW.pause);
			}
		},
		// ------------------------------
		fadeIn : function() {
		// ------------------------------
			if (GALLERY.DIASHOW.opacity < 1.0) {
				GALLERY.DIASHOW.setOpacity(GALLERY.DIASHOW.opacity += GALLERY.DIASHOW.steps);
				window.setTimeout("GALLERY.DIASHOW.fadeIn()",GALLERY.DIASHOW.delay);
			}
			else if ((src = GALLERY.DIASHOW.next()) != null) {
				GALLERY.DIASHOW.setOpacity(GALLERY.DIASHOW.opacity = 1.0);
				GALLERY.DIASHOW.parentRef.style.background = 'url(' + src + ') no-repeat top left';
				window.setTimeout("GALLERY.DIASHOW.fadeOut()",GALLERY.DIASHOW.pause);
			}
		},
		// ------------------------------
		init : function(images,pause,delay,steps,offset,random,infinite) {
		// ------------------------------
			GALLERY.DIASHOW.images = images;
			GALLERY.DIASHOW.pause = pause;
			GALLERY.DIASHOW.delay = delay;
			GALLERY.DIASHOW.steps = steps;
			GALLERY.DIASHOW.currentIndex = offset;
			GALLERY.DIASHOW.random = random;
			GALLERY.DIASHOW.infinite = infinite;
		},
		// ------------------------------
		checkReferences : function() {
		// ------------------------------
			if (!GALLERY.DIASHOW.imageRef || !GALLERY.DIASHOW.parentRef) {
				GALLERY.DIASHOW.imageRef = document.getElementById("GalleryImage" + GALLERY.id);
				GALLERY.DIASHOW.parentRef = document.getElementById("DiashowContainer" + GALLERY.id);
				return false;
			}
			return true;
		},
		// ------------------------------
		start : function() {
		// ------------------------------
			// Referenzen pruefen und ggf. 1/2 Sekunde warten...
			if (!GALLERY.DIASHOW.checkReferences()) {
				window.setTimeout("GALLERY.DIASHOW.start()",500);
				return ;
			}
			var src = GALLERY.DIASHOW.next();
			if (src) {
				GALLERY.DIASHOW.parentRef.style.background = 'url(' + src + ') no-repeat top left';
				window.setTimeout("GALLERY.DIASHOW.fadeOut()",GALLERY.DIASHOW.pause);
			}
		}
	}
};
// ----------------------------------------------------------------------------------------------------
// end of gallery.js
// ----------------------------------------------------------------------------------------------------
