//---------------------------------------------------------------------------------------//
// name:       js-slideShow                                                                                  //
// version:   2.1                                                                                                //
// made by:  melko                                                                                             //
// email: melko@gmx.at                                                                                      //
//                                                                                                                    //
// info:                                                                                                             //
//         this script enables you to use so many slideShows as you want to                //
//         have on your page without any extra-programming.                                    //
//         Only you must do is to set the paths and image-names!                               //
//                                                                                                                     //
// features:                                                                                                       //
//              - so many slideShows as you want to have                                             //
//              - easy implementation in the sourcecode                                              //
//              - each slideShow has its own slideShowSpeed and crossFadeDuration      //
//              - choose between random or in the order                                              //
//              - set a fix picture at the start of a slideShow                                       //
//												         //
// important:										         //
//	       - The slideShow MUST be initialized with the same number as the index    //
//                of the images it is containing!! example: images[1] = slideShowNr 1        //
//             - You should never have more slideShows than images defined!!                 //
//----------------------------------------------------------------------------------------//

//Specify the global path to the directory
var bigPath="http://www.vita-alpina.de/wcms/Clients/107200630081114/Images/";
//var bigPath="http://www.vita-alpina.de/wcms/Clients/148200806081508/Images/";


// pic arrays! FIRST POSITION IN THE ARRAY is the SMALLPATH to the pictures!
// if you no path want, then set "" !! Images starts allways with 0 !
var images = new Array();
// The FIRST slideShow with slideNr = 0 and so on... 
// ,".jpg",".jpg",".jpg",".jpg",".jpg",".jpg",".jpg",".jpg"
// SLIDEs
images[0] = ["","162421200719021626.jpg"];
images[1] = ["","349041200750021527.jpg","350006200751021527.jpg","349904200751021527.jpg","349801200751021527.jpg","349758200750021527.jpg","349655200750021527.jpg","349551200750021527.jpg","349449200750021527.jpg","349346200750021527.jpg","349244200750021527.jpg"];
images[2] = ["","160255200703021626.jpg","160358200703021626.jpg","160914200704021626.jpg","160811200704021626.jpg","160708200704021626.jpg","160605200704021626.jpg","160503200704021626.jpg","160400200704021626.jpg","220536200744021926.jpg","220638200744021926.jpg","220741200744021926.jpg","727619200712090928.jpg","727720200712090928.jpg","727821200712090928.jpg","727921200712090928.jpg","728022200712090928.jpg","728123200712090928.jpg"];
images[3] = ["","162846200719021626.jpg","229739200751022026.jpg","229637200751022026.jpg","229535200751022026.jpg","229433200751022026.jpg","229331200751022026.jpg","229229200751022026.jpg","229127200751022026.jpg","229026200751022026.jpg","350319200752021527.jpg"];
images[4] = ["","316029200754021227.jpg","315926200754021227.jpg","315822200754021227.jpg","315619200754021227.jpg","315515200754021227.jpg","315412200754021227.jpg","315309200754021227.jpg","315207200754021227.jpg","315103200754021227.jpg"];
images[5] = ["","599655200721041323.jpg","599555200721041323.jpg","599453200721041323.jpg","599352200721041323.jpg","599251200721041323.jpg"];
images[6] = ["","522711200713021328.jpg","520709200712021328.jpg","2199107200806041822.jpg","520914200712021328.jpg","521018200712021328.jpg","521123200712021328.jpg","521225200712021328.jpg","521331200712021328.jpg","521435200712021328.jpg","521537200712021328.jpg","521640200712021328.jpg","521743200712021328.jpg","521846200712021328.jpg","521949200712021328.jpg","522051200712021328.jpg","522156200712021328.jpg","2199007200806041822.jpg","522300200713021328.jpg","2199208200806041822.jpg","626829200823101620.jpg","626930200823101620.jpg","627030200823101620.jpg"];
images[7] = ["","1221140200716061721.jpg","1221039200716061721.jpg","1221342200716061721.jpg","1220939200716061721.jpg","1221241200716061721.jpg","1220835200716061721.jpg"];


// do not edit anything below this line 
//-------------------------------------------------------------------------------------//
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 init(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); 
}