function init()
{
	checkCompatibility();
	startSlideshow();
}

function checkCompatibility()
{
	if (BrowserDetect.browser == "Internet Explorer") {
		window.location = "./ie.html"
	}
}

function fadeInAbout()
{
	document.getElementById('playpause').style.opacity = 0;

	
	if (BrowserDetect.browser == "Safari") {
		//Nice stuff here
		//document.getElementById('about').style.display = 'block';
		document.getElementById('about').style.opacity = 1;
	} else {
		document.getElementById('about').style.display = 'block';
		opacity('about', 0, 100, 300);
	}
}

function fadeOutAbout()
{
	if (BrowserDetect.browser == "Safari") {
		setTimeout("document.getElementById('about').style.opacity = 0;", 250);
		//setTimeout("document.getElementById('about').style.display = 'none';", 600);
	} else {
		setTimeout("opacity('about', 100, 0, 300);", 250);
		setTimeout("document.getElementById('about').style.display = 'none';", 600);	
	}
	
}

var photos = new Array();

photos[0] = "fish";
photos[1] = "dragonfly";
photos[2] = "beach";
photos[3] = "buds";
photos[4] = "bus";


var currentPhoto = 0;

//duration of fade transition in milliseconds
var fadeDuration = 620;

playing = 1;

nextPhotoIsCurrentlyRunning = 0;

function forceNext()
{
	if (playing == 0) {
		playing = 1;
		startSlideshow();
		document.getElementById('playpause').style.backgroundImage = "url('./images/play.png')";
		document.getElementById('playpause').style.opacity = 1;
		setTimeout("document.getElementById('playpause').style.opacity = 0;", 1500);
		nextPhotoIsCurrentlyRunning = 0;
		nextPhoto();
	} else {
		nextPhotoIsCurrentlyRunning = 0;
		nextPhoto();
	}
}



function nextPhoto()
{	
	if (nextPhotoIsCurrentlyRunning == 0) {
		if (playing == 1) {
			nextPhotoIsCurrentlyRunning = 1;
			if (BrowserDetect.browser == "Safari") {
				//cross fade Safari
				if (currentPhoto + 1 < photos.length) {
					document.getElementById(photos[currentPhoto]).style.opacity = 0;
					currentPhoto ++;
					document.getElementById(photos[currentPhoto]).style.opacity = 1;
				} else {
					document.getElementById(photos[currentPhoto]).style.opacity = 0;
					currentPhoto = 0;
					document.getElementById(photos[currentPhoto]).style.opacity = 1;
				}
				setTimeout("nextPhotoIsCurrentlyRunning = 0;", 920);
			} else {
				//cross fade
				if (currentPhoto + 1 < photos.length) {
					opacity(photos[currentPhoto], 100, 0, fadeDuration);
					currentPhoto ++;
					opacity(photos[currentPhoto], 0, 100, fadeDuration);
				} else {
					opacity(photos[currentPhoto], 100, 0, fadeDuration);
					currentPhoto = 0;
					opacity(photos[currentPhoto], 0, 100, fadeDuration);
				}
				setTimeout("nextPhotoIsCurrentlyRunning = 0;", 920);
			}
		}
	} else {
		setTimeout("nextPhotoIsCurrentlyRunning = 0;", 920);
		//alert('nextPhotoIsCurrentlyRunning');
	}
}

function updateStatus()
{
	document.getElementById('label').innerHTML = nextPhotoIsCurrentlyRunning;
	document.getElementById('labeltwo').innerHTML = playing;
	setTimeout("updateStatus();", 10);
}

function previousPhoto()
{	
	pause();
	//cross fade
	if (BrowserDetect.browser == "Safari") {
		if (currentPhoto != 0) {
			document.getElementById(photos[currentPhoto]).style.opacity = 0;
			currentPhoto --;
			document.getElementById(photos[currentPhoto]).style.opacity = 1;
		} else {
			document.getElementById(photos[currentPhoto]).style.opacity = 0;
			currentPhoto = photos.length - 1;
			document.getElementById(photos[currentPhoto]).style.opacity = 1;
		}
	} else {
		if (currentPhoto != 0) {
			opacity(photos[currentPhoto], 100, 0, fadeDuration);
			currentPhoto --;
			opacity(photos[currentPhoto], 0, 100, fadeDuration);
		} else {
			opacity(photos[currentPhoto], 100, 0, fadeDuration);
			currentPhoto = photos.length - 1;
			opacity(photos[currentPhoto], 0, 100, fadeDuration);
		}
	}

}

var hasInit = 0;

function showControls()
{
	document.getElementById('playpause').style.backgroundImage = "url('./images/play.png')";
	document.getElementById('playpause').style.opacity = 1;
	setTimeout("document.getElementById('playpause').style.opacity = 0;", 1500);
	hasInit = 1;
}


function startSlideshow()
{
	
	if (playing == 1) {
		setTimeout("nextPhoto();", 4000);
		
		setTimeout("startSlideshow();", 6000);
	}
}

function pause()
{
	if (playing == 1) {
		document.getElementById('playpause').style.backgroundImage = "url('./images/paused.png')";
		document.getElementById('playpause').style.opacity = 1;
		playing = 0;
		setTimeout("document.getElementById('playpause').style.opacity = 0;", 1500);
	}
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}

//browser detect

function checkBrowser() {

}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

