// Set the slideshow speed (in milliseconds)
var SlideShowSpeed = 6000;

// Set the duration of crossfade (in seconds)
var CrossFadeDuration = 3;

var Picture = new Array();

Picture[49] = 'images/top/DSC_0952_2.jpg';
Picture[48] = 'images/top/18_1.jpg';
Picture[47] = 'images/top/DSC_0351_1.jpg';
Picture[46] = 'images/top/02_1.jpg';
Picture[45] = 'images/top/DSC_0064_1.jpg';
Picture[44] = 'images/top/24.jpg';
Picture[43] = 'images/top/DSC_0216_2.jpg';
Picture[42] = 'images/top/DSC_0950_1.jpg';
Picture[41] = 'images/top/IMG_1485_1.jpg';
Picture[40] = 'images/top/DSC_0898_1.jpg';
Picture[39] = 'images/top/DSC_0953_2.jpg';
Picture[38] = 'images/top/21_1.jpg';
Picture[37] = 'images/top/IMG_1429_1.jpg';
Picture[36] = 'images/top/DSC_0951_1.jpg';
Picture[35] = 'images/top/15_2.jpg';
Picture[34] = 'images/top/DSC_0214_1.jpg';
Picture[33] = 'images/top/DSC_0894_1.jpg';
Picture[32] = 'images/top/04_1.jpg';
Picture[31] = 'images/top/DSC_0893_1.jpg';
Picture[30] = 'images/top/20_1.jpg';
Picture[29] = 'images/top/DSC_0893_2.jpg';
Picture[28] = 'images/top/05_1.jpg';
Picture[27] = 'images/top/DSC_0895_1.jpg';
Picture[26] = 'images/top/13_1.jpg';
Picture[25] = 'images/top/DSC_0216_1.jpg';
Picture[24] = 'images/top/DSC_0847_1.jpg';
Picture[23] = 'images/top/21_2.jpg';
Picture[22] = 'images/top/DSC_0898_2.jpg';
Picture[21] = 'images/top/06_1.jpg';
Picture[20] = 'images/top/DSC_0161_1.jpg';
Picture[19] = 'images/top/10_1.jpg';
Picture[18] = 'images/top/DSC_0947_1.jpg';
Picture[17] = 'images/top/DSC_0350_1.jpg';
Picture[16] = 'images/top/DSC_0355_1.jpg';
Picture[15] = 'images/top/11.jpg';
Picture[14] = 'images/top/13.jpg';
Picture[13] = 'images/top/18.jpg';
Picture[12] = 'images/top/19.jpg';
Picture[11] = 'images/top/2.jpg';
Picture[10] = 'images/top/23.jpg';
Picture[9] = 'images/top/35.jpg';
Picture[8] = 'images/top/40.jpg';
Picture[7] = 'images/top/43.jpg';
Picture[6] = 'images/top/45.jpg';
Picture[5] = 'images/top/46.jpg';
Picture[4] = 'images/top/5.jpg';
Picture[3] = 'images/top/8.jpg';
Picture[2] = 'images/top/01.jpg';
Picture[1] = 'images/top/04.jpg';
Picture[0] = 'images/top/03_1.jpg';
	

var tss;
var cookie = readCookie("crossfade");
var preLoadStart = 0; 
if(cookie != null)
	preLoadStart = parseInt(cookie)+1;
var preLoadEnd = Picture.length;
if (preLoadStart < 0 || preLoadStart >= preLoadEnd)
	preLoadStart = 0;
var showImage = preLoadStart;
var preLoadIndex = preLoadStart;
var preLoadImage = preLoadIndex;
var preLoadCount = 0;
var preLoadInitiated = false;
var pictureBox;
var documentAll;

var soundCount = 0;
var soundNumber = 2;
var soundOff = true;

// preLoad the first picture
var preLoad = new Array();
preLoad[preLoadIndex] = new Image();
preLoadIndex = preLoadIndex + 1;
preLoadCount = preLoadCount + 1;
if (preLoadIndex >= preLoadEnd)
	preLoadIndex = 0;
preLoad[preLoadImage].src = Picture[preLoadImage];

var time;
var startTime;
var endTime;
var bandwidth = 1500;

function preLoadNextImage() {
	// alert("preLoadNextImage: preLoadIndex="+preLoadIndex+" bandwidth="+bandwidth);
	time = new Date();
	startTime = time.getTime();
    preLoad[preLoadIndex] = new Image();
	preLoad[preLoadImage].onload = null;
	preLoadImage = preLoadIndex;
	preLoadIndex = preLoadIndex + 1;
	preLoadCount = preLoadCount + 1;
	if (preLoadIndex >= preLoadEnd)
		preLoadIndex = 0;
	if (preLoadCount < preLoadEnd && bandwidth > 500) 
		preLoad[preLoadImage].onload = function () {setTimeout('preLoadNextImage()',1);};
	else
		preLoad[preLoadImage].onload = null;
	preLoad[preLoadImage].src = Picture[preLoadImage];	
	time = new Date();
	endTime = time.getTime();
	//// calculate download time
	if (startTime == endTime) {
		bandwidth = 1500; // if it's to fast to measure: dummy bandwidth 1500 kbps
	}
	else { 
		bandwidth = 800/((endTime - startTime)/10000); //bandwidth in kbps
	}
}

function runSlideShow(){
	if(!preLoadInitiated) {
		preLoad[preLoadIndex] = new Image();
		preLoadImage = preLoadIndex;
		preLoadIndex = preLoadIndex + 1;
		preLoadCount = preLoadCount + 1;
		if (preLoadIndex >= preLoadEnd)
			preLoadIndex = 0;
		preLoad[preLoadImage].onload = function () {setTimeout('preLoadNextImage()',1);};
		preLoad[preLoadImage].src = Picture[preLoadImage];
		preLoadInitiated = true;
	}
	if(document.all) {
		document.images.PictureBox.style.filter="blendTrans(duration=2)";
		document.images.PictureBox.style.filter="blendTrans(duration=CrossFadeDuration)";
		if (document.images.PictureBox.filters)
			document.images.PictureBox.filters.blendTrans.Apply();
	}
	document.images.PictureBox.src = preLoad[showImage].src;
	document.images.PictureBox.width = 800;
	if(document.all) {
		if (document.images.PictureBox.filters)
			document.images.PictureBox.filters.blendTrans.Play();
	}
	createCookie("crossfade", showImage, 1);
	showImage = showImage + 1;
	if (showImage >= preLoadEnd) 
		showImage = 0;
	tss = setTimeout('runSlideShow()', SlideShowSpeed);
	
	if (soundCount++ % 7 == 0)
		playSound();
}

function currentImage()
{
	document.writeln("<img class=\"toppic\" name=\"PictureBox\" src=\"" + Picture[showImage] + 		
		  "\"width=\"800px\"/>");
}

function currentImageID()
{
	document.write("image="+showImage);
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

// Functions to play music

ver=parseInt(navigator.appVersion)
ie4=(ver>3  && navigator.appName!="Netscape")?1:0
ns4=(ver>3  && navigator.appName=="Netscape")?1:0
ns3=(ver==3 && navigator.appName=="Netscape")?1:0

function soundOn() {
	soundOff = false;
}

function playSound() {
 if (!soundOff) {
	 if (ie4)
		document.all['BGSOUND_ID'].src='sounds/tui0.asf';
//		document.all['BGSOUND_ID'].src='sounds/tui'+(soundNumber++ % 5)+'.asf';
	 if ((ns4||ns3)
	  && navigator.javaEnabled()
	  && navigator.mimeTypes['audio/x-midi']
	  && self.document.Tui.IsReady()
	 )
	 {
	  self.document.Tui.play()
	 }
 }
}

function stopSound() {
 if (ie4) document.all['BGSOUND_ID'].src='jsilence.mid';
 if ((ns4||ns3)
  && navigator.javaEnabled()
  && navigator.mimeTypes['audio/x-midi']
 )
 {
  self.document.Tui.stop()
 }
}
