var morphInterval;
var bigImageInterval;

var intervalDuration = 1000;
var imageWidth = 95;
var imageHeight = 95;
var defaultOpacity = 0.5;
var num_firstImages = 10;
var backgroundColors = new Array('#ffffff','#f2f2f2','#d9dadb','#f2efda','#d2c984');
var num_backgroundColors = backgroundColors.length;

var files;
var files2;

var bigImage = false;


var usedFiles = 0;
var usedFiles2 = 0;
var dontShowFiles = 0;


// PHP äquivalent
function in_array(needle, haystack, strict) {
	for(var i = 0; i < haystack.length; i++) {
		if(strict) {
			if(haystack[i] === needle) {
				return true;
			}
		} else {
			if(haystack[i] == needle) {
				return true;
			}
		}
	}

	return false;
}

// Zufallszahl ermitteln, [Maximalwert, nicht erlaubte Zahlen]
function getRandomNumber(maxValue, forbidden){
	var number = Math.floor(Math.random()*maxValue);
	while(in_array(number,forbidden)){
			number = Math.floor(Math.random()*maxValue);
	}
	return number;
}

function getIndexOfValue(value, arr){
	for(var i=0;i<arr.length;i++){
		if(arr[i].toLowerCase() == value.toLowerCase()){
			return i;
		}
	}
	return -1;
}

// soll verhindern, dass eine Farbe mehrmals im Umkreis auftritt "den Zufall ordnen :-)"
function getAllowedColors(rowNo, colNo, rows){
	var forbiddenValues = new Array();
	var cell;
	var overlay;
	var colorIndex;
	switch(rowNo){
		case 0:
			switch(colNo){
				case 0:
					cell = rows[rowNo].getChildren('td')[colNo+1];
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
					forbiddenValues.push(colorIndex);
				break;
				case 4:
					cell = rows[rowNo].getChildren('td')[colNo-1];
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
					forbiddenValues.push(colorIndex);
				break;
				default:
					cell = rows[rowNo].getChildren('td')[colNo-1];
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
					cell = rows[rowNo].getChildren('td')[colNo+1];
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
				break;
			}
		break;
		case 2:
			switch(colNo){
				case 0:
					cell = rows[rowNo].getChildren('td')[colNo+1];
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
					cell = rows[rowNo+1].getChildren('td')[colNo];
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
				break;
				case 4:
					cell = rows[rowNo].getChildren('td')[colNo-1];
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
					cell = rows[rowNo+1].getChildren('td')[colNo];
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
				break;
				default:
					cell = rows[rowNo].getChildren('td')[colNo-1];
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
					cell = rows[rowNo].getChildren('td')[colNo+1];
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
					cell = rows[rowNo+1].getChildren('td')[colNo];
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
				break;
			}
		break;
		case 3:
			switch(colNo){
				case 0:
					cell = rows[rowNo].getChildren('td')[colNo+1]; // Zelle rechts
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
					cell = rows[rowNo+1].getChildren('td')[colNo]; // Zelle drunter
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
					cell = rows[rowNo-1].getChildren('td')[colNo]; // Zelle drüber
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
				break;
				case 4:
					cell = rows[rowNo].getChildren('td')[colNo-1]; // Zelle links
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
					cell = rows[rowNo+1].getChildren('td')[colNo]; // Zelle drunter
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
					cell = rows[rowNo-1].getChildren('td')[colNo]; // Zelle drüber
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
				break;
				default:
					cell = rows[rowNo].getChildren('td')[colNo-1]; // Zelle links
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
					cell = rows[rowNo].getChildren('td')[colNo+1]; // Zelle rechts
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
					cell = rows[rowNo+1].getChildren('td')[colNo]; // Zelle drunter
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
					cell = rows[rowNo-1].getChildren('td')[colNo]; // Zelle drüber
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
				break;
			}
		break;
		case 4:
			switch(colNo){
				case 0:
					cell = rows[rowNo].getChildren('td')[colNo+1]; // Zelle rechts
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
					cell = rows[rowNo-1].getChildren('td')[colNo]; // Zelle drüber
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
				break;
				case 4:
					cell = rows[rowNo].getChildren('td')[colNo-1]; // Zelle links
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
					cell = rows[rowNo-1].getChildren('td')[colNo]; // Zelle drüber
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
				break;
				default:
					cell = rows[rowNo].getChildren('td')[colNo-1]; // Zelle links
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
					cell = rows[rowNo].getChildren('td')[colNo+1]; // Zeller rechts
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
					cell = rows[rowNo-1].getChildren('td')[colNo]; // Zelle drüber
					overlay = cell.getChildren('div')[0].getChildren('div')[1];
					colorIndex = getIndexOfValue(overlay.getStyle('background-color'), backgroundColors);
					forbiddenValues.push(colorIndex);
				break;
			}
		break;
		default:
		break;
	}
	return getRandomNumber(num_backgroundColors, forbiddenValues);
}

// Overlay einblenden
function setOverlay(rows){
	// zufällige Zeile ermitteln
	var num_rows = rows.length;
	var randomRow = getRandomNumber(num_rows, new Array(1,1));

	// zufällige Spalte ermitteln
	var cols = rows[randomRow].getChildren('td');
	var num_cols = cols.length;
	if(randomRow == 2){
		var forbiddenFields = new Array(2,2);
	}else{
		var forbiddenFields = new Array();
	}
	var randomCol = getRandomNumber(num_cols, forbiddenFields);
	
	var column = cols[randomCol];
	// zufällige Hintergrundfarbe ermitteln
	var randomColor = getAllowedColors(randomRow, randomCol, rows);
	var color = backgroundColors[randomColor];

	var cell = column.getChildren('div')[0];
	var overlay = cell.getChildren('div')[1];
	if(overlay.getParent('td').id != 'bigImageBox'){
		if(column.get('rel') != null){

		}else{
			overlay.get('morph').start( { 'opacity': 0 } ).chain(
				function(){
					this.start( { 'background-color': [color,color], 'opacity': defaultOpacity } );
				}
			);
		}
	}else{
		overlay.get('morph').start( { 'opacity': 0 } );
	}
}

function resetImages(arr, mark){
	var num_elements = arr.length;
	for(var i=0;i<num_elements;i++){
		if(arr[i].get('rel') == 'dont_show'){
			arr[i].set('rel', mark);
		}
	}
}

// soll verhindern, dass Bilder mehrfach angezeigt werden
function getAllowedImages(arr, mark){
	var num_elements = arr.length;
	var allowedIndizes = new Array();
	var allIndizes = new Array();
	for(var i=0;i<num_elements;i++){
		allIndizes.push(i);
		if(arr[i].get('rel') == mark){
			allowedIndizes.push(i);
		}
	}
	if(!(allowedIndizes.length > 0)){
		resetImages(arr, mark);
		allowedIndizes = allIndizes;
	}
	return allowedIndizes;
}

// dateinamen der Bilder aus dem img-Tag im div ziehen
function getFileName(divElement){
	var fileDiv = divElement.getChildren('div')[0];
	var file = fileDiv.getChildren('img')[0];
	var filePath = file.src.split('/');
	return filePath[(filePath.length-1)];
}

// kleine Bilder einblenden
function setSmallImage(rows){
	var num_rows = rows.length;
	var randomRow = getRandomNumber(num_rows, new Array(1,(rows.length-1)));

	var allowedImageIndizes = getAllowedImages(files, 'not_used');
	var randomImage = getRandomNumber(allowedImageIndizes.length, new Array());
	var imageIndex = allowedImageIndizes[randomImage];

	// Dateinamen herausfiltern
	var fileObjectDiv = files[imageIndex];
	var fileName = getFileName(fileObjectDiv);

	// Bild einblenden
	var cols = rows[randomRow].getChildren('td');
	var num_cols = cols.length;
	if(randomRow == 2){
		var forbiddenFields = new Array(2,2);
	}else{
		var forbiddenFields = new Array();
	}
	var randomCol = getRandomNumber(num_cols, forbiddenFields);
	
	// zu viele Bilder innerhalb eines bestimmten bereiches vermeiden
	while(checkImagePosition(randomRow, randomCol, rows) < 0){
		randomRow = getRandomNumber(num_rows, new Array(1,(rows.length-1)));

		allowedImageIndizes = getAllowedImages(files, 'not_used');
		randomImage = getRandomNumber(allowedImageIndizes.length, new Array());
		imageIndex = allowedImageIndizes[randomImage];

		// Dateinamen herausfiltern
		fileObjectDiv = files[imageIndex];
		fileName = getFileName(fileObjectDiv);

		// Bild einblenden
		cols = rows[randomRow].getChildren('td');
		num_cols = cols.length;
		if(randomRow == 2){
			forbiddenFields = new Array(2,2);
		}else{
			forbiddenFields = new Array();
		}
		randomCol = getRandomNumber(num_cols, forbiddenFields);
	}
	
	var column = cols[randomCol];
	var cell = column.getChildren('div')[0];
	var image = cell.getChildren('div')[0];
	if(column.get('rel') != null){
		files[column.get('rel')].set('rel','not_used');
		column.set('rel',null);
		image.get('morph').start( { 'opacity': 0 } );
	}else{
		column.set('rel',imageIndex);
		image.get('morph').start( { 'opacity': 0 } ).chain(
			function(){
				fileObjectDiv.set('rel','used');
				image.style.backgroundImage = 'url(index.php?rex_resize='+imageWidth+'c__'+imageHeight+'h__'+fileName+')';
				this.start( { 'opacity': 1 } );
			}
		);
	}
}

// kleine Bilder in der letzten Zeile einbinden, diese haben kein großes Bild mit Zitat und dürfen auch nur in der letzten Zeile auftreten
function setSpecialImage(rows, randomRow){
	var allowedImageIndizes = getAllowedImages(files2, 'not_used');
	var randomImage = getRandomNumber(allowedImageIndizes.length, new Array());
	var imageIndex = allowedImageIndizes[randomImage];

	// Dateinamen herausfiltern
	var fileObjectDiv = files2[imageIndex];

	var fileName = getFileName(fileObjectDiv);

	var imageFile = 'url(index.php?rex_resize='+imageWidth+'c__'+imageHeight+'h__'+fileName+')';
	// var imageFile = 'url(files/'+fileName+')';


	var cols;
	var num_cols;
	var randomCol;
	var column;
	var cell;
	var tempFile;
	// Bild einblenden
	var cols = rows[rows.length-1].getChildren('td');
	var num_cols = cols.length;
	var randomCol = Math.floor(Math.random()*num_cols);
	var column = cols[randomCol];
	var cell = column.getChildren('div')[0];
	var image = cell.getChildren('div')[0];
	if(column.get('rel') != null){
		files2[column.get('rel')].set('rel','not_used');
		column.set('rel',null);
		image.get('morph').start( { 'opacity': 0 } );
	}else{
		column.set('rel',imageIndex);
		image.get('morph').start( { 'opacity': 0 } ).chain(
			function(){
				fileObjectDiv.set('rel','used');
				image.style.backgroundImage = imageFile;
				this.start( { 'opacity': 1 } );
			}
		);
	}
}

var softedImages = new Array();

function softenSmallImages(){
	var overlays = $$('.overlay');
	var num_overlays = overlays.length;
	var overlay;
	for(var i=0;i<num_overlays;i++){
		overlay = overlays[i];
		overlay.get('morph').start( { 'opacity': 0.9 } );
	}
}

function resetSoftedImages(){
	var overlays = $$('.overlay');
	var num_overlays = overlays.length;
	var overlay;
	for(var i=0;i<num_overlays;i++){
		overlay = overlays[i];
		overlay.get('morph').start( { 'opacity': defaultOpacity } );
	}
}

// großes Bild mit Zitat einblenden
function showBigImage(){
	if(bigImage){
		resetSoftedImages();
		bigImage = false;
		$('imageBoxDescription').get('morph').start( { 'opacity': 0 } ).chain(
			function(){
				var fx = function(){
					$('imageBoxDescription').style.backgroundImage = 'url(files/willkommen_1.gif)';
					$('imageBoxDescription').removeEvents('click');
					$('imageBoxDescription').addEvent('click',function()
					{
						window.location = '1-0-';
					}
					);
					$('imageBoxDescription').get('morph').start( { 'opacity': 1 } );
				}
				fx.delay(1000);
			}
		);
		morphInterval = window.setInterval('startMorphs()',intervalDuration);
	}else{
		var allowedImageIndizes = getAllowedImages(files, 'not_used');
		var randomImage = getRandomNumber(allowedImageIndizes.length, new Array());
		var imageIndex = allowedImageIndizes[randomImage];

		var fileObjectDiv = files[imageIndex];
		var fileDiv = fileObjectDiv.getChildren('div')[1];
		var file = fileDiv.getChildren('img')[0];
		var filePath = file.src.split('/');
		var fileName = filePath[(filePath.length-1)];
		var siteUrl = file.alt;

		var fx = function(){
			$('imageBoxDescription').get('morph').start( { 'opacity': 0 } ).chain(
				function(){
					var fx2 = function(){
						$('imageBoxDescription').removeEvents('click');
						$('imageBoxDescription').style.backgroundImage = 'url(files/'+fileName+')';
						$('imageBoxDescription').addEvent('click',
							function(){
								window.location = siteUrl;
							}
						);
						$('imageBoxDescription').get('morph').start( { 'opacity': 1 } );
					}
					fx2.delay(500);
				}
			);	
		}
		fx.delay(1);
		softenSmallImages();
		fileObjectDiv.set('rel','dont_show');
		bigImage = true;
		clearInterval(morphInterval);
	}
}

// Zufallsbild bestimmen
function getRandomImage(rows){
	var num_rows = rows.length;
	var randomRow = getRandomNumber(num_rows, new Array(1));

	if(randomRow == (num_rows-1)){
		setSpecialImage(rows);
	}else{
		setSmallImage(rows); // kleine Bilder anzeigen
	}
}

// wird in regelmäßigen Intervallen aufgerufen um die Animationen zu starten
function startMorphs(){
	var table = $('imageBox').getChildren('table')[0];
	var rows = table.getChildren('tbody')[0].getChildren('tr');

	getRandomImage(rows);
	setOverlay(rows);
}

// soll vermeiden, dass zu viele Bilder nebeneinander stehen
function checkImagePosition(rowNo, colNo, rows){
	var cell;
	switch(rowNo){
		case 3:
			switch(colNo){
				case 1,2,3:
					cell = rows[rowNo].getChildren('td')[colNo];
					if(rows[rowNo].getChildren('td')[colNo-1].get('rel') != '' || rows[rowNo].getChildren('td')[colNo+1].get('rel') != ''){
						return -1;
					}
			//	break;
				default:
					if(rows[rowNo+1].getChildren('td')[colNo].get('rel') != '' || rows[rowNo-1].getChildren('td')[colNo].get('rel') != ''){
						return -1;
					}
				break;
			}
		break;
		default:
			switch(colNo){
				case 1,2,3:
					cell = rows[rowNo].getChildren('td')[colNo];
					if(rows[rowNo].getChildren('td')[colNo-1].get('rel') != '' || rows[rowNo].getChildren('td')[colNo+1].get('rel') != ''){
						return -1;
					}
				break;
			}
		break;
	}
	return 1;
}

// soll beim Laden der Seite bereits zufällig einige Felder füllen
function setFirstImages(){
	var table = $('imageBox').getChildren('table')[0];
	var rows = table.getChildren('tbody')[0].getChildren('tr');
	var randomRow;
	var randomCol;
	var usedCols = new Array();
	var col;
	var row;
	var cell;
	var imageDiv;
	var divElement;
	var fileName;

	var allowedImageIndizes = new Array();
	var randomImage;
	var imageIndex;
	var fileObjectDiv;
	var fileName;

	var randomColor;

	for(var i=0;i<num_firstImages;i++){
		randomRow = getRandomNumber(rows.length, new Array(1,1));
		row = rows[randomRow];
		if(randomRow == 2){
			randomCol = getRandomNumber(row.getChildren('td').length, new Array(2,2));
		}else{
			randomCol = getRandomNumber(row.getChildren('td').length, new Array());
		}
		while(checkImagePosition(randomRow, randomCol, rows) < 0){
			randomRow = getRandomNumber(rows.length, new Array(1,1));
			row = rows[randomRow];
			if(randomRow == 2){
				randomCol = getRandomNumber(row.getChildren('td').length, new Array(2,2));
			}else{
				randomCol = getRandomNumber(row.getChildren('td').length, new Array());
			}
		}
		col = row.getChildren('td')[randomCol];
		cell = col.getChildren('div')[0];
		imageDiv = cell.getChildren('div')[0];

		if(randomRow != (rows.length-1)){
			allowedImageIndizes = getAllowedImages(files, 'not_used');
			randomImage = getRandomNumber(allowedImageIndizes.length, new Array());
			imageIndex = allowedImageIndizes[randomImage];
			// Dateinamen herausfiltern
			fileObjectDiv = files[imageIndex];
			fileName = getFileName(fileObjectDiv);
		}else{
			allowedImageIndizes = getAllowedImages(files2, 'not_used');
			randomImage = getRandomNumber(allowedImageIndizes.length, new Array());
			imageIndex = allowedImageIndizes[randomImage];
			// Dateinamen herausfiltern
			fileObjectDiv = files2[imageIndex];
			fileName = getFileName(fileObjectDiv);
		}
		imageDiv.style.backgroundImage = 'url(index.php?rex_resize='+imageWidth+'c__'+imageHeight+'h__'+fileName+')';
		fileObjectDiv.set('rel', 'used');
		col.set('rel',imageIndex);
	}
	
	var overlays = $$('.overlay');
	var overlay;
	var num_overlays = overlays.length;
	for(var i=0;i<num_overlays;i++){
		overlay = overlays[i];
		overlay.get('morph').start( { 'background-color': '#FFFFFF', 'opacity': [defaultOpacity,defaultOpacity] } );
	}

	for(var i=0;i<num_firstImages;i++){
		randomRow = getRandomNumber(rows.length, new Array(1,1));
		row = rows[randomRow];
		if(randomRow == 2){
			randomCol = getRandomNumber(row.getChildren('td').length, new Array(2,2));
		}else{
			randomCol = getRandomNumber(row.getChildren('td').length, new Array());
		}
		col = row.getChildren('td')[randomCol];
		cell = col.getChildren('div')[0];
		overlayDiv = cell.getChildren('div')[1];

		while(overlayDiv.getStyle('background-color').indexOf('#') > -1){
			randomRow = getRandomNumber(rows.length, new Array(1,1));
			row = rows[randomRow];
			if(randomRow == 2){
				randomCol = getRandomNumber(row.getChildren('td').length, new Array(2,2));
			}else{
				randomCol = getRandomNumber(row.getChildren('td').length, new Array());
			}
			col = row.getChildren('td')[randomCol];
			cell = col.getChildren('div')[0];
			overlayDiv = cell.getChildren('div')[1];
		}
		randomColor = getAllowedColors(randomRow, randomCol, rows);
		
		overlayDiv.get('morph').start( { 'background-color': [backgroundColors[randomColor],backgroundColors[randomColor]], 'opacity': [defaultOpacity,defaultOpacity]} );
	}
}

window.addEvent('domready',
	function(){
		$('imageBoxDescription').addEvent('click',function()
		{
			window.location = '1-0-';
		}
		);
		files = $('imageBoxContainer').getChildren('div');
		num_files = files.length;
		files2 = $('imageBoxContainer2').getChildren('div');
		num_files2 = files2.length;
		var fx = function(){
			morphInterval = window.setInterval('startMorphs()',intervalDuration);
			bigImageInterval = window.setInterval('showBigImage()',intervalDuration*8);
		}
		setFirstImages();
		fx.delay(1000);
	}
);