//Specify the global path to the directory
var bigPath="/mediaCache/";
var images = new Array();

// eigene funktionen um die werte zu setzen
function setImages(imagesSz) {
  slideImagesArr = imagesSz.split(";");
  tmp_array = new Array();
  tmp_array[0] = "";
  for(i=0; i < slideImagesArr.length; i++) {
    if(slideImagesArr[i] != "") {
      tmp_array[i+1] = slideImagesArr[i];
    }
  }
  images[0] = tmp_array;//["",imagesSz];
}

var slideSpeed = new Array();
var crossFade = new Array();  
var index = new Array(); 
var pic = new Array(); 
var smallPath = new Array();
var preLoad = new Array();

// Initialize the slideShow... 
// @param slideNr - The slideNr of the slideShow... Every slide shoud start with 1
// @param slideShowSpeed - The speed of the slideShow in ms! (1sec. = 1000ms)
// @param crossFadeDuration - The duration of the crossFade (changing one picture through an other) values: 1, 2, 3,...
// @param random - Indicates if the slideShow shoud choose the pictures randomly or in the order. values; true, false
// @param fixStartPic - Indicates if the slideShow, with random = true, should have a fixStart picture at refreshing the page. Its the first image in the array. values: true, false
function initSlide(slideNr, slideShowSpeed, crossFadeDuration, random, fixStartPic) {

	index[slideNr] = 0;
	slideSpeed[slideNr] = slideShowSpeed;
	crossFade[slideNr] = crossFadeDuration;
	smallPath[slideNr] = images[slideNr][0];
	pic[slideNr] = new Array();
	
	for(var i = 0; i < images[slideNr].length-1; i++){
		pic[slideNr][i] = images[slideNr][i+1];
	}
	
	prepareSlide(slideNr, fixStartPic, random, pic[slideNr].length);
}

// prepareSlide the slideShow, set the pictures-order, fixStartPic and load it into PreLoad-Object
// @param slideNr - The slideNr of the slideShow... Every slide shoud start with 1
// @param fixStartPic - Indicates if the slideShow, with random = true, should have a fixStart picture at refreshing the page. Its the first image in the array. values: true, false 
// @param random - Indicates if the slideShow shoud choose the pictures randomly or in the order. values; true, false
// @param picLength - It's the length of the pic-Array of this slideShow
function prepareSlide(slideNr, fixStartPic, random, picLength){
	
	var duplicate = false;
	var reihenfolge = new Array();
	var z=0;
	
	if(fixStartPic){
		reihenfolge[0] = 0;
		z=1;
	}
	
	while (z != picLength){
		y=Math.floor(Math.random()*(picLength));
		for(i=0;i<reihenfolge.length;i++){	
			if (y==reihenfolge[i]){	
				duplicate=true;
			}
		}
		if (duplicate==true){ 
			duplicate=false;
			continue;
		} 
		else if (duplicate==false) { 
			reihenfolge[z] = y; z+=1; 
			
		}
	}
	preLoad[slideNr] = new Array();
	
	if(random) {
		for(i = 0; i < picLength; i++){
			preLoad[slideNr][i] = new Image();
			preLoad[slideNr][i].src = bigPath + smallPath[slideNr] + pic[slideNr][reihenfolge[i]];	
		}
	} 
	else {
		for (i = 0; i < picLength; i++) { 
			preLoad[slideNr][i] = new Image(); 
			preLoad[slideNr][i].src = bigPath + smallPath[slideNr] + pic[slideNr][i]; 
		} 
	}
}

// Run the slideShow with the slideNr that indicates the special slide. It makes a pause of "slideShowSpeed" before starting it...
// @param slideNr - The slideNr of the slideShow... Every slide shoud start with 1
function runSlideShow(slideNr){
	setTimeout('runSlide('+slideNr+')', slideSpeed[slideNr]); 
}

// Run the slideShow with the slideNr that indicates the special slide
// @param slideNr - The slideNr of the slideShow... Every slide shoud start with 1
function runSlide(slideNr) { 
	var element = document.getElementById("slide"+slideNr);
	
	if (document.all) { 
		element.style.filter='blendTrans(duration='+crossFade[slideNr]+')'
		element.filters.blendTrans.Apply(); 
	} 
	element.src = preLoad[slideNr][index[slideNr]].src; 
	
	if (document.all) { 
		element.filters.blendTrans.Play(); 
	} 
	index[slideNr] += 1; 
	
	if (index[slideNr] > (preLoad[slideNr].length - 1)) {
		index[slideNr] = 0;
	}
	runSlideShow(slideNr);
}

