// S5 1.3beta6 (09-Mar-2007) advanced version by by s5 [at] netzgesta (dot) de
// based on S5 v1.2a1 slides.js -- released into the Public Domain
// Please see http://www.meyerweb.com/eric/tools/s5/credits.html for information 
// about all the wonderful and talented contributors to this code!
// audio extension: soundmanager2 is NOT Public Domain
// Please see http://www.schillmania.com/projects/soundmanager2/ for information

var undef;
var slideCSS = '';
var snum = 0;
var smax = 1;
var incpos = 0;
var number = undef;
var s5mode = true;
var defaultView = 'slideshow'; //outline
var controlVis = 'visible';

// scalable images extension
var empx = 0;
var images = new Array();
var medias = new Array();
// scalable images extension

// transition extension
var tranSitions = false;
var fadeModus = false;
var fadeDuration = 500;
var incrDuration = 250;
var opac = 1;
var cid = '';
var nid = '';
var tid = '';
var jl = '';
// transition extension

// autoplay extension
var autoMatic = false;
var playLoop = false;
var playPause = false;
var autoRun = false;
var playDelay = 5000;
var remainDer = 0;
var incrDelay = 0;
// autoplay extension

// audio extension
var sound = new Array();
var audioSupport = false;
var audioVolume = 100;
var audioError = false;
var swfUnloaded = true;
var bgSoundItem = 9999;
var curSoundID = -1;
// audio extension

// panel extension
var imgWidth = 32;
var imgHeight = 32;
// panel extension

var s5NotesWindow;
var s5NotesWindowLoaded = false;
var previousSlide = 0;
var presentationStart = new Date();
var slideStart = new Date();

var countdown = {
	timer: 0,
	state: 'pause',
	start: new Date(),
	end: 0,
	remaining: 0
};


var isIE = navigator.appName == 'Microsoft Internet Explorer' && navigator.userAgent.indexOf('Opera') < 1 ? 1 : 0;
if(isIE) var notIE7 = parseInt(navigator.appVersion) < 7 ? 1 : 0;
var isOp = navigator.userAgent.indexOf('Opera') > -1 ? 1 : 0;
var isGe = navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('Safari') < 1 ? 1 : 0;
var isS2 = navigator.userAgent.indexOf('Safari') >= 2 ? 1 : 0;


function hasClass(object, className) {
	if (!object.className) return false;
	return (object.className.search('(^|\\s)' + className + '(\\s|$)') != -1);
}

function hasValue(object, value) {
	if (!object) return false;
	return (object.search('(^|\\s)' + value + '(\\s|$)') != -1);
}

function removeClass(object,className) {
	if (!object || !hasClass(object,className)) return;
	object.className = object.className.replace(new RegExp('(^|\\s)'+className+'(\\s|$)'), RegExp.$1+RegExp.$2);
}

function addClass(object,className) {
	if (!object || hasClass(object, className)) return;
	if (object.className) {
		object.className += ' '+className;
	} else {
		object.className = className;
	}
}

function changeClass(object,className) {
	if (!object) return;
	object.firstChild.className = className;
}

function GetElementsWithClassName(elementName,className) {
	var allElements = document.getElementsByTagName(elementName);
	var elemColl = new Array();
	for (var i = 0; i< allElements.length; i++) {
		if (hasClass(allElements[i], className)) {
			elemColl[elemColl.length] = allElements[i];
		}
	}
	return elemColl;
}

function isParentOrSelf(element, id) {
	if (element == null || element.nodeName=='BODY') return false;
	else if (element.id == id) return true;
	else return isParentOrSelf(element.parentNode, id);
}

function nodeValue(node) {
	var result = "";
	if (node.nodeType == 1) {
		var children = node.childNodes;
		for (var i = 0; i < children.length; ++i) {
			result += nodeValue(children[i]);
		}		
	}
	else if (node.nodeType == 3) {
		result = node.nodeValue;
	}
	return(result);
}

function slideLabel() {
	var slideColl = GetElementsWithClassName('*','slide');
	var list = document.getElementById('jumplist');
	smax = slideColl.length;
	for (var n = 0; n < smax; n++) {
		var obj = slideColl[n];
		var did = 'slide' + n.toString();
		obj.setAttribute('id',did);
		var otext = '';
		var menu = obj.firstChild;
		if (!menu) continue; // to cope with empty slides
		while (menu && menu.nodeType == 3) {
			menu = menu.nextSibling;
		}
	 	if (!menu) continue; // to cope with slides with only text nodes
		var menunodes = menu.childNodes;
		for (var o = 0; o < menunodes.length; o++) {
			otext += nodeValue(menunodes[o]);
		}
		list.options[list.length] = new Option(n + ' : '  + otext, n);
	}
}

function currentSlide() {
	var cs, at, fd, ss;
	if (document.getElementById) {
		cs = document.getElementById('currentSlide');
	} else {
		cs = document.currentSlide;
	}
	fd = fadeModus?"F":"&ndash;";
	ss = audioSupport?"S":"&ndash;";  
	at = (autoMatic?(playPause?"||":(playLoop?"&gt;0":"&gt;|")):"&ndash;&ndash;");
	cs.innerHTML = '<div id="plink" nowrap="nowrap">' + 
	'<span id="csFade">[' + fd + ss + ']<\/span>&nbsp;' +
	'<span id="csHere"><strong>' + snum + '<\/strong><\/span>' + 
	'<span id="csSep">\/<\/span>' + 
	'<span id="csTotal">' + (smax-1) + '<\/span>&nbsp;' +
	'<span id="csAuto">[' + at + ']<\/span>' +
	'<\/div>';
		
	if (snum == 0) {
		cs.style.visibility = 'hidden';
	} else {
		cs.style.visibility = 'visible';
	}
}

function go(step) {
	if (document.getElementById('slideProj').disabled || step == 0) return;
	jl = document.getElementById('jumplist');
	cid = 'slide' + snum;
	var ce = document.getElementById(cid);
	if (incrementals[snum].length > 0) {
		for (var i = 0; i < incrementals[snum].length; i++) {
			removeClass(incrementals[snum][i], 'current');
			removeClass(incrementals[snum][i], 'incremental');
		}
	}
	if (step != 'j') {
		snum += step;
		lmax = smax - 1;
		if (snum > lmax) snum = lmax;
		if (snum < 0) snum = 0;
	}else {
		snum = parseInt(jl.value);
	}	
	nid = 'slide' + snum;
	var ne = document.getElementById(nid);
	if (!ne) {
		ne = document.getElementById('slide0');
		nid = 'slide0';
		snum = 0;
	}
	if (step < 0) {
		incpos = incrementals[snum].length
	}else {
		incpos = 0;
	}
	if (incrementals[snum].length > 0 && incpos == 0) {
		for (var i = 0; i < incrementals[snum].length; i++) {
			if (hasClass(incrementals[snum][i], 'current')) {
				incpos = i + 1;
			}else {
				addClass(incrementals[snum][i], 'incremental');
			}
		}
	}
	if (incrementals[snum].length > 0 && incpos > 0) {
		addClass(incrementals[snum][incpos - 1], 'current');
	}
	var guru = document.getElementById('guru');
	if(guru && snum==0) {
		guru.style.visibility = 'visible';
	}else if(guru && snum>0) {
		guru.style.visibility = 'hidden';
	}	
	if(tranSitions && s5mode && fadeModus) {
		if(curSoundID != getSoundID(nid)) {
			if(curSoundID == bgSoundItem && !sound[getSoundID(nid)]) {
			}else {fadeoutSound(curSoundID,true); } // audio support
		}		
		changeOpac(0,nid);
		changeOpac(100,cid);
		ce.style.visibility = 'visible';
		shiftOpacity(cid,fadeDuration);
		window.setTimeout("changeSlides()",fadeDuration);
	}else {
		if(curSoundID != getSoundID(nid)) {
			if(curSoundID == bgSoundItem && !sound[getSoundID(nid)]) {
			}else {stopSound(curSoundID); } // audio support 
		}
		ce.style.visibility = 'hidden';
		if (isOp) location.hash = nid;
		ne.style.visibility = 'visible';
		finishSlides();		
	}
}

function changeSlides() {
	if(nid != cid) changeOpac(100,cid);
	document.getElementById(cid).style.visibility = 'hidden';
	document.getElementById(nid).style.visibility = 'visible';
	if (isOp) location.hash = nid;
	shiftOpacity(nid,fadeDuration);
	window.setTimeout("finishSlides()",fadeDuration);
}

function finishSlides() {
	jl.selectedIndex = snum;
	currentSlide();
	loadNote();
	permaLink();
	number = undef;
	if(sound[getSoundID(nid)]) {
		playSound(nid); // audio support
	}else if(sound[bgSoundItem] && curSoundID != bgSoundItem) {
		playSound(bgSoundItem); // audio support
	}
}

function goTo(target) {
	if (target >= smax || target == snum) return;
	go(target - snum);
}

function subgo(step) {
	if (step > 0) {
		removeClass(incrementals[snum][incpos - 1],'current');
		removeClass(incrementals[snum][incpos], 'incremental');
		if(tranSitions && s5mode && fadeModus) { 			
			if(!incrementals[snum][incpos].id) {
				var tmp = new Date(); tid = "inc" + String(tmp.getTime());
				incrementals[snum][incpos].id = tid;
			}else {
				tid = incrementals[snum][incpos].id;
			}	
			if(typeof(incrementals[snum][incpos].src) != "undefined") {
				changeOpac(0,tid);		
				addClass(incrementals[snum][incpos],'current');
				shiftOpacity(tid,incrDuration);
				setTimeout("nextInc()",incrDuration);
			}else {
				addClass(incrementals[snum][incpos],'current');
				nextInc();
			}	
		}else {
			addClass(incrementals[snum][incpos],'current');
			nextInc();
		}
	} else {
		incpos--;
		removeClass(incrementals[snum][incpos],'current');
		addClass(incrementals[snum][incpos], 'incremental');
		addClass(incrementals[snum][incpos - 1],'current');
		loadNote();
	}
}

function nextInc() {
	incpos++;
	loadNote();
}

function toggle() {
	var slideColl = GetElementsWithClassName('*','slide');
	var slides = document.getElementById('slideProj');
	var outline = document.getElementById('outlineStyle');
	var guru = document.getElementById('guru');
	if (!slides.disabled) {
		stopPlay();
		if(audioSupport && !swfUnloaded) stopAllSounds();
		slides.disabled = true;
		outline.disabled = false;
		s5mode = false;
		fontSize(1,'em');
		for (var n = 0; n < smax; n++) {
			var slide = slideColl[n];
			slide.style.visibility = 'visible';
		}
		if(guru) guru.style.visibility = 'hidden';
	} else {
		slides.disabled = false;
		outline.disabled = true;
		s5mode = true;
		fontScale();
		for (var n = 0; n < smax; n++) {
			var slide = slideColl[n];
			slide.style.visibility = 'hidden';
		}
		slideColl[snum].style.visibility = 'visible';
		if(guru && snum==0) guru.style.visibility = 'visible';
	}
}

function showHide(action) {
	var obj = GetElementsWithClassName('*','hideme')[0];
	// var oid = obj.id;
	switch (action) {
	case 's': 
		obj.style.visibility = 'visible'; 
		break;
	case 'h':
		obj.style.visibility = 'hidden'; 
		break;
	case 'k':
		if (obj.style.visibility != 'visible') {
			obj.style.visibility = 'visible';
		} else {
			obj.style.visibility = 'hidden';
		}
	break;
	}
}

function keys(key) {
	if (!key) {
		key = event;
		key.which = key.keyCode;
	}
	if (key.which == 84 && !isOp) {
		toggle();
		return;
	}
	if (s5mode) {
		if (autoMatic) {
			switch (key.which) {
			case 70: // f/ading on/off
				switchFade();
				break;
			case 83: // s/ound on/off
				toggleSounds();
				break;	
			case 67: // c
				showHide('k');
				break;
			case 65: // a/utoplay on/off
				stopPlay();
				break;
			case 76: // l/ooping on/off
				switchLoop();
				break;
			case 80: // p/ause
			case 32: // spacebar
				pausePlay();
				break;
			}
		}else {
			switch (key.which) {
			case 10: // return
			case 13: // enter
				if (window.event && isParentOrSelf(window.event.srcElement, 'controls')) return;
				if (key.target && isParentOrSelf(key.target, 'controls')) return;
				if(number != undef) {
					goTo(number);
					break;
				}
			case 32: // spacebar
			case 34: // page down
			case 39: // rightkey
			case 40: // downkey
				if(number != undef) {
					go(number);
				} else if (!incrementals[snum] || incpos >= incrementals[snum].length) {
					go(1);
				} else {
					subgo(1);
				}
				break;
			case 33: // page up
			case 37: // leftkey
			case 38: // upkey
				if(number != undef) {
					go(-1 * number);
				} else if (!incrementals[snum] || incpos <= 0) {
					go(-1);
				} else {
					subgo(-1);
				}
				break;
			case 65: // a/utoplay
				startPlay();
				break;				
			case 72: // h
			case 36: // home
				goTo(0);
				break;
			case 69: // e
			case 35: // end
				goTo(smax-1);
				break;
			case 70: // f/ade transitions on/off
				switchFade();
				break;
			case 76: // l/ooping on/off
				switchLoop();
				break;
			case 83: // s/ound support on/off
				toggleSounds();
				break;					
			case 27: // escape
			case 81: // q
				if(!isOp) byby();
				break;
			case 67: // c
				showHide('k');
				break;
			case 78: // n
				createNotesWindow();
				break;
			}
			if (key.which < 48 || key.which > 57) {
				number = undef;
			} else {
				if (window.event && isParentOrSelf(window.event.srcElement, 'controls')) return;
				if (key.target && isParentOrSelf(key.target, 'controls')) return;
				number = (((number != undef) ? number : 0) * 10) + (key.which - 48);
			}
		}
	}
	return false;
}

function clicker(e) {
	number = undef;
	var target;
	if (window.event) {
		target = window.event.srcElement;
		e = window.event;
	} else target = e.target;
	if (target.href != null || hasValue(target.rel, 'external') || isParentOrSelf(target, 'controls') || isParentOrSelf(target,'embed') || isParentOrSelf(target,'object')) return true;
	if (!e.which || e.which == 1) {
		if (!incrementals[snum] || incpos >= incrementals[snum].length) {
			go(1);
		} else {
			subgo(1);
		}
	}
}

function findSlide(hash) {
	var target = null;
	var slides = GetElementsWithClassName('*','slide');
	for (var i = 0; i < slides.length; i++) {
		var targetSlide = slides[i];
		if ( (targetSlide.name && targetSlide.name == hash)
		 || (targetSlide.id && targetSlide.id == hash) ) {
			target = targetSlide;
			break;
		}
	}
	while(target != null && target.nodeName != 'BODY') {
		if (hasClass(target, 'slide')) {
			return parseInt(target.id.slice(5));
		}
		target = target.parentNode;
	}
	return null;
}

function slideJump() {
	if (window.location.hash == null) return;
	var sregex = /^#slide(\d+)$/;
	var matches = sregex.exec(window.location.hash);
	var dest = null;
	if (matches != null) {
		dest = parseInt(matches[1]);
	} else {
		dest = findSlide(window.location.hash.slice(1));
	}
	if (dest != null)
		go(dest - snum);
}

function fixLinks() {
	var thisUri = window.location.href;
	thisUri = thisUri.slice(0, thisUri.length - window.location.hash.length);
	var aelements = document.getElementsByTagName('A');
	for (var i = 0; i < aelements.length; i++) {
		var a = aelements[i].href;
		var slideID = a.match('\#slide[0-9]{1,2}');
		if ((slideID) && (slideID[0].slice(0,1) == '#')) {
			var dest = findSlide(slideID[0].slice(1));
			if (dest != null) {
				if (aelements[i].addEventListener) {
					aelements[i].addEventListener("click", new Function("e",
						"if (document.getElementById('slideProj').disabled) return;" +
						"go("+dest+" - snum); " +
						"if (e.preventDefault) e.preventDefault();"), true);
				} else if (aelements[i].attachEvent) {
					aelements[i].attachEvent("onclick", new Function("",
						"if (document.getElementById('slideProj').disabled) return;" +
						"go("+dest+" - snum); " +
						"event.returnValue = false;"));
				}
			}
		}
	}
}

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName('a');
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute('href') && hasValue(anchor.rel, 'external')) {
			anchor.target = '_blank';
			addClass(anchor,'external');
		}
	}
}

function permaLink() {
	document.getElementById('plink').href = window.location.pathname + '#slide' + snum;
}

function createControls() {
	var controlsDiv = document.getElementById("controls");
	if (!controlsDiv) return;
	var hider = ' onmouseover="showHide(\'s\');" onmouseout="showHide(\'h\');"';
	var hideDiv, hideList = '';
	if (controlVis == 'hidden') {
		hideDiv = hider;
	} else {
		hideList = hider;
	}
	if(isOp) {
		var str = '';
	}else {
		var str = '<a accesskey="t" id="sheet" title="toggle CSS" href="javascript:toggle();">&plusmn;<\/a>';
	}	
	if(isIE) {
		var tmp = "move around&xA0;until the color&xA0;change to red!";
	}else if(isS2) {
		var tmp = "move around\r\nuntil the color\r\nchange to red!";
	}else {
		var tmp = "move around until color change to red!";
	}
	if(isIE) {
		controlsDiv.innerHTML = str +
		'<form action="#" id="controlForm"' + hideDiv + '>' +
		'<div id="navLinks"><ul>' +
		'<li id="show-notes"><a href="javascript:createNotesWindow();" accesskey="n" title="show Notes"><\/a><\/li>' +
		'<li id="toggle"><a href="javascript:toggle();" accesskey="t" title="toggle CSS"><\/a><\/li>' +
		'<li id="zero"><a href="javascript:goTo(0);" accesskey="h" title="goto Start Slide"><\/a><\/li>' +
		'<li id="prev"><a href="javascript:go(-1);" accesskey="y" title="previous Slide"><\/a><\/li>' +
		'<li id="next"><a href="javascript:go(1);" accesskey="x" title="next Slide"><\/a><\/li>' +
		'<li id="last"><a href="javascript:goTo(smax-1);" accesskey="e" title="goto Last Slide"><\/a><\/li>' +
		'<li id="lst" style="vertical-align: middle; width: 160px;"><select style="cursor: auto; width: 160px; height: auto;" id="jumplist" title="select named Slide" onchange="go(\'j\');"><\/select><\/li>' +
		'<li id="auto"><a class="isoff" href="javascript:togglePlay();" accesskey="a" title="Auto Play"><\/a><\/li>' +
		'<li id="pause"><a class="isoff" href="javascript:pausePlay();" accesskey="p" title="Pause"><\/a><\/li>' +
		'<li id="loop"><a class="isoff" href="javascript:switchLoop();" accesskey="l" title="Loop"><\/a><\/li>' +
		'<li id="del" style="vertical-align: middle; width: 52px;"><select style="cursor: auto; width: 52px; height: auto;" id="delaylist" title="select Delay" onchange="setDelay();"><option value="90">90<\/option><option value="75">75<\/option><option value="60">60<\/option><option value="45">45<\/option><option value="30">30<\/option><option value="20">20<\/option><option value="15">15<\/option><option value="10">10<\/option><option value="5">5<\/option><\/select><\/li>' +
		'<\/ul><\/div><\/form>';
	}else {
		controlsDiv.innerHTML = str +
		'<form action="#" id="controlForm"' + hideDiv + '>' +
		'<div id="navLinks"><ul>' +
		'<li id="exit"><a href="javascript:byby();" accesskey="q" title="exit Show"><\/a><\/li>' +
		'<li id="show-notes"><a href="javascript:createNotesWindow();" accesskey="n" title="show Notes"><\/a><\/li>' +
		'<li id="toggle"><a href="javascript:toggle();" accesskey="t" title="toggle CSS"><\/a><\/li>' +
		'<li class="vr"><\/li>' +
		'<li id="zero"><a href="javascript:goTo(0);" accesskey="h" title="goto Start Slide"><\/a><\/li>' +
		'<li id="prev"><a href="javascript:go(-1);" accesskey="y" title="previous Slide"><\/a><\/li>' +
		'<li id="next"><a href="javascript:go(1);" accesskey="x" title="next Slide"><\/a><\/li>' +
		'<li id="last"><a href="javascript:goTo(smax-1);" accesskey="e" title="goto Last Slide"><\/a><\/li>' +
		'<li id="lst"><a id="list" style="cursor:wait;" title="' + tmp + '"><\/a><select id="jumplist" title="select named Slide" onchange="go(\'j\');"><\/select><\/li>' +
		'<li id="fadeLinks" class="vr"><\/li>' +
		'<li id="fade"><a class="isoff" href="javascript:switchFade();" accesskey="f" title="Transions"><\/a><\/li>' +
		'<li id="audioLinks" class="vr"><\/li>' +
		'<li id="audio"><a class="isoff" href="javascript:toggleSounds();" accesskey="s" title="Sounds" ><\/a><\/li>' +
		'<li id="vol"><a id="volume" style="cursor:wait;" title="' + tmp + '"><\/a><select id="volumelist" title="select Volume" onchange="setVolume();"><option value="100">100<\/option><option value="90">90<\/option><option value="80">80<\/option><option value="70">70<\/option><option value="60">60<\/option><option value="50">50<\/option><option value="40">40<\/option><option value="30">30<\/option><option value="20">20<\/option><option value="10">10<\/option><option value="0">0<\/option><\/select><\/li>' +	
		'<li id="autoLinks" class="vr"><\/li>' +
		'<li id="auto"><a class="isoff" href="javascript:togglePlay();" accesskey="a" title="Auto Play"><\/a><\/li>' +
		'<li id="pause"><a class="isoff" href="javascript:pausePlay();" accesskey="p" title="Pause"><\/a><\/li>' +
		'<li id="loop"><a class="isoff" href="javascript:switchLoop();" accesskey="l" title="Loop"><\/a><\/li>' +
		'<li id="del"><a id="delay" style="cursor:wait;" title="' + tmp + '"><\/a><select id="delaylist" title="select Delay" onchange="setDelay();"><option value="90">90<\/option><option value="75">75<\/option><option value="60">60<\/option><option value="45">45<\/option><option value="30">30<\/option><option value="20">20<\/option><option value="15">15<\/option><option value="10">10<\/option><option value="5">5<\/option><\/select><\/li>' +
		'<\/ul><\/div><\/form>';
	}
	if (controlVis == 'hidden') {
		var hidden = document.getElementById('navLinks');
	} else {
		var hidden = document.getElementById('jumplist');
	}
	addClass(hidden,'hideme');
}

function fontScale() {  // causes layout problems in FireFox that get fixed if browser's Reload is used; same may be true of other Gecko-based browsers
	if (!s5mode && !isOp) return false;
	var hScreen = screen.width; var vScreen = screen.height;
	var vWindow = window.outerHeight; var hWindow = window.outerWidth;
	if (isOp && s5mode && defaultView=='slideshow' && ((hScreen != hWindow) || (vScreen != vWindow))) {
		toggle();
		return false;
	}
	if (isOp && !s5mode && ((hScreen != hWindow) || (vScreen != vWindow))) return false;
	if (isOp && !s5mode && (hScreen == hWindow) && (vScreen == vWindow)) toggle();
	var vScale = 48;  // both yield 16 (the usual browser default) at 1024x768
	var hScale = 64;  // perhaps should auto-calculate based on theme's declared value?
	if (window.innerHeight) {
		var vSize = window.innerHeight;
		var hSize = window.innerWidth;
	} else if (document.documentElement.clientHeight) {
		var vSize = document.documentElement.clientHeight;
		var hSize = document.documentElement.clientWidth;
	} else if (document.body.clientHeight) {
		var vSize = document.body.clientHeight;
		var hSize = document.body.clientWidth;
	} else {
		var vSize = 700;  // assuming 1024x768, minus chrome and such equals 8:5
		var hSize = 1024; // these do not account for kiosk mode or Opera Show
	}
	var newSize = Math.min(Math.round(vSize/vScale),Math.round(hSize/hScale));
	extendImgSizes(newSize); // scalable images extension
	extendObjSizes(newSize); // scalable object extension
	fontSize(newSize,"px");
	if (isGe) {  // hack to counter incremental reflow bugs
		var obj = document.getElementsByTagName('body')[0];
		obj.style.visibility = 'hidden';
		obj.style.display = 'none';
		obj.style.display = 'block';
		obj.style.visibility = 'visible';
		changeOpac(100,'slide' + snum);
		shiftOpacity('slide' + snum,10);
		window.setTimeout("fixReflow()",10);
	}else {
		setListPos(); // invisible select extension
	}
}

function fixReflow() {
	shiftOpacity('slide' + snum,10);
	window.setTimeout("finishReflow()",10);
}
function finishReflow() {
	setListPos(); // invisible select extension
}

function fontSize(val,fmt) {
	var value = val + fmt;
	if (!(s5ss = document.getElementById('s5ss'))) {
		if (!document.createStyleSheet) {
			document.getElementsByTagName('head')[0].appendChild(s5ss = document.createElement('style'));
			s5ss.setAttribute('media','screen, projection');
			s5ss.setAttribute('id','s5ss');
		} else {
			document.createStyleSheet();
			document.s5ss = document.styleSheets[document.styleSheets.length - 1];
		}
	}
	if (!(document.s5ss && document.s5ss.addRule)) {
		while (s5ss.lastChild) s5ss.removeChild(s5ss.lastChild);
		s5ss.appendChild(document.createTextNode('html {font-size: ' + value + ' !important;}'));
	} else {
		document.s5ss.addRule('html','font-size: ' + value + ' !important;');
	}
}

function windowChange() {
	fontScale();
}

function notOperaFix() {
	slideCSS = document.getElementById('slideProj').href;
	var slides = document.getElementById('slideProj');
	var outline = document.getElementById('outlineStyle');
	slides.setAttribute('media','screen');
	outline.disabled = true;
	if (isGe) {
		slides.setAttribute('href','null');   // Gecko fix
		slides.setAttribute('href',slideCSS); // Gecko fix
	}
	if ((isIE && notIE7) && document.styleSheets && document.styleSheets[0]) {
		document.styleSheets[0].addRule('img', 'behavior: url(ui/graphic_support/iepngfix.htc)');
		document.styleSheets[0].addRule('div', 'behavior: url(ui/graphic_support/iepngfix.htc)');
		document.styleSheets[0].addRule('.slide', 'behavior: url(ui/graphic_support/iepngfix.htc)');
	}
}

function getIncrementals(obj) {
	var incrementals = new Array();
	if (!obj) 
		return incrementals;
	var children = obj.childNodes;
	for (var i = 0; i < children.length; i++) {
		var child = children[i];
		if (hasClass(child, 'incremental')) {
			if (child.nodeName == 'OL' || child.nodeName == 'UL') {
				removeClass(child, 'incremental');
				for (var j = 0; j < child.childNodes.length; j++) {
					if (child.childNodes[j].nodeType == 1) {
						addClass(child.childNodes[j], 'incremental');
					}
				}
			} else {
				incrementals[incrementals.length] = child;
				removeClass(child,'incremental');
			}
		}
		if (hasClass(child, 'show-first')) {
			if (child.nodeName == 'OL' || child.nodeName == 'UL') {
				removeClass(child, 'show-first');
				if (child.childNodes[isGe].nodeType == 1) {
					removeClass(child.childNodes[isGe], 'incremental');
				}
			} else {
				incrementals[incrementals.length] = child;
			}
		}
		incrementals = incrementals.concat(getIncrementals(child));
	}
	return incrementals;
}

function createIncrementals() {
	var incrementals = new Array();
	for (var i = 0; i < smax; i++) {
		incrementals[i] = getIncrementals(document.getElementById('slide'+i));
	}
	return incrementals;
}

function trap(e) {
	if (!e) {
		e = event;
		e.which = e.keyCode;
	}
	try {
		modifierKey = e.ctrlKey || e.altKey || e.metaKey;
	}
	catch(e) {
		modifierKey = false;
	}
	return modifierKey || e.which == 0;
}

// notes extension
function noteLabel() { // Gives notes id's to match parent slides
	var notes = GetElementsWithClassName('div','notes');
	for (var i = 0; i < notes.length; i++) {
		var note = notes[i];
		var id = 'note' + note.parentNode.id.substring(5);
		note.setAttribute('id',id);
	}
	resetElapsedSlide();
	resetRemainingTime();
	window.setInterval('updateElaspedTime()', 1000);
}

function createNotesWindow() { // creates a window for our notes
	if (!s5NotesWindow || s5NotesWindow.closed) { // Create the window if it doesn't exist
		s5NotesWindowLoaded = false;
		// Note: Safari has a tendency to ignore window options preferring to default to the settings of the parent window, grr.
		s5NotesWindow = window.open('ui/s5-notes.html', 's5NotesWindow', 'top=0,left=0');
	}
	if (s5NotesWindowLoaded) { // Load the current note if the Note HTML has loaded
		loadNote();
	} else { // Keep trying...
		window.setTimeout('createNotesWindow()', 50);
	}
}

function loadNote() {
// Loads a note into the note window
	var notes = nextNotes = '<em class="disclaimer">There are no notes for this slide.</em>';
	if (document.getElementById('note' + snum)) {
		notes = document.getElementById('note' + snum).innerHTML;
	}
	if (document.getElementById('note' + (snum + 1))) {
		nextNotes = document.getElementById('note' + (snum + 1)).innerHTML;
	}
	
	var jl = document.getElementById('jumplist');
	var slideTitle = jl.options[jl.selectedIndex].text.replace(/^\d+\s+:\s+/, '') + ((jl.selectedIndex) ? ' (' + jl.selectedIndex + '/' + (smax - 1) + ')' : '');
	if (incrementals[snum].length > 0) {
		slideTitle += ' <small>[' + incpos + '/' + incrementals[snum].length + ']</small>';
	}
	if (jl.selectedIndex < smax - 1) {
		var nextTitle = jl.options[jl.selectedIndex + 1].text.replace(/^\d+\s+:\s+/, '') + ((jl.selectedIndex + 1) ? ' (' + (jl.selectedIndex + 1) + '/' + (smax - 1) + ')' : '');
	} else {
		var nextTitle = '[end of slide show]';
	}
	
	if (s5NotesWindow && !s5NotesWindow.closed && s5NotesWindow.document) {
		s5NotesWindow.document.getElementById('slide').innerHTML = slideTitle;
		s5NotesWindow.document.getElementById('notes').innerHTML = notes;
		s5NotesWindow.document.getElementById('next').innerHTML = nextTitle;
		s5NotesWindow.document.getElementById('nextnotes').innerHTML = nextNotes;
	}
	resetElapsedSlide();
}

function minimizeTimer(id) {
	var obj = s5NotesWindow.document.getElementById(id);
	if (hasClass(obj,'collapsed')) {
		removeClass(obj,'collapsed');
	} else {
		addClass(obj,'collapsed');
	}
}

function resetElapsedTime() {
	presentationStart = new Date();
	slideStart = new Date();
	updateElaspedTime();
}

function resetElapsedSlide() {
	if (snum != previousSlide) {
		slideStart = new Date();
		previousSlide = snum;
		updateElaspedTime();
	}
}

function updateElaspedTime() {
	if (!s5NotesWindowLoaded || !s5NotesWindow || s5NotesWindow.closed) return;
	var now = new Date();
	var ep = s5NotesWindow.document.getElementById('elapsed-presentation');
	var es = s5NotesWindow.document.getElementById('elapsed-slide');
	ep.innerHTML = formatTime(now.valueOf() - presentationStart.valueOf());
	es.innerHTML = formatTime(now.valueOf() - slideStart.valueOf());
}

function resetRemainingTime() {
	if (!s5NotesWindowLoaded || !s5NotesWindow || s5NotesWindow.closed) return;
	var startField = s5NotesWindow.document.getElementById('startFrom');
	startFrom = readTime(startField.value);
	countdown.remaining = startFrom * 60000;  // convert to msecs
	countdown.start = new Date().valueOf();
	countdown.end = countdown.start + countdown.remaining;
	var tl = s5NotesWindow.document.getElementById('timeLeft');
	var timeLeft = formatTime(countdown.remaining);
	tl.innerHTML = timeLeft;
}

function updateRemainingTime() {
	if (!s5NotesWindowLoaded || !s5NotesWindow || s5NotesWindow.closed) return;
	var tl = s5NotesWindow.document.getElementById('timeLeft');
	var now = new Date();
	if (countdown.state == 'run') {
		countdown.remaining = countdown.end - now;
	}
	tl.style.color = '';
	tl.style.backgroundColor = '';
	if (countdown.remaining >= 0) {
		var timeLeft = formatTime(countdown.remaining);
		removeClass(tl,'overtime');
		if (countdown.remaining < 300000) {
			tl.style.color = 'rgb(' + (255-Math.round(countdown.remaining/2000)) + ',0,0)';
			tl.style.backgroundColor = 'rgb(255,255,' + (Math.round(countdown.remaining/2000)) + ')';
		}
	} else {
		var timeLeft = '-' + formatTime(-countdown.remaining);
		addClass(tl,'overtime');
	}
	tl.innerHTML = timeLeft;
}

function toggleRemainingTime() {
	if (countdown.state == 'pause') countdown.state = 'run'; else countdown.state = 'pause';
	if (countdown.state == 'pause') {
		window.clearInterval(countdown.timer);
	}
	if (countdown.state == 'run') {
		countdown.start = new Date().valueOf();
		countdown.end = countdown.start + countdown.remaining;
		countdown.timer = window.setInterval('updateRemainingTime()', 1000);
	}
}

function alterRemainingTime(amt) {
	var change = amt * 60000;  // convert to msecs
	countdown.end += change;
	countdown.remaining += change;
	updateRemainingTime();
}

function formatTime(msecs)  {
	var time = new Date(msecs);
	
	var hrs = time.getUTCHours() + ((time.getUTCDate() -1) * 24); // I doubt anyone will spend more than 24 hours on a presentation or single slide but just in case...
	hrs = (hrs < 10) ? '0'+hrs : hrs;
	if (hrs == 'NaN' || isNaN(hrs)) hrs = '--';
	
	var min = time.getUTCMinutes();
	min = (min < 10) ? '0'+min : min;
	if (min == 'NaN' || isNaN(min)) min = '--';
	
	var sec = time.getUTCSeconds();
	sec = (sec < 10) ? '0'+sec : sec;
	if (sec == 'NaN' || isNaN(sec)) sec = '--';

	return hrs + ':' + min + ':' + sec;
}

function readTime(val) {
	var sregex = /:/;
	var matches = sregex.exec(val);
	if (matches == null) {
		return val;
	} else {
		var times = val.split(':');
		var hours = parseInt(times[0]);
		var mins = parseInt(times[1]);
		var total = (hours * 60) + mins;
		return total;
	}
}
// notes extension

// startup process
function createSlideShow() {
	defaultCheck();	
	if(!isIE) createDetector(); // (degrade IE) scalable images extension 
	if(opac!=0 || isIE) { // &&!isIE (degrade IE)
		tranSitions = false;
		fadeModus = false;
	}
	if(tranSitions && document.getElementById && document.createElement){
		createProgress();
		var nop=document.getElementById('StartupControl');
		nop.onload = dumpProgress;
	}else {
		startup();
		showAll();
		setListPos(true); // invisible select extension
		panelSetup();
		audioSetup(); // audio extension	
	}
}

function defaultCheck() {
	var allMetas = document.getElementsByTagName('meta');
	for (var i = 0; i< allMetas.length; i++) {
		if (allMetas[i].name == 'defaultView') {
			defaultView = allMetas[i].content;
		}
		if (allMetas[i].name == 'controlVis') {
			controlVis = allMetas[i].content;
		}
		if (allMetas[i].name == 'tranSitions') {
			tranSitions = (allMetas[i].content == "true") ? true : false;
			fadeModus = (tranSitions == true) ? true : false;
		}
		if (allMetas[i].name == 'fadeDuration') {
			var tmp = parseInt(allMetas[i].content);
			fadeDuration = Math.max(200,Math.min(tmp,2000));
		}
		if (allMetas[i].name == 'incrDuration') {
			var tmp = parseInt(allMetas[i].content);
			incrDuration = Math.max(50,Math.min(tmp,500));
		}
		if (allMetas[i].name == 'autoMatic') {
			autoMatic = (allMetas[i].content == "true") ? true : false;
		}
		if (allMetas[i].name == 'playLoop') {
			playLoop = (allMetas[i].content == "true") ? true : false;
		}
		if (allMetas[i].name == 'playDelay') {
			var tmp = parseInt(allMetas[i].content);
			playDelay = Math.max(5,Math.min(tmp,90))*1000;
			playDelay = (fadeModus == true) ? (playDelay+(2*fadeDuration)) : playDelay;
		}
		if (allMetas[i].name == 'audioSupport') {
			audioSupport = (allMetas[i].content == "true") ? true : false;
		}
		if (allMetas[i].name == 'audioVolume') {
			var tmp = parseInt(allMetas[i].content);
			audioVolume = Math.max(0,Math.min(tmp,100));
		}
		if (allMetas[i].name == 'audioError') {
			audioError = (allMetas[i].content == "true") ? true : false;
		}						
	}
}

function createProgress() {
	var obj = document.getElementsByTagName("body")[0].firstChild;
	var pg = document.createElement('div');
	pg.id = "StartupProgress";
	pg.style.position = 'absolute';
	pg.style.left = 0 + 'px';
	pg.style.top = 0 + 'px';
	pg.style.width = 100 + '%';
	pg.style.height = 100 + '%';
	pg.style.margin = 0 + 'px';
	pg.style.padding = 0 + 'px';
	if (isIE) {
		pg.style.filter = "alpha(opacity=100)";	
	}else {
		pg.style.opacity = 1.0;
	}	pg.style.zIndex = 9999;
	pg.style.backgroundColor="rgb(255, 255, 255)";
	pg.style.textAlign = "center";	pg.style.verticalAlign = "middle";
	pg.style.backgroundPosition="center center";
	pg.style.backgroundRepeat="no-repeat";
	pg.style.backgroundImage="url(ui/graphic_support/progress.gif)";
	document.getElementsByTagName("body")[0].insertBefore(pg,obj);

	var im = document.createElement('img');
	im.id = "StartupControl";
	im.src = "ui/graphic_support/blank.gif?" + new Date().valueOf();
	document.getElementsByTagName("body")[0].appendChild(im);
}

function startup() {
	createControls(); // hallvord
	slideLabel();
	incrementals = createIncrementals();
	noteLabel(); // [SI:060104] must follow slideLabel()
	loadNote();
	fixLinks();
	externalLinks();
	fontScale();
	if (!isOp) {
		if(isIE) {
			document.getElementById('lst').style.backgroundImage = 'none';
			document.getElementById('del').style.backgroundImage = 'none';
		}else {
			document.getElementById('audio').style.backgroundImage = 'none';
		}
		notOperaFix();
	}else if(isOp) {
		var obj = document.getElementById('exit');
		obj.firstChild.style.visibility = 'hidden';
		document.getElementById('exit').style.opacity = 0.5;
		obj = document.getElementById('toggle');
		obj.firstChild.style.visibility = 'hidden';
		document.getElementById('toggle').style.opacity = 0.5;
		document.getElementById('jumplist').style.visibility = 'hidden';
		document.getElementById('list').style.visibility = 'hidden';
		document.getElementById('lst').style.opacity = 0.5;
		obj = document.getElementById('audio');
		obj.firstChild.style.visibility = 'hidden';
		document.getElementById('audio').style.opacity = 0.5;
		document.getElementById('volumelist').style.visibility = 'hidden';
		document.getElementById('volume').style.visibility = 'hidden';
		document.getElementById('vol').style.opacity = 0.5;
		document.getElementById('delaylist').style.visibility = 'hidden';
		document.getElementById('delay').style.visibility = 'hidden';
		document.getElementById('del').style.opacity = 0.5;
	}
	slideJump();
	if (defaultView == 'outline') toggle();
	document.onkeyup = keys;
	document.onkeypress = trap;
	document.onclick = clicker;
}

function preloadImgages() {
	var temp = '';
	var objects = document.getElementsByTagName('img');
	for (var i=0; i < objects.length; i++) {
		if(objects[i].src != '') {
			temp = new Image(); 
			temp.src = objects[i].src;
		}
	}
}

function showAll() {
	var obj1 = GetElementsWithClassName('div','presentation')[0];
	if(!obj1) var obj1 = GetElementsWithClassName('ol','presentation')[0];
	var obj2 = GetElementsWithClassName('div','layout')[0];
	if(!obj1){}else {obj1.style.display = 'block'};
	if(!obj2){}else {obj2.style.display = 'block'};
}

function dumpProgress() {
	document.body.removeChild(document.getElementById('StartupControl'));
	startup();
	preloadImgages();
	showAll();
	createSoundManagerScript();
	shiftOpacity('StartupProgress',1000);
	window.setTimeout("removeProgress()",1000);}

function removeProgress() {
	document.body.removeChild(document.getElementById('StartupProgress'));
	setListPos(true); // invisible select extension
	panelSetup();
	audioSetup(); // audio extension
}
function panelSetup() {
	if(playPause) {	
		var obj = document.getElementById('pause'); changeClass(obj,'ison');
	}
	if(playLoop) {	
		var obj = document.getElementById('loop'); changeClass(obj,'ison');
	}
	if(audioSupport && !isIE && !isOp) {	
		var obj = document.getElementById('audio'); changeClass(obj,'ison');
	}
	if(fadeModus && !isIE) {	
		var obj = document.getElementById('fade'); changeClass(obj,'ison');
	}
	if(autoMatic) {
		var obj = document.getElementById('auto'); changeClass(obj,'ison');
		startPlay();
	}
	if(audioVolume && !isIE && !isOp) {
		var idx = 0;
		if(audioVolume >= 95 && audioVolume <= 100) {idx = 0;}
		else if(audioVolume >= 85 && audioVolume < 95) {idx = 1;}
		else if(audioVolume >= 75 && audioVolume < 85) {idx = 2;}
		else if(audioVolume >= 65 && audioVolume < 75) {idx = 3;}
		else if(audioVolume >= 55 && audioVolume < 65) {idx = 4;}
		else if(audioVolume >= 45 && audioVolume < 55) {idx = 5;}
		else if(audioVolume >= 35 && audioVolume < 45) {idx = 6;}
		else if(audioVolume >= 25 && audioVolume < 35) {idx = 7;}
		else if(audioVolume >= 15 && audioVolume < 25) {idx = 8;}
		else if(audioVolume >= 5 && audioVolume < 15) {idx = 9;}
		else {idx = 10;}
		document.getElementById('volumelist').selectedIndex = idx;
	}
	if(playDelay && !isOp) {
		var idx = 0; var vol = parseInt(playDelay/1000);
		if(vol >= 83 && vol <= 90) {idx = 0;}
		else if(vol >= 68 && vol < 83) {idx = 1;}
		else if(vol >= 53 && vol < 68) {idx = 2;}
		else if(vol >= 38 && vol < 53) {idx = 3;}
		else if(vol >= 25 && vol < 38) {idx = 4;}
		else if(vol >= 18 && vol < 25) {idx = 5;}
		else if(vol >= 13 && vol < 18) {idx = 6;}
		else if(vol >= 8 && vol < 13) {idx = 7;}
		else {idx = 8;}
		document.getElementById('delaylist').selectedIndex = idx;		
	}
}
// startup process

// shutdown process
function byby() {
	stopPlay();
	if(tranSitions && fadeModus && s5mode && !isOp) {
		fadeoutSound(curSoundID,true); // audio support
		var pg = document.createElement('div');
		pg.id = "GoodBy";
		pg.style.position = 'absolute';
		pg.style.left = 0 + 'px';
		pg.style.top = 0 + 'px';
		pg.style.width = 100 + '%';
		pg.style.height = 100 + '%';
		pg.style.margin = 0 + 'px';
		pg.style.padding = 0 + 'px';
		if (isIE) {
			pg.style.filter = "alpha(opacity=0)";	
		}else {
			pg.style.opacity = 0.0;
		}		pg.style.zIndex = 9999;
		pg.style.backgroundColor="rgb(255, 255, 255)";
		document.getElementsByTagName("body")[0].appendChild(pg);
		shiftOpacity('GoodBy',1000);
		window.setTimeout("history.back()",1000);	}else {
		stopSound(curSoundID); 
		history.back();
	}
}
// shutdown process

// scalable images extension
function createDetector() {
	var em = document.createElement('div');
	em.id='EMSizeControl'; em.style.position="absolute"; em.style.left="-999px";
	em.style.width="1em"; em.style.height="1em"; em.style.opacity=0.0;
	document.getElementsByTagName("body")[0].appendChild(em);
	var nop=document.getElementById('EMSizeControl');
	if(!nop||findPosX(nop)!=-999) {}else {
		opac=document.getElementById('EMSizeControl').style.opacity;
		empx=document.getElementById('EMSizeControl').offsetHeight;
		document.body.removeChild(document.getElementById('EMSizeControl'));
		var objects = document.getElementsByTagName('img'); var j = 0; var i = 0; 
		for (i=0; i < objects.length; i++) {
			if(objects[i].className.match(/^scale/i)) {
				images[j] = objects[i];
				++j;
			}
		}
		objects = document.getElementsByTagName('object'); j = 0; i = 0;
		for (i=0; i < objects.length; i++) {
			if(objects[i].className.match(/^scale/i)) {
				medias[j] = objects[i]; ++j;
				if(!isIE) {
  					if(objects[i].getAttributeNode("classid")) objects[i].removeAttributeNode(objects[i].getAttributeNode("classid"));
				  	if(objects[i].getAttributeNode("codebase")) objects[i].removeAttributeNode(objects[i].getAttributeNode("codebase"));
				}
			}
		}
	}
}
function extendImgSizes(f) {
	if(empx>0) {
		var q = (f/empx); var w = 0; var h = 0;
		for(var i=0; i < images.length; i++) {
			w=images[i].getAttribute("width",0); 
			h=images[i].getAttribute("height",0);
			if(w>0&&h>0) {
				images[i].style.width=Math.floor(w*q)+"px";				images[i].style.height=Math.floor(h*q)+"px";
			}
		}
	}
}
function extendObjSizes(f) {
	if(empx>0) {
		var q = (f/empx); var w = 0; var h = 0;
		for(var i=0; i < medias.length; i++) {
			w=medias[i].getAttribute("width",0); 
			h=medias[i].getAttribute("height",0);
			if(w>0&&h>0) {
				medias[i].style.width=Math.floor(w*q)+"px";				medias[i].style.height=Math.floor(h*q)+"px";
			}
		}
	}
}
function findPosX(obj) {
	var posLeft = 0;
	while (obj.offsetParent) {
		posLeft += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return posLeft;
}
function findPosY(obj) {
	var posTop = 0;
	while (obj.offsetParent) {
		posTop += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return posTop;
}
// scalable images extension

// invisible select extension
function setListPos(opt) {
	if(!isIE) { //(degrade IE)
		var ref = document.getElementById('list');
		var x = findPosX(ref); var y = findPosY(ref);
		var obj = document.getElementById('jumplist');
		obj.style.position = 'fixed'; obj.style.left = x + 'px'; obj.style.top = y + 'px';	
		var vol = document.getElementById('volumelist');
		ref = document.getElementById('volume');
		x = findPosX(ref); if(isOp) {y = window.innerHeight-imgHeight; }else {y = findPosY(ref);} 
		vol.style.position = 'fixed'; vol.style.left = x + 'px'; vol.style.top = y + 'px';	
		var del = document.getElementById('delaylist');
		ref = document.getElementById('delay');
		x = findPosX(ref); if(isOp) {y = window.innerHeight-imgHeight; }else {y = findPosY(ref);} 
		del.style.position = 'fixed'; del.style.left = x + 'px'; del.style.top = y + 'px';	
		var pnl = document.getElementById('navLinks');
	}
	if(opt) {
		if(isIE) {
			//(degrade IE)
			//pnl.style.filter = "alpha(opacity=80)";	
		}else {
			obj.style.opacity = 0.0;
			vol.style.opacity = 0.0;
			del.style.opacity = 0.0;
			pnl.style.opacity = 0.8;
		}
	}
}
// invisible select extension

// transition extension
function switchFade() {
	if(tranSitions && s5mode && fadeModus) {
		fadeModus = false; 
		playDelay = playDelay-(2*fadeDuration);
		var obj = document.getElementById('fade'); changeClass(obj,'isoff');
	}else if(tranSitions && s5mode && !fadeModus) {
		fadeModus = true; 
		playDelay = playDelay+(2*fadeDuration);
		var obj = document.getElementById('fade'); changeClass(obj,'ison');
	}
	currentSlide();
}
function opacity(ids, opacStart, opacEnd, millisec) {	var speed = Math.round(millisec / 100);	var timer = 0;	if(opacStart > opacEnd) {		for(var i = opacStart; i >= opacEnd; i--) {			window.setTimeout("changeOpac(" + i + ",'" + ids + "')",(timer * speed));			timer++;		}	} else if(opacStart < opacEnd) {		for(var i = opacStart; i <= opacEnd; i++) {			window.setTimeout("changeOpac(" + i + ",'" + ids + "')",(timer * speed));			timer++;		}	}
}function changeOpac(opacity, ids) {	var obj = document.getElementById(ids); 
	if (isIE) {
		obj.style.filter = "alpha(opacity=" + opacity + ")";	} else {		obj.style.opacity = (opacity / 100);	}}function shiftOpacity(ids, millisec) {	if(document.getElementById(ids).style.opacity != '') {		var currentOpac = document.getElementById(ids).style.opacity * 100;
	} else {
		var currentOpac = 0;
	}
	if(currentOpac == 0) {
		opacity(ids, currentOpac, 100, millisec);	} else if(currentOpac > 0) {
		opacity(ids, currentOpac, 0, millisec);	}}
// transition extension

// autoplay extension
function autoPlay() {
	if (s5mode && autoMatic && !playPause) {
		if ((snum >= (smax-1)) && playLoop) {
			goTo(0);
			autoRun = setTimeout('autoPlay();',playDelay);
		}else if ((snum >= (smax-1)) && !playLoop) {
			stopPlay();
		}else {
			if (!incrementals[snum] || incpos >= incrementals[snum].length) {
				go(1);
				if (incrementals[snum].length >0) {
					clearTimeout(autoRun); autoRun = null;
					incrDelay = parseInt(playDelay/(incrementals[snum].length+1));
					remainDer = parseInt(playDelay-(incrDelay*incrementals[snum].length));
					autoRun = setTimeout('autoPlayIncr()',incrDelay);
				}
			} else {
				clearTimeout(autoRun); autoRun = null;
				incrDelay = incrDuration;
				remainDer = parseInt(playDelay-(incrementals[snum].length*incrDuration));
				autoRun = setTimeout('autoPlayIncr()',incrDelay);
			}
			autoRun = setTimeout('autoPlay();',playDelay);
		}  
	}
}
function autoPlayIncr() {
	if (incpos < incrementals[snum].length) {
		subgo(1);
		autoRun = setTimeout('autoPlayIncr();',incrDelay);
	}else {
		autoRun = setTimeout('nop();',remainDer);
	}
}
function nop() {
	// no operation dummy
}
function togglePlay() {
	if (autoRun && s5mode) {
		stopPlay();
	}else if (!autoRun && s5mode) {
		startPlay();
	}
}
function stopPlay() {
	if (autoRun && s5mode) {
		clearTimeout(autoRun); autoRun = null; 
		autoMatic = false; playPause = false; var obj = '';
		obj = document.getElementById('auto'); changeClass(obj,'isoff');
		obj = document.getElementById('pause'); changeClass(obj,'isoff');
		currentSlide();
	}
}
function startPlay() {
	if (!autoRun && s5mode) {
		playPause = false; autoMatic = true; var obj = '';
		obj = document.getElementById('auto'); changeClass(obj,'ison');
		obj = document.getElementById('pause'); changeClass(obj,'isoff');
		autoRun = setTimeout('autoPlay();',playDelay); 
		currentSlide();
	}
}
function pausePlay() {
	if (s5mode && autoMatic) {
		if (playPause) {
			playPause = false; autoRun = setTimeout('autoPlay();',playDelay);
			var obj = document.getElementById('pause'); changeClass(obj,'isoff');
		}else {
			if (autoRun){ 
				clearTimeout(autoRun); autoRun = null; playPause = true;
				var obj = document.getElementById('pause'); changeClass(obj,'ison');
			}
		}
		currentSlide();
	}
}
function switchLoop() {
	if(s5mode) {
		if (playLoop) {
			playLoop = false; 
			var obj = document.getElementById('loop'); changeClass(obj,'isoff');
		}else {
			playLoop = true; 
			var obj = document.getElementById('loop'); changeClass(obj,'ison');
		} 
	}
	currentSlide();
}
function setDelay() {
	var val = document.getElementById('delaylist');
	if(s5mode) {
		var delay = Math.max(5,Math.min(parseInt(val.value),300));
		playDelay = (fadeModus == true) ? ((delay*1000)+(2*fadeDuration)) : (delay*1000);
	}
}
// autoplay extension

// audio extension
function createSoundManagerScript() {
	if(typeof soundManager=="undefined") {
		onerrorSM2();	
	}else {
		var script=document.createElement('SCRIPT');
		var tx=document.createTextNode("soundManager.createMovie();");
		script.appendChild(tx);
		document.getElementsByTagName("body")[0].appendChild(script);
	}
}
//soundManager.onload = function() {
function onloadSM2() {
	if(!isIE) { //(degrade IE)	
		swfUnloaded = false;
		preloadSounds();
	}
}
//soundManager.onerror = function() {
function onerrorSM2() {
	if(typeof soundManager!="undefined") {
		soundManager.destruct;
		delete soundManager;
	}	
	audioSupport = false; swfUnloaded = true;
	if(audioError && !isIE && !isOp) {
		var dv = document.createElement('div'); dv.id = "guru";
		var d2=document.createElement('div'); dv.appendChild(d2);		var tx=document.createTextNode('Guru Meditation - SoundManager failed to load/initialize!');
		d2.appendChild(tx);	document.getElementById('slide0').appendChild(dv);
	}
}
function audioSetup() {
	if(sound[0]) {
		playSound(0); 
	}else if(sound[bgSoundItem] && !sound[0]) {
		playSound(bgSoundItem); 
	}
}
function fadeoutSound(ids, option) {
	if(curSoundID >= 0  && !swfUnloaded) {
		if(isNaN(ids)) {
			if(ids == "bgSound") {
				var cnum = parseInt(bgSoundItem);
			}else {
				for (var i = 0; i < (sound.length-1); i++) {
					if(sound[i] && ids == sound[i]["id"]) {
						var cnum = i;
						break;
					}
				}
			}
		}else {
			var cnum = ids;
			ids = sound[cnum]["id"];
		}	
		var vol = getMaxVolume(sound[cnum]["volume"]);
		var millisec = fadeDuration;
		var speed = Math.round(millisec / vol);		var timer = 0;		for(var i = vol; i > 0; i--) {			setTimeout("fadeout(" + i + ",'" + ids + "')",(timer * speed));			timer++;		}
		if(option) setTimeout("stopSound('"+ids+"')",millisec);
	}
}
function fadeout(volume, id) {	soundManager.setVolume(id,volume);}
function stopSound(ids) {
	var sid;
	if(isNaN(ids)) {
		sid = ids;
	}else if(sound[ids]) {
		sid = sound[ids]["id"];
	}
	if(sid!='' && curSoundID >= 0) {
		soundManager.stop(sid);
		curSoundID = -1;
	}
}
function toggleSounds() {
	if(audioSupport && !swfUnloaded) {
		stopAllSounds();
	}else if (!audioSupport && !swfUnloaded) {
		allowSounds();
	}
}
function allowSounds() {
	if(!swfUnloaded) {
		audioSupport = true;
		var obj = document.getElementById('audio'); changeClass(obj,'ison');
		currentSlide();
	}
}
function stopAllSounds() {
	if(curSoundID >= 0) {
		stopSound(curSoundID);
	}else {
		soundManager.stopAll();
		curSoundID = -1;
	}
	audioSupport = false;
	var obj = document.getElementById('audio'); changeClass(obj,'isoff');
	currentSlide();
}
function playSound(id) {
	if(audioSupport && !swfUnloaded) {
		var url, sid, vol, lps, cnum;
		if(isNaN(id)) {
			sid = id;
			if(sid == "bgSound") {
				cnum = parseInt(bgSoundItem);
			}else {
				cnum = getSoundID(id);
			}
		}else {
			cnum = parseInt(id); 
			if(sound[cnum]) sid = sound[cnum]["id"];
		}		
		if(sound[cnum] && sound[cnum]["url"]!='' && sid!=''){
			url = sound[cnum]["url"];
			vol = (sound[cnum]["volume"]!='')?getMaxVolume(sound[cnum]["volume"]):getMaxVolume(100);
			lps = (sound[cnum]["loops"])?true:false;			
			if(lps) {
				soundManager.play(sid,{volume:vol,onplay:function(){curSoundID=cnum;},onfinish:function(){soundManager.play(sid,{volume:getMaxVolume(sound[cnum]["volume"])});}});
			}else { 
				soundManager.play(sid,{volume:vol,onplay:function(){curSoundID=cnum;},onfinish:function(){curSoundID=-1;}});
			}
		}
	}	
}
function getSoundID(str) {
	for (var i = 0; i < (sound.length-1); i++) {
		if(sound[i] && str == sound[i]["id"]) {
			var id = i;
			break;
		}
	}
	return id;
}
function setVolume() {
	var vol = document.getElementById('volumelist');
	if(audioSupport && !swfUnloaded) {
		audioVolume = parseInt(vol.value);
		if(curSoundID >= 0) {
			if(sound[curSoundID]) {
				var sid = sound[curSoundID]["id"];
				var vid = getMaxVolume(sound[curSoundID]["volume"]);
				soundManager.setVolume(sid,vid);
			}
		}	}	
}
function getMaxVolume(value) {
	if(audioVolume>0) {var factor = audioVolume/100;}else {var factor = 0;}
	return Math.max(0,Math.min(parseInt(value*factor),audioVolume));
}
function preloadSounds() {
	var temp = ''; var parm = ''; var t = ''; var cl = '';
	var objects = document.getElementsByTagName('object');
	for (var i=0; i < objects.length; i++) {
		if(objects[i].type.toLowerCase() == 'audio/mp3' && objects[i].data != '') {
			objects[i].width = 0; objects[i].height = 0;
			if(objects[i].parentNode.tagName == 'DIV') {
				cl = objects[i].parentNode.className.toLowerCase();			
				if(cl == 'presentation' || cl == 'slide') {
					if(cl == 'presentation') {
						t = parseInt(bgSoundItem);
					}else {
						t = parseInt(objects[i].parentNode.id.slice(5, objects[i].parentNode.id.length));
					}	
					sound[t] = new Object();
					if(t < bgSoundItem) {
						sound[t]["id"] = objects[i].parentNode.id;
					}else {
						sound[t]["id"] = "bgSound";
					}	
					sound[t]["url"] = objects[i].data;
					sound[t]["volume"] = 100; sound[t]["loops"] = false;
					if(objects[i].archive != '') {
						parm = objects[i].archive.toLowerCase().split(',');
						for (var j=0; j < parm.length; j++) {
							if(parm[j] == 'loop') sound[t]["loops"] = true;
							if(parm[j].search(/^volume/) != -1) {
								var tmp = parm[j].split(':');
								sound[t]["volume"] = parseInt(tmp[1]);
							}
						}
					}
					soundManager.createSound(sound[t]["id"],sound[t]["url"]);
				}
			}			
		}
	}
}
// audio extension

document.write('<style type="text/css" media="screen" id="blockStyle">.presentation, .layout {display: none; }</style>');

if(!isIE && !isOp) {
	document.write('<script type="text/javascript" src="ui/audio_support/soundmanager2.js"></script>');
	if(typeof soundManager!="undefined") {
		var allMetas = document.getElementsByTagName('meta');
		for (var i = 0; i< allMetas.length; i++) {
			if (allMetas[i].name == 'audioDebug') {
				var audioDebug = (allMetas[i].content == "true") ? true : false;
				soundManager.defaultOptions.debugMode = audioDebug;
			}						
		}
	}
}

window.onload = createSlideShow;
window.onresize = function(){setTimeout('windowChange()',5);}
