1// S5 1.3beta7 (18-Apr-2007) advanced version by C. Effenberger
2// Please see http://s5.netzgesta.de/ for more information
3// based on S5 v1.2a1 slides.js -- released into the Public Domain
4// Please see http://www.meyerweb.com/eric/tools/s5/credits.html for information
5// about all the wonderful and talented contributors to this code!
6// audio extension: soundmanager2 is NOT Public Domain
7// Please see http://www.schillmania.com/projects/soundmanager2/ for information
8
9var undef;
10var slideCSS = '';
11var snum = 0;
12var smax = 1;
13var incpos = 0;
14var number = undef;
15var firstTime = 1;
16var s5mode = true;
17var helpmode = false;
18var defaultView = 'slideshow'; //outline
19var controlVis = 'visible';
20var s5Path = 'lib/plugins/s5reloaded/';
21
22// scalable images extension
23var empx = 0;
24var images = new Array();
25var canvas = new Array();
26var medias = new Array();
27var piecharts = new Array();
28var barcharts = new Array();
29var linecharts = new Array();
30// scalable images extension
31
32// transition extension
33var tranSitions = false;
34var fadeModus = false;
35var fadeDuration = 500;
36var incrDuration = 250;
37var opac = 1;
38var cid = '';
39var nid = '';
40var tid = '';
41var jl = '';
42// transition extension
43
44// autoplay extension
45var autoMatic = false;
46var playLoop = false;
47var playPause = false;
48var autoRun = false;
49var playDelay = 5000;
50var remainDer = 0;
51var incrDelay = 0;
52// autoplay extension
53
54// audio extension
55var sound = new Array();
56var audioSupport = false;
57var audioVolume = 100;
58var audioError = false;
59var swfUnloaded = true;
60var bgSoundItem = 9999;
61var curSoundID = -1;
62// audio extension
63
64// panel extension
65var imgWidth = 32;
66var imgHeight = 32;
67// panel extension
68
69// canvas chart extension
70var canvasSupport = false;
71var ChartData = new Array();
72var colorSlice = new Array();
73var font = document.createElement("img");
74font.setAttribute("src", s5Path+"ui/graphic_support/numeric.png");
75signs = {
76	'0': {sx: 0, sy: 0, sw: 48, sh: 64},
77	'1': {sx: 48, sy: 0, sw: 48, sh: 64},
78	'2': {sx: 96, sy: 0, sw: 48, sh: 64},
79	'3': {sx: 144, sy: 0, sw: 48, sh: 64},
80	'4': {sx: 192, sy: 0, sw: 48, sh: 64},
81	'5': {sx: 240, sy: 0, sw: 48, sh: 64},
82	'6': {sx: 288, sy: 0, sw: 48, sh: 64},
83	'7': {sx: 336, sy: 0, sw: 48, sh: 64},
84	'8': {sx: 384, sy: 0, sw: 48, sh: 64},
85	'9': {sx: 432, sy: 0, sw: 48, sh: 64},
86	'%': {sx: 480, sy: 0, sw: 48, sh: 64},
87	'.': {sx: 528, sy: 0, sw: 24, sh: 64}
88};
89var colorNames= new Array();
90colorNames["black"]="#000000"; colorNames["maroon"]="#800000";
91colorNames["green"]="#008000"; colorNames["olive"]="#808000";
92colorNames["navy"]="#000080"; colorNames["purple"]="#800080";
93colorNames["teal"]="#008080"; colorNames["gray"]="#808080";
94colorNames["silver"]="#C0C0C0"; colorNames["red"]="#FF0000";
95colorNames["lime"]="#00FF00"; colorNames["yellow"]="#FFFF00";
96colorNames["blue"]="#0000FF"; colorNames["fuchsia"]="#FF00FF";
97colorNames["aqua"]="#00FFFF"; colorNames["white"]="#FFFFFF";
98colorNames["aliceblue"]="#F0F8FF"; colorNames["antiquewhite"]="#FAEBD7";
99colorNames["aquamarine"]="#7FFFD4"; colorNames["azure"]="#F0FFFF";
100colorNames["beige"]="#F5F5DC"; colorNames["blueviolet"]="#8A2BE2";
101colorNames["brown"]="#A52A2A"; colorNames["burlywood"]="#DEB887";
102colorNames["cadetblue"]="#5F9EA0"; colorNames["chartreuse"]="#7FFF00";
103colorNames["chocolate"]="#D2691E"; colorNames["coral"]="#FF7F50";
104colorNames["cornflowerblue"]="#6495ED"; colorNames["cornsilk"]="#FFF8DC";
105colorNames["crimson"]="#DC143C"; colorNames["darkblue"]="#00008B";
106colorNames["darkcyan"]="#008B8B"; colorNames["darkgoldenrod"]="#B8860B";
107colorNames["darkgray"]="#A9A9A9"; colorNames["darkgreen"]="#006400";
108colorNames["darkkhaki"]="#BDB76B"; colorNames["darkmagenta"]="#8B008B";
109colorNames["darkolivegreen"]="#556B2F"; colorNames["darkorange"]="#FF8C00";
110colorNames["darkorchid"]="#9932CC"; colorNames["darkred"]="#8B0000";
111colorNames["darksalmon"]="#E9967A"; colorNames["darkseagreen"]="#8FBC8F";
112colorNames["darkslateblue"]="#483D8B"; colorNames["darkslategray"]="#2F4F4F";
113colorNames["darkturquoise"]="#00CED1"; colorNames["darkviolet"]="#9400D3";
114colorNames["deeppink"]="#FF1493"; colorNames["deepskyblue"]="#00BFFF";
115colorNames["dimgray"]="#696969"; colorNames["dodgerblue"]="#1E90FF";
116colorNames["firebrick"]="#B22222"; colorNames["floralwhite"]="#FFFAF0";
117colorNames["forestgreen"]="#228B22"; colorNames["gainsboro"]="#DCDCDC";
118colorNames["ghostwhite"]="#F8F8FF"; colorNames["gold"]="#FFD700";
119colorNames["goldenrod"]="#DAA520"; colorNames["greenyellow"]="#ADFF2F";
120colorNames["honeydew"]="#F0FFF0"; colorNames["hotpink"]="#FF69B4";
121colorNames["indianred"]="#CD5C5C"; colorNames["indigo"]="#4B0082";
122colorNames["ivory"]="#FFFFF0"; colorNames["khaki"]="#F0E68C";
123colorNames["lavender"]="#E6E6FA"; colorNames["lavenderblush"]="#FFF0F5";
124colorNames["lawngreen"]="#7CFC00"; colorNames["lemonchiffon"]="#FFFACD";
125colorNames["lightblue"]="#ADD8E6"; colorNames["lightcoral"]="#F08080";
126colorNames["lightcyan"]="#E0FFFF"; colorNames["lightgoldenrodyellow"]="#FAFAD2";
127colorNames["lightgreen"]="#90EE90"; colorNames["lightgrey"]="#D3D3D3";
128colorNames["lightpink"]="#FFB6C1"; colorNames["lightsalmon"]="#FFA07A";
129colorNames["lightseagreen"]="#20B2AA"; colorNames["lightskyblue"]="#87CEFA";
130colorNames["lightslategray"]="#778899"; colorNames["lightsteelblue"]="#B0C4DE";
131colorNames["lightyellow"]="#FFFFE0"; colorNames["limegreen"]="#32CD32";
132colorNames["linen"]="#FAF0E6"; colorNames["mediumaquamarine"]="#66CDAA";
133colorNames["mediumblue"]="#0000CD"; colorNames["mediumorchid"]="#BA55D3";
134colorNames["ediumpurple"]="#9370D"; colorNames["mediumseagreen"]="#3CB371";
135colorNames["mediumslateblue"]="#7B68EE"; colorNames["mediumspringgreen"]="#00FA9A";
136colorNames["mediumturquoise"]="#48D1CC"; colorNames["mediumvioletred"]="#C71585";
137colorNames["midnightblue"]="#191970"; colorNames["mintcream"]="#F5FFFA";
138colorNames["mistyrose"]="#FFE4E1"; colorNames["moccasin"]="#FFE4B5";
139colorNames["navajowhite"]="#FFDEAD"; colorNames["oldlace"]="#FDF5E6";
140colorNames["olivedrab"]="#6B8E23"; colorNames["orange"]="#FFA500";
141colorNames["orangered"]="#FF4500"; colorNames["orchid"]="#DA70D6";
142colorNames["palegoldenrod"]="#EEE8AA"; colorNames["palegreen"]="#98FB98";
143colorNames["paleturquoise"]="#AFEEEE"; colorNames["palevioletred"]="#DB7093";
144colorNames["papayawhip"]="#FFEFD5"; colorNames["peachpuff"]="#FFDAB9";
145colorNames["peru"]="#CD853F"; colorNames["pink"]="#FFC0CB";
146colorNames["plum"]="#DDA0DD"; colorNames["powderblue"]="#B0E0E6";
147colorNames["rosybrown"]="#BC8F8F"; colorNames["royalblue"]="#4169E1";
148colorNames["saddlebrown"]="#8B4513"; colorNames["salmon"]="#FA8072";
149colorNames["sandybrown"]="#F4A460"; colorNames["seagreen"]="#2E8B57";
150colorNames["seashell"]="#FFF5EE"; colorNames["sienna"]="#A0522D";
151colorNames["skyblue"]="#87CEEB"; colorNames["slateblue"]="#6A5ACD";
152colorNames["slategray"]="#708090"; colorNames["snow"]="#FFFAFA";
153colorNames["springgreen"]="#00FF7F"; colorNames["steelblue"]="#4682B4";
154colorNames["tan"]="#D2B48C"; colorNames["thistle"]="#D8BFD8";
155colorNames["tomato"]="#FF6347"; colorNames["turquoise"]="#40E0D0";
156colorNames["violet"]="#EE82EE"; colorNames["wheat"]="#F5DEB3";
157colorNames["whitesmoke"]="#F5F5F5"; colorNames["yellowgreen"]="#9ACD32";
158var canvas_bgcolor = "";
159var canvas_width = 200;
160var canvas_height = 200;
161var canvas_noshade = 0;
162var canvas_nofill = 0;
163var canvas_noshadow = 0;
164var canvas_htmltext = 0;
165var canvas_imgtext = 0;
166var canvas_notext = 0;
167// canvas chart extension
168
169var s5NotesWindow;
170var s5NotesWindowLoaded = false;
171var previousSlide = 0;
172var presentationStart = new Date();
173var slideStart = new Date();
174
175var countdown = {
176	timer: 0,
177	state: 'pause',
178	start: new Date(),
179	end: 0,
180	remaining: 0
181};
182
183var isIE = navigator.appName == 'Microsoft Internet Explorer' && navigator.userAgent.indexOf('Opera') < 1 ? 1 : 0;
184if(isIE) var notIE7 = parseInt(navigator.appVersion) < 7 ? 1 : 0;
185var isOp = navigator.userAgent.indexOf('Opera') > -1 ? 1 : 0;
186var isGe = navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('Safari') < 1 ? 1 : 0;
187var isS2 = navigator.userAgent.indexOf('Safari') >= 2 ? 1 : 0;
188
189function hasClass(object, className) {
190	if (!object.className) return false;
191try {
192	return (object.className.search('(^|\\s)' + className + '(\\s|$)') != -1);
193} catch (err) {
194 return false;
195}
196}
197
198function hasValue(object, value) {
199	if (!object) return false;
200	return (object.search('(^|\\s)' + value + '(\\s|$)') != -1);
201}
202
203function removeClass(object,className) {
204	if (!object || !hasClass(object,className)) return;
205	object.className = object.className.replace(new RegExp('(^|\\s)'+className+'(\\s|$)'), RegExp.$1+RegExp.$2);
206}
207
208function addClass(object,className) {
209	if (!object || hasClass(object, className)) return;
210	if (object.className) {
211		object.className += ' '+className;
212	} else {
213		object.className = className;
214	}
215}
216
217function changeClass(object,className) {
218	if (!object) return;
219	object.firstChild.className = className;
220}
221
222function GetElementsWithClassName(elementName,className) {
223	var allElements = document.getElementsByTagName(elementName);
224	var elemColl = new Array();
225	for (var i = 0; i< allElements.length; i++) {
226		if (hasClass(allElements[i], className)) {
227			elemColl[elemColl.length] = allElements[i];
228		}
229	}
230	return elemColl;
231}
232
233function isParentOrSelf(element, id) {
234	if (element == null || element.nodeName=='BODY') return false;
235	else if (element.id == id) return true;
236	else if (element.id && element.id.indexOf(id) == 0) return true;
237	else return isParentOrSelf(element.parentNode, id);
238}
239
240function nodeValue(node) {
241	var result = "";
242	if (node.nodeType == 1) {
243		var children = node.childNodes;
244		for (var i = 0; i < children.length; ++i) {
245			result += nodeValue(children[i]);
246		}
247	}
248	else if (node.nodeType == 3) {
249		result = node.nodeValue;
250	}
251	return(result);
252}
253
254function slideLabel() {
255	var slideColl = GetElementsWithClassName('*','slide');
256	var list = document.getElementById('jumplist');
257	smax = slideColl.length;
258	for (var n = 0; n < smax; n++) {
259		var obj = slideColl[n];
260		var did = 'slide' + n.toString();
261		obj.setAttribute('id',did);
262		var otext = '';
263		var menu = obj.firstChild;
264		if (!menu) continue; // to cope with empty slides
265		while (menu && menu.nodeType == 3) {
266			menu = menu.nextSibling;
267		}
268	 	if (!menu) continue; // to cope with slides with only text nodes
269		var menunodes = menu.childNodes;
270		for (var o = 0; o < menunodes.length; o++) {
271			otext += nodeValue(menunodes[o]);
272		}
273		list.options[list.length] = new Option(n + ' : '  + otext, n);
274	}
275}
276var sectionNames= new Array();
277var sectionTimes= new Array();
278var sectionTitle = "";
279function currentSlide() {
280	var cs, at, fd, ss;
281	if (document.getElementById) {
282		cs = document.getElementById('currentSlide');
283	} else {
284		cs = document.currentSlide;
285	}
286	fd = fadeModus?"F":"&ndash;";
287	ss = audioSupport?"S":"&ndash;";
288	at = (autoMatic?(playPause?"||":(playLoop?"&gt;0":"&gt;|")):"&ndash;&ndash;");
289
290        fd = "";
291        ss = "";
292        at = "";
293	try {
294		for (var dat in sectionNames) {
295			if(dat==snum) sectionTitle = sectionNames[dat];
296		}
297	} catch (exc1) {}
298	try {
299		for (var dat in sectionTimes) {
300			if(dat==snum+1) {
301				playDelay = parseInt(sectionTimes[dat])*1000;
302				playDelay = (fadeModus == true) ? (playDelay+(2*fadeDuration)) : playDelay;
303				if(playDelay && !isOp) {
304					var idx = 0; var vol = parseInt(playDelay/1000);
305					if(vol >= 83 && vol <= 90) {idx = 0;}
306					else if(vol >= 68 && vol < 83) {idx = 1;}
307					else if(vol >= 53 && vol < 68) {idx = 2;}
308					else if(vol >= 38 && vol < 53) {idx = 3;}
309					else if(vol >= 25 && vol < 38) {idx = 4;}
310					else if(vol >= 18 && vol < 25) {idx = 5;}
311					else if(vol >= 13 && vol < 18) {idx = 6;}
312					else if(vol >= 8 && vol < 13) {idx = 7;}
313					else {idx = 8;}
314					document.getElementById('delaylist').selectedIndex = idx;
315				}
316			}
317		}
318	} catch (exc2) {}
319	var secTitle = sectionTitle;
320	if (secTitle != "") secTitle += "<BR>";
321	cs.innerHTML = secTitle+'<div id="plink" nowrap="nowrap">' +
322	'<span id="csFade">' + fd + ss + '<\/span>' +
323	'<span id="csHere"><strong>' + snum + '<\/strong><\/span>' +
324	'<span id="csSep">\/<\/span>' +
325	'<span id="csTotal">' + (smax-1) + '<\/span>' +
326	'<span id="csAuto">' + at + '<\/span>' +
327	'<\/div>';
328
329	if (snum == 0) {
330		cs.style.visibility = 'hidden';
331	} else {
332		cs.style.visibility = 'visible';
333	}
334	try { sendNSCommand("slide "+snum); } catch (err) {}
335}
336
337function go(step) {
338	if (document.getElementById('slideProj').disabled || step == 0) return;
339	jl = document.getElementById('jumplist');
340	cid = 'slide' + snum;
341	var ce = document.getElementById(cid);
342	if (incrementals[snum].length > 0) {
343		for (var i = 0; i < incrementals[snum].length; i++) {
344			removeClass(incrementals[snum][i], 'current');
345			removeClass(incrementals[snum][i], 'incremental');
346		}
347	}
348	if (step != 'j') {
349		snum += step;
350		lmax = smax - 1;
351		if (snum > lmax) snum = lmax;
352		if (snum < 0) snum = 0;
353	}else {
354		snum = parseInt(jl.value);
355	}
356	nid = 'slide' + snum;
357	var ne = document.getElementById(nid);
358	if (!ne) {
359		ne = document.getElementById('slide0');
360		nid = 'slide0';
361		snum = 0;
362	}
363	if (step < 0) {
364		incpos = incrementals[snum].length
365	}else {
366		incpos = 0;
367	}
368	if (incrementals[snum].length > 0 && incpos == 0) {
369		for (var i = 0; i < incrementals[snum].length; i++) {
370			if (hasClass(incrementals[snum][i], 'current')) {
371				incpos = i + 1;
372			}else {
373				addClass(incrementals[snum][i], 'incremental');
374			}
375		}
376	}
377	if (incrementals[snum].length > 0 && incpos > 0) {
378		addClass(incrementals[snum][incpos - 1], 'current');
379	}
380	var guru = document.getElementById('guru');
381//	if(guru && snum==0) {
382//		guru.style.visibility = 'visible';
383//	}else if(guru && snum>0) {
384//		guru.style.visibility = 'hidden';
385//	}
386	if(tranSitions && s5mode && fadeModus) {
387		if(curSoundID != getSoundID(nid)) {
388			if(curSoundID == bgSoundItem && !sound[getSoundID(nid)]) {
389			}else {fadeoutSound(curSoundID,true); } // audio support
390		}
391		changeOpac(0,nid);
392		changeOpac(100,cid);
393		ce.style.visibility = 'visible';
394		shiftOpacity(cid,fadeDuration);
395		window.setTimeout("changeSlides()",fadeDuration);
396	}else {
397		if(curSoundID != getSoundID(nid)) {
398			if(curSoundID == bgSoundItem && !sound[getSoundID(nid)]) {
399			}else {stopSound(curSoundID); } // audio support
400		}
401		ce.style.visibility = 'hidden';
402		if (isOp) location.hash = nid;
403		ne.style.visibility = 'visible';
404		finishSlides();
405	}
406}
407
408function changeSlides() {
409	if(nid != cid) changeOpac(100,cid);
410	document.getElementById(cid).style.visibility = 'hidden';
411	document.getElementById(nid).style.visibility = 'visible';
412	if (isOp) location.hash = nid;
413	shiftOpacity(nid,fadeDuration);
414	window.setTimeout("finishSlides()",fadeDuration);
415}
416
417function finishSlides() {
418	jl.selectedIndex = snum;
419	currentSlide();
420	loadNote();
421	permaLink();
422	number = undef;
423	if(sound[getSoundID(nid)]) {
424		playSound(nid); // audio support
425	}else if(sound[bgSoundItem] && curSoundID != bgSoundItem) {
426		playSound(bgSoundItem); // audio support
427	}
428}
429
430function goTo(target) {
431	if (target >= smax || target == snum) return;
432	go(target - snum);
433}
434
435function subgo(step) {
436	if (step > 0) {
437		removeClass(incrementals[snum][incpos - 1],'current');
438		removeClass(incrementals[snum][incpos], 'incremental');
439		if(tranSitions && s5mode && fadeModus) {
440			if(!incrementals[snum][incpos].id) {
441				var tmp = new Date(); tid = "inc" + String(tmp.getTime());
442				incrementals[snum][incpos].id = tid;
443			}else {
444				tid = incrementals[snum][incpos].id;
445			}
446			if(typeof(incrementals[snum][incpos].src) != "undefined" || incrementals[snum][incpos].getContext) {
447				changeOpac(0,tid);
448				addClass(incrementals[snum][incpos],'current');
449				shiftOpacity(tid,incrDuration);
450				setTimeout("nextInc()",incrDuration);
451			}else {
452				addClass(incrementals[snum][incpos],'current');
453				nextInc();
454			}
455		}else {
456			addClass(incrementals[snum][incpos],'current');
457			nextInc();
458		}
459	} else {
460		incpos--;
461		removeClass(incrementals[snum][incpos],'current');
462		addClass(incrementals[snum][incpos], 'incremental');
463		addClass(incrementals[snum][incpos - 1],'current');
464		loadNote();
465	}
466}
467
468function nextInc() {
469	incpos++;
470	loadNote();
471}
472
473function toggle() {
474	var slideColl = GetElementsWithClassName('*','slide');
475	var slides = document.getElementById('slideProj');
476	var outline = document.getElementById('outlineStyle');
477	var guru = document.getElementById('guru');
478	if (!slides.disabled) {
479		stopPlay();
480		if(audioSupport && !swfUnloaded) stopAllSounds();
481		slides.disabled = true;
482		outline.disabled = false;
483		s5mode = false;
484		fontSize(1,'em');
485		for (var n = 0; n < smax; n++) {
486			var slide = slideColl[n];
487			slide.style.visibility = 'visible';
488		}
489		if(guru) guru.style.visibility = 'hidden';
490	} else {
491		slides.disabled = false;
492		outline.disabled = true;
493		s5mode = true;
494		fontScale();
495		for (var n = 0; n < smax; n++) {
496			var slide = slideColl[n];
497			slide.style.visibility = 'hidden';
498		}
499		slideColl[snum].style.visibility = 'visible';
500//		if(guru && snum==0) guru.style.visibility = 'visible';
501	}
502}
503
504function showHide(action) {
505	var obj = GetElementsWithClassName('*','hideme')[0];
506	switch (action) {
507	case 's':
508		obj.style.visibility = 'visible';
509		break;
510	case 'h':
511		obj.style.visibility = 'hidden';
512		break;
513	case 'k':
514		if (obj.style.visibility != 'visible') {
515			obj.style.visibility = 'visible';
516		} else {
517			obj.style.visibility = 'hidden';
518		}
519	break;
520	}
521}
522
523function keys(key) {
524	if (!key) {
525		key = event;
526		key.which = key.keyCode;
527	}
528	if (helpmode) {
529		dumpHelpReq();
530		return;
531	}
532	if (key.which == 84 && !isOp) {
533		toggle();
534		return;
535	}
536	if (s5mode) {
537		if (autoMatic) {
538			switch (key.which) {
539			case 70: // f/ading on/off
540				switchFade();
541				break;
542			case 83: // s/ound on/off
543				toggleSounds();
544				break;
545			case 67: // c
546				showHide('k');
547				break;
548			case 65: // a/utoplay on/off
549				stopPlay();
550				break;
551			case 76: // l/ooping on/off
552				switchLoop();
553				break;
554			case 80: // p/ause
555			case 32: // spacebar
556				pausePlay();
557				break;
558			}
559		}else {
560			switch (key.which) {
561			case 8: // backspace = HELP
562				createHelpReq();
563				break;
564			case 10: // return
565			case 13: // enter
566				if (window.event && isParentOrSelf(window.event.srcElement, 'controls')) return;
567				if (key.target && isParentOrSelf(key.target, 'controls')) return;
568				if(number != undef) {
569					goTo(number);
570					break;
571				}
572			case 32: // spacebar
573			case 34: // page down
574			case 39: // rightkey
575			case 40: // downkey
576				if(number != undef) {
577					go(number);
578				} else if (!incrementals[snum] || incpos >= incrementals[snum].length) {
579					go(1);
580				} else {
581					subgo(1);
582				}
583				break;
584			case 33: // page up
585			case 37: // leftkey
586			case 38: // upkey
587				if(number != undef) {
588					go(-1 * number);
589				} else if (!incrementals[snum] || incpos <= 0) {
590					go(-1);
591				} else {
592					subgo(-1);
593				}
594				break;
595			case 65: // a/utoplay
596				startPlay();
597				break;
598			case 72: // h
599			case 36: // home
600				goTo(0);
601				break;
602			case 69: // e
603			case 35: // end
604				goTo(smax-1);
605				break;
606			case 70: // f/ade transitions on/off
607				switchFade();
608				break;
609			case 76: // l/ooping on/off
610				switchLoop();
611				break;
612			case 83: // s/ound support on/off
613				toggleSounds();
614				break;
615			case 27: // escape
616			case 81: // q
617				if(!isOp) byby();
618				break;
619			case 67: // c
620				showHide('k');
621				break;
622			case 78: // n
623				createNotesWindow();
624				break;
625			}
626			if (key.which < 48 || key.which > 57) {
627				number = undef;
628			} else {
629				if (window.event && isParentOrSelf(window.event.srcElement, 'controls')) return;
630				if (key.target && isParentOrSelf(key.target, 'controls')) return;
631				number = (((number != undef) ? number : 0) * 10) + (key.which - 48);
632			}
633		}
634	}
635	return false;
636}
637
638function clicker(e) {
639	number = undef;
640	var target;
641	if (window.event) {
642		target = window.event.srcElement;
643		e = window.event;
644	} else {
645		target = e.target;
646	}
647	if (target.href != null || hasValue(target.rel, 'external') || isParentOrSelf(target, 'controls') || isParentOrSelf(target,'embed') || isParentOrSelf(target,'object') || isParentOrSelf(target, 'galler')) return true;
648	if (!helpmode) {
649		if (!e.which || e.which == 1) {
650			if (!incrementals[snum] || incpos >= incrementals[snum].length) {
651				go(1);
652			} else {
653				subgo(1);
654			}
655		}
656	} else {
657		dumpHelpReq();
658	}
659}
660
661function findSlide(hash) {
662	var target = null;
663	var slides = GetElementsWithClassName('*','slide');
664	for (var i = 0; i < slides.length; i++) {
665		var targetSlide = slides[i];
666		if ( (targetSlide.name && targetSlide.name == hash)
667		 || (targetSlide.id && targetSlide.id == hash) ) {
668			target = targetSlide;
669			break;
670		}
671	}
672	while(target != null && target.nodeName != 'BODY') {
673		if (hasClass(target, 'slide')) {
674			return parseInt(target.id.slice(5));
675		}
676		target = target.parentNode;
677	}
678	return null;
679}
680
681function slideJump() {
682	if (window.location.hash == null) return;
683	var sregex = /^#slide(\d+)$/;
684	var matches = sregex.exec(window.location.hash);
685	var dest = null;
686	if (matches != null) {
687		dest = parseInt(matches[1]);
688	} else {
689		dest = findSlide(window.location.hash.slice(1));
690	}
691	if (dest != null)
692		go(dest - snum);
693}
694
695function fixLinks() {
696	var thisUri = window.location.href;
697	thisUri = thisUri.slice(0, thisUri.length - window.location.hash.length);
698	var aelements = document.getElementsByTagName('A');
699	for (var i = 0; i < aelements.length; i++) {
700		var a = aelements[i].href;
701		var slideID = a.match('\#slide[0-9]{1,2}');
702		if ((slideID) && (slideID[0].slice(0,1) == '#')) {
703			var dest = findSlide(slideID[0].slice(1));
704			if (dest != null) {
705				if (aelements[i].addEventListener) {
706					aelements[i].addEventListener("click", new Function("e",
707						"if (document.getElementById('slideProj').disabled) return;" +
708						"go("+dest+" - snum); " +
709						"if (e.preventDefault) e.preventDefault();"), true);
710				} else if (aelements[i].attachEvent) {
711					aelements[i].attachEvent("onclick", new Function("",
712						"if (document.getElementById('slideProj').disabled) return;" +
713						"go("+dest+" - snum); " +
714						"event.returnValue = false;"));
715				}
716			}
717		}
718	}
719}
720
721function externalLinks() {
722	if (!document.getElementsByTagName) return;
723	var anchors = document.getElementsByTagName('a');
724	for (var i=0; i<anchors.length; i++) {
725		var anchor = anchors[i];
726		if (anchor.getAttribute('href') && hasValue(anchor.rel, 'external')) {
727			anchor.target = '_blank';
728			addClass(anchor,'external');
729		}
730	}
731}
732
733function permaLink() {
734	document.getElementById('plink').href = window.location.pathname + '#slide' + snum;
735}
736
737function createControls() {
738	var controlsDiv = document.getElementById("controls");
739	if (!controlsDiv) return;
740	var hider = ' onmouseover="showHide(\'s\');" onmouseout="showHide(\'h\');"';
741	var hideDiv, hideList = '';
742	if (controlVis == 'hidden') {
743		hideDiv = hider;
744	} else {
745		hideList = hider;
746	}
747	if(isOp) {
748		var str = '';
749	}else {
750		var str = '<a accesskey="t" id="sheet" title="toggle CSS" onClick="javascript:toggle();">&plusmn;<\/a>';
751	}
752	if(isIE) {
753		var tmp = "move around&xA0;until the color&xA0;change to red!";
754	}else if(isS2) {
755		var tmp = "move around\r\nuntil the color\r\nchange to red!";
756	}else {
757		var tmp = "move around until color change to red!";
758	}
759	if(isIE) {
760		controlsDiv.innerHTML = str +
761		'<form action="#" id="controlForm"' + hideDiv + '>' +
762		'<div id="navLinks" title="press [backspace] for keyboard help!"><ul>' +
763		'<li id="show-notes"><a onClick="javascript:createNotesWindow();" accesskey="n" title="show Notes"><\/a><\/li>' +
764		'<li id="toggle"><a onClick="javascript:toggle();" accesskey="t" title="toggle CSS"><\/a><\/li>' +
765		'<li id="zero"><a onClick="javascript:goTo(0);" accesskey="h" title="goto Start Slide"><\/a><\/li>' +
766		'<li id="prev"><a onClick="javascript:go(-1);" accesskey="y" title="previous Slide"><\/a><\/li>' +
767		'<li id="next"><a onClick="javascript:go(1);" accesskey="x" title="next Slide"><\/a><\/li>' +
768		'<li id="last"><a onClick="javascript:goTo(smax-1);" accesskey="e" title="goto Last Slide"><\/a><\/li>' +
769		'<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>' +
770		'<li id="auto"><a class="isoff" onClick="javascript:togglePlay();" accesskey="a" title="Auto Play"><\/a><\/li>' +
771		'<li id="pause"><a class="isoff" onClick="javascript:pausePlay();" accesskey="p" title="Pause"><\/a><\/li>' +
772		'<li id="loop"><a class="isoff" onClick="javascript:switchLoop();" accesskey="l" title="Loop"><\/a><\/li>' +
773		'<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>' +
774		'<\/ul><\/div><\/form>';
775	}else {
776		controlsDiv.innerHTML = str +
777		'<form action="#" id="controlForm"' + hideDiv + '>' +
778		'<div id="navLinks" title="press [backspace] or double click this area for keyboard help!" ondblclick="createHelpReq();"><ul>' +
779		'<li id="exit"><a onClick="javascript:byby();" accesskey="q" title="exit Show"><\/a><\/li>' +
780		'<li id="show-notes"><a onClick="javascript:createNotesWindow();" accesskey="n" title="show Notes"><\/a><\/li>' +
781		'<li id="toggle"><a onClick="javascript:toggle();" accesskey="t" title="toggle CSS"><\/a><\/li>' +
782		'<li class="vr"><\/li>' +
783		'<li id="zero"><a onClick="javascript:goTo(0);" accesskey="h" title="goto Start Slide"><\/a><\/li>' +
784		'<li id="prev"><a onClick="javascript:go(-1);" accesskey="y" title="previous Slide"><\/a><\/li>' +
785		'<li id="next"><a onClick="javascript:go(1);" accesskey="x" title="next Slide"><\/a><\/li>' +
786		'<li id="last"><a onClick="javascript:goTo(smax-1);" accesskey="e" title="goto Last Slide"><\/a><\/li>' +
787		'<li id="lst"><a id="list" style="cursor:wait;" title="' + tmp + '"><\/a><select id="jumplist" title="select named Slide" onchange="go(\'j\');"><\/select><\/li>' +
788		'<li id="fadeLinks" class="vr"><\/li>' +
789		'<li id="fade"><a class="isoff" onClick="javascript:switchFade();" accesskey="f" title="Transions"><\/a><\/li>' +
790		'<li id="audioLinks" class="vr"><\/li>' +
791		'<li id="audio"><a class="isoff" onClick="javascript:toggleSounds();" accesskey="s" title="Sounds" ><\/a><\/li>' +
792		'<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>' +
793		'<li id="autoLinks" class="vr"><\/li>' +
794		'<li id="auto"><a class="isoff" onClick="javascript:togglePlay();" accesskey="a" title="Auto Play"><\/a><\/li>' +
795		'<li id="pause"><a class="isoff" onClick="javascript:pausePlay();" accesskey="p" title="Pause"><\/a><\/li>' +
796		'<li id="loop"><a class="isoff" onClick="javascript:switchLoop();" accesskey="l" title="Loop"><\/a><\/li>' +
797		'<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>' +
798		'<\/ul>' +
799		'<a onClick="http://s5.netzgesta.de" target="_blank" title="S5 Reloaded"><img style="position: absolute; right: 0; bottom: 0;" src="data:image/png;charset=utf-8;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAgCAYAAAASYli2AAAABGdBTUEAANbY1E9YMgAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAYpSURBVHjaYvz//z8DOYCRkZEZRAEx0Ij/f2HiAAHEgqYIpACkkB1J7g8Q/wLRIJ1QNSB5fiDmAOLvQKHPQPoHSB4ggFiQDGMCUnxALAPECkAsBLIdiD8A8SMgfghU8wlqkTgQK1ZVVWldv3792fr16y8D+c9AhgMEECPIy1DDRIDYAojdzMzMWNXV1UG2/v/y5Qvzw4cPP587d24/kH8Gar/uwoULQ+/cufNFXFyciZmZ+UVmZuZKoFmvAQII5kJOIDbi4uKK2Llz53EbG5vP6GGWn5+vMWnSpJtA5jcg5v327Rtnc3PzfSD79+rVq2WBNBtIHUAAwQzkAWKzBQsWnIUZFhISovXmzZsfkpKSDD09PY8kJCR+QtWCguGvrKwsz7Rp07Q4ODh+srCwgILiH0gSIIBgBrICsUBoaCgorBiANgqvXbtWDMg8AcQf9+7d+x0o9xbI/gJV/3fVqlUvmJiY/gIdcaWhoYETahEDQADBDPwNxO9h3gNpBiq6f/HiRbWjR4+yvnr16grQNbeh6kCWsxkYGIhClT8yNDQUgyYhBoAAYoIKfgXi06mpqUowQ+vr6x+uW7fu0suXL8+uWbOGS0BAwB7kC6jXvqmoqLDIyclxzZo1S4udnR2WtBgAAggWyyCXSgOxZUxMjGpWVtY7S0vLr8iRsnnzZl4/P7/DQCYoYtSA2DApKUkVGNNPDh06dBrIvwU06xNAAMEM5AIKqAOxCjQsmHl5eXWdnJx4N2zYcB4prd4CUpfwJRuAAGJCimULoGYpbm5uZ5DBnz9/5tq4caPWkSNHeJEc+g0aTFzfv3/nACabjzk5OW8FBQVloLmHASCAYJECUiTg7+//HJiQTzY2NsrfvXv3n7m5+T5YMgJGEkjDS2gY/pKRkeHt7Ow0Bsb0v9+/fz+HxTJAAMG8DHKFLTC9aRUXF79BT9Qgw4CWHAAy70FdYgjEDgkJCTpWVlYMQBfeAaaMPqBZbwECCGYgMzQGQSleCehS0X///jEDvf9lxYoVoOTyAIjfANX+BqrlBrL1gLFf09vb+0FaWvoHMBctA6USUKQABBAjrPiCliKg7AOKIG5ougLlju9Ipc1foDJWqMWGhYWFtsBg4RISEnrg5uY2BWQgQACxIBkGMkQKijmRfPwXWuI8ASp7DQ1vEP4DDO8PwBzzDJheT0CLPQaAAEJOh0o8zAzeihwMiv+gGZ0B4sz/bIwM797/YTh1/wfDIWj5qAfMmtFnzpz5ICIiwqKoqPgjKChoOtCs5wABhJyXpUCGzddgOIethJ71jEFi1nNwgQrKz8zv37//097eDop15qVLl0pAzWAACCAWhEMYOJFdduELA++b3wxsTIwMfzmYGH6xMDG8gYYpKAg+cnJy/gB6VwuYZFiA7E+wvAwQQCy46ozexwzG17+BYx6UVE4B8Vmo68CRFR0dDQo3UAHBBUwJ4lCLGAACCNnAv4zQxAkCxbIMZ0EuBIYb98EPDFo3voGTzjOogVzArGf969cvNmC2+wssHD7BDAQIIBakmHwPDPy3MAMNeBhgpfbbVEkGhqQbDJaXvjI8BPJB4jz79u37DcwlP+fPn38NuTwECCBkA1+8+8Nwtusxg+STHwwcP/8z8EuwMXA1KjBcBSlwEmRgBhrID/U2O7QMBIEHxsbGkrAwBAggmIGgNMT64AfDWyB+By0EQMVZlC0/wwsXQYa38hzgCGGBWv5ZU1OT4c+fP8yLFi1SA3r5Haw8BAggmIGg5KBpJ8BgeOYTg8S3f2DN/OxMDNwgw0AKnv0EJ+avsITu7u6+EZqzQEHwHFqaMwAEEAtShS/pLcTwrU+Z4QwsyQANOwIL06tfGV5BqwmQWoGKigoLYJnJvWPHjhstLS169vb2M0DqAAIIVh6CXHT/9ndIawEUITCXgUDrQwbGbe8YjkJdAzZQVVVV/t69e8LAgtUYaNgxWKQABBByacMHzfTK9gIMYkBZpj//GT4c+8gAKm1AsfseqPYPtHTXAtaEacBqlgHoyq+srKw3XV1dFwHlvwEEECNyYwmp3cIJjbUf0DbLP7RGEg+0bcMCjQxQzH8BWQgQQIzktr5wAYAAYmKgMgAIMAAp8Fx3osz1lgAAAABJRU5ErkJggg==" width="20" height="32" alt="S5" \/><\/a>' +
800		'<\/div><\/form>';
801	}
802	if (controlVis == 'hidden') {
803		var hidden = document.getElementById('navLinks');
804	} else {
805		var hidden = document.getElementById('jumplist');
806	}
807	addClass(hidden,'hideme');
808}
809
810function fontScale() {  // causes layout problems in FireFox that get fixed if browser's Reload is used; same may be true of other Gecko-based browsers
811	if (!s5mode && !isOp) return false;
812	var hScreen = screen.width; var vScreen = screen.height;
813	var vWindow = window.outerHeight; var hWindow = window.outerWidth;
814	if (isOp && s5mode && defaultView=='slideshow' && ((hScreen != hWindow) || (vScreen != vWindow))) {
815		toggle();
816		return false;
817	}
818	if (isOp && !s5mode && ((hScreen != hWindow) || (vScreen != vWindow))) return false;
819	if (isOp && !s5mode && (hScreen == hWindow) && (vScreen == vWindow)) toggle();
820	var vScale = 48;  // both yield 16 (the usual browser default) at 1024x768
821	var hScale = 64;  // perhaps should auto-calculate based on theme's declared value?
822	if (window.innerHeight) {
823		var vSize = window.innerHeight;
824		var hSize = window.innerWidth;
825	} else if (document.documentElement.clientHeight) {
826		var vSize = document.documentElement.clientHeight;
827		var hSize = document.documentElement.clientWidth;
828	} else if (document.body.clientHeight) {
829		var vSize = document.body.clientHeight;
830		var hSize = document.body.clientWidth;
831	} else {
832		var vSize = 700;  // assuming 1024x768, minus chrome and such equals 8:5
833		var hSize = 1024; // these do not account for kiosk mode or Opera Show
834	}
835	var newSize = Math.min(Math.round(vSize/vScale),Math.round(hSize/hScale));
836	extendImgSizes(newSize); // scalable images extension
837	extendCanSizes(newSize); // scalable canvas extension
838	extendObjSizes(newSize); // scalable object extension
839	fontSize(newSize,"px");
840	if(!isS2 || firstTime==0) {
841		generateCanvas(); // dynamic canvas extension
842	}
843	if (isGe) {  // hack to counter incremental reflow bugs
844		var obj = document.getElementsByTagName('body')[0];
845		obj.style.visibility = 'hidden';
846		obj.style.display = 'none';
847		obj.style.display = 'block';
848		obj.style.visibility = 'visible';
849		changeOpac(100,'slide' + snum);
850		shiftOpacity('slide' + snum,10);
851		window.setTimeout("fixReflow()",10);
852	}else {
853		setListPos(); // invisible select extension
854	}
855}
856
857function fixReflow() {
858	shiftOpacity('slide' + snum,10);
859	window.setTimeout("finishReflow()",10);
860}
861function finishReflow() {
862	setListPos(); // invisible select extension
863}
864
865function fontSize(val,fmt) {
866	var value = val + fmt;
867	if (!(s5ss = document.getElementById('s5ss'))) {
868		if (!document.createStyleSheet) {
869			document.getElementsByTagName('head')[0].appendChild(s5ss = document.createElement('style'));
870			s5ss.setAttribute('media','screen, projection');
871			s5ss.setAttribute('id','s5ss');
872		} else {
873			document.createStyleSheet();
874			document.s5ss = document.styleSheets[document.styleSheets.length - 1];
875		}
876	}
877	if (!(document.s5ss && document.s5ss.addRule)) {
878		while (s5ss.lastChild) s5ss.removeChild(s5ss.lastChild);
879		s5ss.appendChild(document.createTextNode('html {font-size: ' + value + ' !important;}'));
880	} else {
881		document.s5ss.addRule('html','font-size: ' + value + ' !important;');
882	}
883}
884
885function windowChange() {
886	fontScale();
887}
888
889function notOperaFix() {
890	slideCSS = document.getElementById('slideProj').href;
891	var slides = document.getElementById('slideProj');
892	var outline = document.getElementById('outlineStyle');
893	slides.setAttribute('media','screen');
894	outline.disabled = true;
895	if (isGe) {
896		slides.setAttribute('href','null');   // Gecko fix
897		slides.setAttribute('href',slideCSS); // Gecko fix
898	}
899	if ((isIE && notIE7) && document.styleSheets && document.styleSheets[0]) {
900		document.styleSheets[0].addRule('img', 'behavior: url('+s5Path+'ui/graphic_support/iepngfix.htc)');
901		document.styleSheets[0].addRule('div', 'behavior: url('+s5Path+'ui/graphic_support/iepngfix.htc)');
902		document.styleSheets[0].addRule('.slide', 'behavior: url('+s5Path+'ui/graphic_support/iepngfix.htc)');
903	}
904}
905
906function getIncrementals(obj) {
907	var incrementals = new Array();
908	if (!obj)
909		return incrementals;
910	var children = obj.childNodes;
911	for (var i = 0; i < children.length; i++) {
912		var child = children[i];
913		if (hasClass(child, 'incremental')) {
914			if (child.nodeName == 'OL' || child.nodeName == 'UL') {
915				removeClass(child, 'incremental');
916				for (var j = 0; j < child.childNodes.length; j++) {
917					if (child.childNodes[j].nodeType == 1) {
918						addClass(child.childNodes[j], 'incremental');
919					}
920				}
921			} else {
922				incrementals[incrementals.length] = child;
923				removeClass(child,'incremental');
924			}
925		}
926		if (hasClass(child, 'show-first')) {
927			if (child.nodeName == 'OL' || child.nodeName == 'UL') {
928				removeClass(child, 'show-first');
929				if (child.childNodes[isGe].nodeType == 1) {
930					removeClass(child.childNodes[isGe], 'incremental');
931				}
932			} else {
933				incrementals[incrementals.length] = child;
934			}
935		}
936		incrementals = incrementals.concat(getIncrementals(child));
937	}
938	return incrementals;
939}
940
941function createIncrementals() {
942	var incrementals = new Array();
943	for (var i = 0; i < smax; i++) {
944		incrementals[i] = getIncrementals(document.getElementById('slide'+i));
945	}
946	return incrementals;
947}
948
949function trap(e) {
950	if (!e) {
951		e = event;
952		e.which = e.keyCode;
953	}
954	try {
955		modifierKey = e.ctrlKey || e.altKey || e.metaKey;
956	}
957	catch(e) {
958		modifierKey = false;
959	}
960	return modifierKey || e.which == 0;
961}
962
963// notes extension
964function noteLabel() { // Gives notes id's to match parent slides
965	var notes = GetElementsWithClassName('div','notes');
966	for (var i = 0; i < notes.length; i++) {
967		var note = notes[i];
968		var id = 'note' + note.parentNode.id.substring(5);
969		note.setAttribute('id',id);
970	}
971	resetElapsedSlide();
972	resetRemainingTime();
973	window.setInterval('updateElaspedTime()', 1000);
974}
975
976function createNotesWindow() { // creates a window for our notes
977	if (!s5NotesWindow || s5NotesWindow.closed) { // Create the window if it doesn't exist
978		s5NotesWindowLoaded = false;
979		// Note: Safari has a tendency to ignore window options preferring to default to the settings of the parent window, grr.
980		s5NotesWindow = window.open(s5Path+'ui/s5-notes.html', 's5NotesWindow', 'top=0,left=0');
981	}
982	if (s5NotesWindowLoaded) { // Load the current note if the Note HTML has loaded
983		loadNote();
984	} else { // Keep trying...
985		window.setTimeout('createNotesWindow()', 50);
986	}
987}
988
989function loadNote() {
990// Loads a note into the note window
991	var notes = nextNotes = '<em class="disclaimer">There are no notes for this slide.</em>';
992	if (document.getElementById('note' + snum)) {
993		notes = document.getElementById('note' + snum).innerHTML;
994	}
995	if (document.getElementById('note' + (snum + 1))) {
996		nextNotes = document.getElementById('note' + (snum + 1)).innerHTML;
997	}
998
999	var jl = document.getElementById('jumplist');
1000	var slideTitle = jl.options[jl.selectedIndex].text.replace(/^\d+\s+:\s+/, '') + ((jl.selectedIndex) ? ' (' + jl.selectedIndex + '/' + (smax - 1) + ')' : '');
1001	if (incrementals[snum].length > 0) {
1002		slideTitle += ' <small>[' + incpos + '/' + incrementals[snum].length + ']</small>';
1003	}
1004	if (jl.selectedIndex < smax - 1) {
1005		var nextTitle = jl.options[jl.selectedIndex + 1].text.replace(/^\d+\s+:\s+/, '') + ((jl.selectedIndex + 1) ? ' (' + (jl.selectedIndex + 1) + '/' + (smax - 1) + ')' : '');
1006	} else {
1007		var nextTitle = '[end of slide show]';
1008	}
1009
1010	if (s5NotesWindow && !s5NotesWindow.closed && s5NotesWindow.document) {
1011		s5NotesWindow.document.getElementById('slide').innerHTML = slideTitle;
1012		s5NotesWindow.document.getElementById('notes').innerHTML = notes;
1013		s5NotesWindow.document.getElementById('next').innerHTML = nextTitle;
1014		s5NotesWindow.document.getElementById('nextnotes').innerHTML = nextNotes;
1015	}
1016	resetElapsedSlide();
1017}
1018
1019function minimizeTimer(id) {
1020	var obj = s5NotesWindow.document.getElementById(id);
1021	if (hasClass(obj,'collapsed')) {
1022		removeClass(obj,'collapsed');
1023	} else {
1024		addClass(obj,'collapsed');
1025	}
1026}
1027
1028function resetElapsedTime() {
1029	presentationStart = new Date();
1030	slideStart = new Date();
1031	updateElaspedTime();
1032}
1033
1034function resetElapsedSlide() {
1035	if (snum != previousSlide) {
1036		slideStart = new Date();
1037		previousSlide = snum;
1038		updateElaspedTime();
1039	}
1040}
1041
1042function updateElaspedTime() {
1043	if (!s5NotesWindowLoaded || !s5NotesWindow || s5NotesWindow.closed) return;
1044	var now = new Date();
1045	var ep = s5NotesWindow.document.getElementById('elapsed-presentation');
1046	var es = s5NotesWindow.document.getElementById('elapsed-slide');
1047	ep.innerHTML = formatTime(now.valueOf() - presentationStart.valueOf());
1048	es.innerHTML = formatTime(now.valueOf() - slideStart.valueOf());
1049}
1050
1051function resetRemainingTime() {
1052	if (!s5NotesWindowLoaded || !s5NotesWindow || s5NotesWindow.closed) return;
1053	var startField = s5NotesWindow.document.getElementById('startFrom');
1054	startFrom = readTime(startField.value);
1055	countdown.remaining = startFrom * 60000;  // convert to msecs
1056	countdown.start = new Date().valueOf();
1057	countdown.end = countdown.start + countdown.remaining;
1058	var tl = s5NotesWindow.document.getElementById('timeLeft');
1059	var timeLeft = formatTime(countdown.remaining);
1060	tl.innerHTML = timeLeft;
1061}
1062
1063function updateRemainingTime() {
1064	if (!s5NotesWindowLoaded || !s5NotesWindow || s5NotesWindow.closed) return;
1065	var tl = s5NotesWindow.document.getElementById('timeLeft');
1066	var now = new Date();
1067	if (countdown.state == 'run') {
1068		countdown.remaining = countdown.end - now;
1069	}
1070	tl.style.color = '';
1071	tl.style.backgroundColor = '';
1072	if (countdown.remaining >= 0) {
1073		var timeLeft = formatTime(countdown.remaining);
1074		removeClass(tl,'overtime');
1075		if (countdown.remaining < 300000) {
1076			tl.style.color = 'rgb(' + (255-Math.round(countdown.remaining/2000)) + ',0,0)';
1077			tl.style.backgroundColor = 'rgb(255,255,' + (Math.round(countdown.remaining/2000)) + ')';
1078		}
1079	} else {
1080		var timeLeft = '-' + formatTime(-countdown.remaining);
1081		addClass(tl,'overtime');
1082	}
1083	tl.innerHTML = timeLeft;
1084}
1085
1086function toggleRemainingTime() {
1087	if (countdown.state == 'pause') countdown.state = 'run'; else countdown.state = 'pause';
1088	if (countdown.state == 'pause') {
1089		window.clearInterval(countdown.timer);
1090	}
1091	if (countdown.state == 'run') {
1092		countdown.start = new Date().valueOf();
1093		countdown.end = countdown.start + countdown.remaining;
1094		countdown.timer = window.setInterval('updateRemainingTime()', 1000);
1095	}
1096}
1097
1098function alterRemainingTime(amt) {
1099	var change = amt * 60000;  // convert to msecs
1100	countdown.end += change;
1101	countdown.remaining += change;
1102	updateRemainingTime();
1103}
1104
1105function formatTime(msecs)  {
1106	var time = new Date(msecs);
1107
1108	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...
1109	hrs = (hrs < 10) ? '0'+hrs : hrs;
1110	if (hrs == 'NaN' || isNaN(hrs)) hrs = '--';
1111
1112	var min = time.getUTCMinutes();
1113	min = (min < 10) ? '0'+min : min;
1114	if (min == 'NaN' || isNaN(min)) min = '--';
1115
1116	var sec = time.getUTCSeconds();
1117	sec = (sec < 10) ? '0'+sec : sec;
1118	if (sec == 'NaN' || isNaN(sec)) sec = '--';
1119
1120	return hrs + ':' + min + ':' + sec;
1121}
1122
1123function readTime(val) {
1124	var sregex = /:/;
1125	var matches = sregex.exec(val);
1126	if (matches == null) {
1127		return val;
1128	} else {
1129		var times = val.split(':');
1130		var hours = parseInt(times[0]);
1131		var mins = parseInt(times[1]);
1132		var total = (hours * 60) + mins;
1133		return total;
1134	}
1135}
1136// notes extension
1137
1138// startup process
1139function createSlideShow() {
1140	defaultCheck();
1141	if(!isIE) createDetector(); // (degrade IE) scalable images extension
1142	if(opac!=0 || isIE) { // &&!isIE (degrade IE)
1143		tranSitions = false;
1144		fadeModus = false;
1145	}
1146// Startup progress bar interacts with Galleria, so I disable it here
1147//	if(tranSitions && document.getElementById && document.createElement){
1148//		createProgress();
1149//		var nop=document.getElementById('StartupControl');
1150//		nop.onload = dumpProgress;
1151//	}else {
1152		startup();
1153		showAll();
1154		setListPos(true); // invisible select extension
1155		panelSetup();
1156		audioSetup(); // audio extension
1157		if(isS2 && firstTime>=1) {
1158			generateCanvas(); // dynamic canvas extension
1159		} firstTime = 0;
1160//	}
1161}
1162
1163function defaultCheck() {
1164	var allMetas = document.getElementsByTagName('meta');
1165	for (var i = 0; i< allMetas.length; i++) {
1166		if (allMetas[i].name == 'defaultView') {
1167			defaultView = allMetas[i].content;
1168		}
1169		if (allMetas[i].name == 'controlVis') {
1170			controlVis = allMetas[i].content;
1171		}
1172		if (allMetas[i].name == 'tranSitions') {
1173			tranSitions = (allMetas[i].content == "true") ? true : false;
1174			fadeModus = (tranSitions == true) ? true : false;
1175		}
1176		if (allMetas[i].name == 'fadeDuration') {
1177			var tmp = parseInt(allMetas[i].content);
1178			fadeDuration = Math.max(200,Math.min(tmp,2000));
1179		}
1180		if (allMetas[i].name == 'incrDuration') {
1181			var tmp = parseInt(allMetas[i].content);
1182			incrDuration = Math.max(50,Math.min(tmp,500));
1183		}
1184		if (allMetas[i].name == 'autoMatic') {
1185			autoMatic = (allMetas[i].content == "true") ? true : false;
1186		}
1187		if (allMetas[i].name == 'playLoop') {
1188			playLoop = (allMetas[i].content == "true") ? true : false;
1189		}
1190		if (allMetas[i].name == 'playDelay') {
1191			var tmp = parseInt(allMetas[i].content);
1192			playDelay = Math.max(5,Math.min(tmp,90))*1000;
1193			playDelay = (fadeModus == true) ? (playDelay+(2*fadeDuration)) : playDelay;
1194		}
1195		if (allMetas[i].name == 'audioSupport') {
1196			audioSupport = (allMetas[i].content == "true") ? true : false;
1197		}
1198		if (allMetas[i].name == 'audioVolume') {
1199			var tmp = parseInt(allMetas[i].content);
1200			audioVolume = Math.max(0,Math.min(tmp,100));
1201		}
1202		if (allMetas[i].name == 'audioError') {
1203			audioError = (allMetas[i].content == "true") ? true : false;
1204		}
1205	}
1206}
1207
1208function createProgress() {
1209	var obj = document.getElementsByTagName("body")[0].firstChild;
1210	var pg = document.createElement('div');
1211	pg.id = "StartupProgress";
1212	pg.style.position = 'absolute';
1213	pg.style.left = 0 + 'px';
1214	pg.style.top = 0 + 'px';
1215	pg.style.width = 100 + '%';
1216	pg.style.height = 100 + '%';
1217	pg.style.margin = 0 + 'px';
1218	pg.style.padding = 0 + 'px';
1219	if (isIE) {
1220		pg.style.filter = "alpha(opacity=100)";
1221	}else {
1222		pg.style.opacity = 1.0;
1223	}
1224	pg.style.zIndex = 9999;
1225	pg.style.backgroundColor="rgb(255, 255, 255)";
1226	pg.style.textAlign = "center";
1227	pg.style.verticalAlign = "middle";
1228	pg.style.backgroundPosition="center center";
1229	pg.style.backgroundRepeat="no-repeat";
1230	pg.style.backgroundImage="url("+s5Path+"ui/graphic_support/progress.gif)";
1231	document.getElementsByTagName("body")[0].insertBefore(pg,obj);
1232
1233	var im = document.createElement('img');
1234	im.id = "StartupControl";
1235	im.src = s5Path+"ui/graphic_support/blank.gif?" + new Date().valueOf();
1236	document.getElementsByTagName("body")[0].appendChild(im);
1237}
1238
1239function startup() {
1240	createControls(); // hallvord
1241	slideLabel();
1242	incrementals = createIncrementals();
1243	noteLabel(); // [SI:060104] must follow slideLabel()
1244	loadNote();
1245	fixLinks();
1246	externalLinks();
1247	fontScale();
1248	if (!isOp) {
1249		if(isIE) {
1250			document.getElementById('lst').style.backgroundImage = 'none';
1251			document.getElementById('del').style.backgroundImage = 'none';
1252		}else {
1253			document.getElementById('audio').style.backgroundImage = 'none';
1254		}
1255		notOperaFix();
1256	}else if(isOp) {
1257		var obj = document.getElementById('exit');
1258		obj.firstChild.style.visibility = 'hidden';
1259		document.getElementById('exit').style.opacity = 0.5;
1260		obj = document.getElementById('toggle');
1261		obj.firstChild.style.visibility = 'hidden';
1262		document.getElementById('toggle').style.opacity = 0.5;
1263		document.getElementById('jumplist').style.visibility = 'hidden';
1264		document.getElementById('list').style.visibility = 'hidden';
1265		document.getElementById('lst').style.opacity = 0.5;
1266		obj = document.getElementById('audio');
1267		obj.firstChild.style.visibility = 'hidden';
1268		document.getElementById('audio').style.opacity = 0.5;
1269		document.getElementById('volumelist').style.visibility = 'hidden';
1270		document.getElementById('volume').style.visibility = 'hidden';
1271		document.getElementById('vol').style.opacity = 0.5;
1272		document.getElementById('delaylist').style.visibility = 'hidden';
1273		document.getElementById('delay').style.visibility = 'hidden';
1274		document.getElementById('del').style.opacity = 0.5;
1275	}
1276	slideJump();
1277	if (defaultView == 'outline') toggle();
1278	document.onkeyup = keys;
1279	document.onkeypress = trap;
1280	document.onclick = clicker;
1281}
1282
1283function preloadImgages() {
1284	var temp = '';
1285	var objects = document.getElementsByTagName('img');
1286	for (var i=0; i < objects.length; i++) {
1287		if(objects[i].src != '') {
1288			temp = new Image();
1289			temp.src = objects[i].src;
1290		}
1291	}
1292}
1293
1294function showAll() {
1295	var obj1 = GetElementsWithClassName('div','presentation')[0];
1296	if(!obj1) var obj1 = GetElementsWithClassName('ol','presentation')[0];
1297	var obj2 = GetElementsWithClassName('div','layout')[0];
1298	if(!obj1){}else {obj1.style.display = 'block'};
1299	if(!obj2){}else {obj2.style.display = 'block'};
1300}
1301
1302function dumpProgress() {
1303	document.body.removeChild(document.getElementById('StartupControl'));
1304	startup();
1305	preloadImgages();
1306	showAll();
1307	createSoundManagerScript();
1308	shiftOpacity('StartupProgress',1000);
1309	window.setTimeout("removeProgress()",1000);
1310}
1311
1312function removeProgress() {
1313	document.body.removeChild(document.getElementById('StartupProgress'));
1314	setListPos(true); // invisible select extension
1315	panelSetup();
1316	audioSetup(); // audio extension
1317	if(isS2 && firstTime>=1) {
1318		generateCanvas(); // dynamic canvas extension
1319	} firstTime = 0;
1320}
1321function panelSetup() {
1322	if(playPause) {
1323		var obj = document.getElementById('pause'); changeClass(obj,'ison');
1324	}
1325	if(playLoop) {
1326		var obj = document.getElementById('loop'); changeClass(obj,'ison');
1327	}
1328	if(audioSupport && !isIE && !isOp) {
1329		var obj = document.getElementById('audio'); changeClass(obj,'ison');
1330	}
1331	if(fadeModus && !isIE) {
1332		var obj = document.getElementById('fade'); changeClass(obj,'ison');
1333	}
1334	if(autoMatic) {
1335		var obj = document.getElementById('auto'); changeClass(obj,'ison');
1336		startPlay();
1337	}
1338	if(audioVolume && !isIE && !isOp) {
1339		var idx = 0;
1340		if(audioVolume >= 95 && audioVolume <= 100) {idx = 0;}
1341		else if(audioVolume >= 85 && audioVolume < 95) {idx = 1;}
1342		else if(audioVolume >= 75 && audioVolume < 85) {idx = 2;}
1343		else if(audioVolume >= 65 && audioVolume < 75) {idx = 3;}
1344		else if(audioVolume >= 55 && audioVolume < 65) {idx = 4;}
1345		else if(audioVolume >= 45 && audioVolume < 55) {idx = 5;}
1346		else if(audioVolume >= 35 && audioVolume < 45) {idx = 6;}
1347		else if(audioVolume >= 25 && audioVolume < 35) {idx = 7;}
1348		else if(audioVolume >= 15 && audioVolume < 25) {idx = 8;}
1349		else if(audioVolume >= 5 && audioVolume < 15) {idx = 9;}
1350		else {idx = 10;}
1351		document.getElementById('volumelist').selectedIndex = idx;
1352	}
1353	if(playDelay && !isOp) {
1354		var idx = 0; var vol = parseInt(playDelay/1000);
1355		if(vol >= 83 && vol <= 90) {idx = 0;}
1356		else if(vol >= 68 && vol < 83) {idx = 1;}
1357		else if(vol >= 53 && vol < 68) {idx = 2;}
1358		else if(vol >= 38 && vol < 53) {idx = 3;}
1359		else if(vol >= 25 && vol < 38) {idx = 4;}
1360		else if(vol >= 18 && vol < 25) {idx = 5;}
1361		else if(vol >= 13 && vol < 18) {idx = 6;}
1362		else if(vol >= 8 && vol < 13) {idx = 7;}
1363		else {idx = 8;}
1364		document.getElementById('delaylist').selectedIndex = idx;
1365	}
1366}
1367// startup process
1368
1369// shutdown process
1370function byby() {
1371	stopPlay();
1372	if(tranSitions && fadeModus && s5mode && !isOp) {
1373		fadeoutSound(curSoundID,true); // audio support
1374		var pg = document.createElement('div');
1375		pg.id = "GoodBy";
1376		pg.style.position = 'absolute';
1377		pg.style.left = 0 + 'px';
1378		pg.style.top = 0 + 'px';
1379		pg.style.width = 100 + '%';
1380		pg.style.height = 100 + '%';
1381		pg.style.margin = 0 + 'px';
1382		pg.style.padding = 0 + 'px';
1383		if (isIE) {
1384			pg.style.filter = "alpha(opacity=0)";
1385		}else {
1386			pg.style.opacity = 0.0;
1387		}
1388		pg.style.zIndex = 9999;
1389		pg.style.backgroundColor="rgb(255, 255, 255)";
1390		pg.style.textAlign = "center";
1391		pg.style.verticalAlign = "middle";
1392		pg.style.backgroundPosition="center center";
1393		pg.style.backgroundRepeat="no-repeat";
1394		pg.style.backgroundImage="url("+s5Path+"ui/graphic_support/finish.gif)";
1395		document.getElementsByTagName("body")[0].appendChild(pg);
1396		shiftOpacity('GoodBy',1000);
1397		window.setTimeout("history.back()",1000);
1398	}else {
1399		stopSound(curSoundID);
1400		history.back();
1401	}
1402	snum = -1;
1403	try { sendNSCommand("slide "+snum); } catch (err) {}
1404}
1405// shutdown process
1406
1407// scalable images extension
1408function createDetector() {
1409	var em = document.createElement('div');
1410	em.id='EMSizeControl'; em.style.position="absolute"; em.style.left="-999px";
1411	em.style.width="1em"; em.style.height="1em"; em.style.opacity=0.0;
1412	document.getElementsByTagName("body")[0].appendChild(em);
1413	var nop=document.getElementById('EMSizeControl');
1414	if(!nop||findPosX(nop)!=-999) {}else {
1415		opac=document.getElementById('EMSizeControl').style.opacity;
1416		empx=document.getElementById('EMSizeControl').offsetHeight;
1417		document.body.removeChild(document.getElementById('EMSizeControl'));
1418		var objects = document.getElementsByTagName('img');
1419		var j = 0; var i = 0; var k = 0; var d; var obj;
1420		for (i=0; i < objects.length; i++) {
1421			if(objects[i].className.match(/^scale/i)) {
1422				images[j] = objects[i];
1423				++j;
1424			}
1425		}
1426		var objects = document.getElementsByTagName('canvas'); j = 0;
1427		for (i=0; i < objects.length; i++) {
1428			if(objects[i].className.match(/^scale/i)) {
1429				canvas[objects[i].id] = objects[i];
1430				if(j==0) {
1431					if(objects[i].getContext) {
1432						canvasSupport = true;
1433					}
1434					++j;
1435				}
1436			}
1437		}
1438		if(canvasSupport!=true) {
1439			for (d in canvas) {
1440				try {
1441					canvas[d].setAttribute("width",1);
1442					canvas[d].setAttribute("height",1);
1443				} catch (e) {
1444				}
1445			}
1446		}
1447		var objects = document.getElementsByTagName('table');
1448		j = 0; k = 0; l = 0; var w; var h; var tmp; var cnt;
1449		for (i=0; i < objects.length; i++) {
1450			if(objects[i].className.match(/^piechart/i)) {
1451				tmp = objects[i].id;
1452				cnt = tmp.split("_");
1453				obj = cnt[0] + "_canvas";
1454				if(canvas[obj]) {
1455					w = canvas[obj].getAttribute("width");
1456					h = canvas[obj].getAttribute("height");
1457					if(w>0&&h>0) {
1458						piecharts[j] = objects[i];
1459						em = piecharts[j].getAttribute("summary");
1460						if(em != "") em = "," + em;
1461						piecharts[j].setAttribute("summary", w + "," + h + em);
1462						++j;
1463					}
1464				}
1465			}
1466			if(objects[i].className.match(/^barchart/i)) {
1467				tmp = objects[i].id;
1468				cnt = tmp.split("_");
1469				obj = cnt[0] + "_canvas";
1470				if(canvas[obj]) {
1471					w = canvas[obj].getAttribute("width");
1472					h = canvas[obj].getAttribute("height");
1473					if(w>0&&h>0) {
1474						barcharts[k] = objects[i];
1475						em = barcharts[k].getAttribute("summary");
1476						if(em != "") em = "," + em;
1477						barcharts[k].setAttribute("summary", w + "," + h + em);
1478						++k;
1479					}
1480				}
1481			}
1482			if(objects[i].className.match(/^linechart/i)) {
1483				tmp = objects[i].id;
1484				cnt = tmp.split("_");
1485				obj = cnt[0] + "_canvas";
1486				if(canvas[obj]) {
1487					w = canvas[obj].getAttribute("width");
1488					h = canvas[obj].getAttribute("height");
1489					if(w>0&&h>0) {
1490						linecharts[l] = objects[i];
1491						em = linecharts[l].getAttribute("summary");
1492						if(em != "") em = "," + em;
1493						linecharts[l].setAttribute("summary", w + "," + h + em);
1494						++l;
1495					}
1496				}
1497			}
1498		}
1499		objects = document.getElementsByTagName('object'); j = 0; i = 0;
1500		for (i=0; i < objects.length; i++) {
1501			if(objects[i].className.match(/^scale/i)) {
1502				medias[j] = objects[i]; ++j;
1503				if(!isIE) {
1504  					if(objects[i].getAttributeNode("classid")) objects[i].removeAttributeNode(objects[i].getAttributeNode("classid"));
1505				  	if(objects[i].getAttributeNode("codebase")) objects[i].removeAttributeNode(objects[i].getAttributeNode("codebase"));
1506				}
1507			}
1508		}
1509	}
1510}
1511function extendImgSizes(f) {
1512	if(empx>0) {
1513		var q = (f/empx); var w = 0; var h = 0;
1514		for(var i=0; i < images.length; i++) {
1515			w=images[i].getAttribute("width",0);
1516			h=images[i].getAttribute("height",0);
1517			if(w>0&&h>0) {
1518				images[i].style.width=Math.floor(w*q)+"px";
1519				images[i].style.height=Math.floor(h*q)+"px";
1520			}
1521		}
1522	}
1523}
1524
1525function extendCanSizes(f) {
1526	if(empx>0 && canvasSupport) {
1527		var q = (f/empx); var w = 0; var h = 0; var tmp = ""; var cnt; var obj;
1528		for(var i=0; i < piecharts.length; i++) {
1529			if(piecharts[i].getAttribute("summary")) {
1530				tmp = piecharts[i].getAttribute("summary");
1531				cnt = tmp.split(",");
1532				if(cnt[0].match(/^[1-9][0-9]+/)) w = parseInt(cnt[0]);
1533				if(cnt[1].match(/^[1-9][0-9]+/)) h = parseInt(cnt[1]);
1534				if(w>0&&h>0) {
1535					tmp = piecharts[i].id;
1536					cnt = tmp.split("_");
1537					obj = cnt[0] + "_canvas";
1538					canvas[obj].setAttribute("width",Math.floor(w*q));
1539					canvas[obj].setAttribute("height",Math.floor(h*q));
1540					canvas[obj].style.width=Math.floor(w*q)+"px";
1541					canvas[obj].style.height=Math.floor(h*q)+"px";
1542				}
1543			}
1544		}
1545		for(var i=0; i < barcharts.length; i++) {
1546			if(barcharts[i].getAttribute("summary")) {
1547				tmp = barcharts[i].getAttribute("summary");
1548				cnt = tmp.split(",");
1549				if(cnt[0].match(/^[1-9][0-9]+/)) w = parseInt(cnt[0]);
1550				if(cnt[1].match(/^[1-9][0-9]+/)) h = parseInt(cnt[1]);
1551				if(w>0&&h>0) {
1552					tmp = barcharts[i].id;
1553					cnt = tmp.split("_");
1554					obj = cnt[0] + "_canvas";
1555					canvas[obj].setAttribute("width",Math.floor(w*q));
1556					canvas[obj].setAttribute("height",Math.floor(h*q));
1557					canvas[obj].style.width=Math.floor(w*q)+"px";
1558					canvas[obj].style.height=Math.floor(h*q)+"px";
1559				}
1560			}
1561		}
1562		for(var i=0; i < linecharts.length; i++) {
1563			if(linecharts[i].getAttribute("summary")) {
1564				tmp = linecharts[i].getAttribute("summary");
1565				cnt = tmp.split(",");
1566				if(cnt[0].match(/^[1-9][0-9]+/)) w = parseInt(cnt[0]);
1567				if(cnt[1].match(/^[1-9][0-9]+/)) h = parseInt(cnt[1]);
1568				if(w>0&&h>0) {
1569					tmp = linecharts[i].id;
1570					cnt = tmp.split("_");
1571					obj = cnt[0] + "_canvas";
1572					canvas[obj].setAttribute("width",Math.floor(w*q));
1573					canvas[obj].setAttribute("height",Math.floor(h*q));
1574					canvas[obj].style.width=Math.floor(w*q)+"px";
1575					canvas[obj].style.height=Math.floor(h*q)+"px";
1576				}
1577			}
1578		}
1579	}
1580}
1581function extendObjSizes(f) {
1582	if(empx>0) {
1583		var q = (f/empx); var w = 0; var h = 0;
1584		for(var i=0; i < medias.length; i++) {
1585			w=medias[i].getAttribute("width",0);
1586			h=medias[i].getAttribute("height",0);
1587			if(w>0&&h>0) {
1588				medias[i].style.width=Math.floor(w*q)+"px";
1589				medias[i].style.height=Math.floor(h*q)+"px";
1590			}
1591		}
1592	}
1593}
1594function findPosX(obj) {
1595	var posLeft = 0;
1596	while (obj.offsetParent) {
1597		posLeft += obj.offsetLeft;
1598		obj = obj.offsetParent;
1599	}
1600	return posLeft;
1601}
1602function findPosY(obj) {
1603	var posTop = 0;
1604	while (obj.offsetParent) {
1605		posTop += obj.offsetTop;
1606		obj = obj.offsetParent;
1607	}
1608	return posTop;
1609}
1610// scalable images extension
1611
1612// canvas chart extension
1613function deg2rad(degrees) {
1614	return Math.PI *degrees/180;
1615}
1616function rad2deg(radians) {
1617	return 180.0 *radians/Math.PI;
1618}
1619function circle_point_x(radians, diameter) {
1620	var x = Math.cos(radians)*(diameter/2);
1621	return x;
1622}
1623function circle_point_y(radians, diameter) {
1624	var y = Math.sin(radians)*(diameter/2);
1625	return y;
1626}
1627function roundTo(val,dig) {
1628	var num = val;
1629	if (val > 8191 && val < 10485) {
1630		val = val-5000;
1631		num = Math.round(val*Math.pow(10,dig))/Math.pow(10,dig);
1632		num = num+5000;
1633	} else {
1634		num = Math.round(val*Math.pow(10,dig))/Math.pow(10,dig);
1635	}
1636	return num;
1637}
1638function searchColor(value) {
1639	for (var dat in colorNames) {
1640		if(dat==value) return colorNames[dat];
1641    }
1642    return false;
1643}
1644function scanColor(value) {
1645	if(value.match(/^#[0-9a-f][0-9a-f][0-9a-f]$/i)) {
1646		var val1 = value.substr(1,1).toLowerCase();
1647		var val2 = value.substr(2,1).toLowerCase();
1648		var val3 = value.substr(3,1).toLowerCase();
1649		value = '#' + val1 + val1 + val2 + val2 + val3 + val3;
1650	}
1651	if(!value.match(/^#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i)) {
1652		var tmp = searchColor(value.toLowerCase());
1653		if(!tmp) {}else{value = tmp;}
1654	}
1655	if(!value.match(/^#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i)) {
1656		value = '#000000';
1657	}
1658	return value.toLowerCase();
1659}
1660function hex2rgb(val,trans) {
1661	if(val.length==7) {
1662		var tp1 = Math.max(0,Math.min(parseInt(val.substr(1,2),16),255));
1663		var tp2 = Math.max(0,Math.min(parseInt(val.substr(3,2),16),255));
1664		var tp3 = Math.max(0,Math.min(parseInt(val.substr(5,2),16),255));
1665		return 'rgba(' + tp1 + ',' + tp2 + ',' + tp3 + ',' + trans + ')';
1666	}
1667}
1668function trim(str) {
1669    return (str.replace(/\s+$/,"").replace(/^\s+/,""));
1670}
1671function roundedRect(ctx,x,y,width,height,radius){
1672	ctx.beginPath();
1673	ctx.moveTo(x,y+radius);
1674	ctx.lineTo(x,y+height-radius);
1675	ctx.quadraticCurveTo(x,y+height,x+radius,y+height);
1676	ctx.lineTo(x+width-radius,y+height);
1677	ctx.quadraticCurveTo(x+width,y+height,x+width,y+height-radius);
1678	ctx.lineTo(x+width,y+radius);
1679	ctx.quadraticCurveTo(x+width,y,x+width-radius,y);
1680	ctx.lineTo(x+radius,y);
1681	ctx.quadraticCurveTo(x,y,x,y+radius);
1682	ctx.closePath();
1683}
1684function drawString(ctx, text, fc, tx, ty) {
1685	var xp = 0; var c = "";
1686	ctx.beginPath();
1687	for (var i = 0; i < text.length; i++) {
1688		c = text[i];
1689		ctx.drawImage(font, signs[c].sx, signs[c].sy, signs[c].sw, signs[c].sh, tx+xp, ty, signs[c].sw*fc, signs[c].sh*fc);
1690		xp += (signs[c].sw*fc);
1691	}
1692	ctx.closePath();
1693}
1694function strokeString(ctx, txt, col, fh, tx, ty) {
1695	var fw = fh*0.666666; var lw = fh*0.125;
1696	var ls = lw/2; var cr = lw; var xp = 0;
1697	ctx.lineCap = "round"; ctx.lineJoin = "round"
1698	ctx.lineWidth = lw; ctx.strokeStyle = col;
1699	for (var i = 0; i < txt.length; i++) {
1700		strokeSymbol(ctx, txt[i], ls, tx+xp, ty, fw, fh);
1701		xp += (txt[i]!="."?fw+cr:(fw/2)+cr);
1702	}
1703}
1704function strokeSymbol(ctx, symbol, fc, cx, cy, cw, ch) {
1705	ctx.beginPath();
1706	switch (symbol) {
1707		case "0":
1708			ctx.moveTo(cx+fc,cy+(ch*0.333333));
1709			ctx.arc(cx+(cw/2),cy+(cw/2),(cw/2)-fc,deg2rad(180),0, false);
1710			ctx.arc(cx+(cw/2),(cy+ch)-(cw/2),(cw/2)-fc,0,deg2rad(180), false);
1711			ctx.closePath();
1712		break;
1713		case "1":
1714			ctx.moveTo(cx+(cw*0.1)+fc,cy+ch-fc);
1715			ctx.lineTo(cx+cw-fc,cy+ch-fc);
1716			ctx.moveTo(cx+(cw*0.666666),cy+ch-fc);
1717			ctx.lineTo(cx+(cw*0.666666),cy+fc);
1718			ctx.lineTo(cx+(cw*0.25),cy+(ch*0.25));
1719		break;
1720		case "2":
1721			ctx.moveTo(cx+cw-fc,cy+(ch*0.8));
1722			ctx.lineTo(cx+cw-fc,cy+ch-fc);
1723			ctx.lineTo(cx+fc,cy+ch-fc);
1724			ctx.arc(cx+(cw/2),cy+(cw*0.425),(cw*0.425)-fc,deg2rad(45),deg2rad(-180), true);
1725		break;
1726		case "3":
1727			ctx.moveTo(cx+(cw*0.1)+fc,cy+fc);
1728			ctx.lineTo(cx+(cw*0.9)-fc,cy+fc);
1729			ctx.arc(cx+(cw/2),cy+ch-(cw*0.5),(cw*0.5)-fc,deg2rad(-90),deg2rad(180), false);
1730		break;
1731		case "4":
1732			ctx.moveTo(cx+(cw*0.75),cy+ch-fc);
1733			ctx.lineTo(cx+(cw*0.75),cy+fc);
1734			ctx.moveTo(cx+cw-fc,cy+(ch*0.666666));
1735			ctx.lineTo(cx+fc,cy+(ch*0.666666));
1736			ctx.lineTo(cx+(cw*0.75),cy+fc);
1737			ctx.moveTo(cx+cw-fc,cy+ch-fc);
1738			ctx.lineTo(cx+(cw*0.5),cy+ch-fc);
1739		break;
1740		case "5":
1741			ctx.moveTo(cx+(cw*0.9)-fc,cy+fc);
1742			ctx.lineTo(cx+(cw*0.1)+fc,cy+fc);
1743			ctx.lineTo(cx+(cw*0.1)+fc,cy+(ch*0.333333));
1744			ctx.arc(cx+(cw/2),cy+ch-(cw*0.5),(cw*0.5)-fc,deg2rad(-80),deg2rad(180), false);
1745		break;
1746		case "6":
1747			ctx.moveTo(cx+fc,cy+ch-(cw*0.5)-fc);
1748			ctx.arc(cx+(cw/2),cy+ch-(cw*0.5),(cw*0.5)-fc,deg2rad(-180),deg2rad(180), false);
1749			ctx.bezierCurveTo(cx+fc,cy+fc,cx+fc,cy+fc,cx+(cw*0.9)-fc,cy+fc);
1750			ctx.moveTo(cx+(cw*0.9)-fc,cy+fc);
1751		break;
1752		case "7":
1753			ctx.moveTo(cx+(cw*0.5),cy+ch-fc);
1754			ctx.lineTo(cx+cw-fc,cy+fc);
1755			ctx.lineTo(cx+(cw*0.1)+fc,cy+fc);
1756			ctx.lineTo(cx+(cw*0.1)+fc,cy+(ch*0.25)-fc);
1757		break;
1758		case "8":
1759			ctx.moveTo(cx+(cw*0.92)-fc,cy+(cw*0.59));
1760			ctx.arc(cx+(cw/2),cy+(cw*0.45),(cw*0.45)-fc,deg2rad(25),deg2rad(-205), true);
1761			ctx.arc(cx+(cw/2),cy+ch-(cw*0.5),(cw*0.5)-fc,deg2rad(-135),deg2rad(-45), true);
1762			ctx.closePath();
1763			ctx.moveTo(cx+(cw*0.79),cy+(ch*0.47));
1764			ctx.lineTo(cx+(cw*0.21),cy+(ch*0.47));
1765		break;
1766		case "9":
1767			ctx.moveTo(cx+cw-fc,cy+(cw*0.5));
1768			ctx.arc(cx+(cw/2),cy+(cw*0.5),(cw*0.5)-fc,deg2rad(0),deg2rad(360), false);
1769			ctx.bezierCurveTo(cx+cw-fc,cy+ch-fc,cx+cw-fc,cy+ch-fc,cx+(cw*0.1)+fc,cy+ch-fc);
1770		break;
1771		case "%":
1772			ctx.moveTo(cx+fc,cy+(ch*0.75));
1773			ctx.lineTo(cx+cw-fc,cy+(ch*0.25));
1774			ctx.moveTo(cx+(cw*0.505),cy+(cw*0.3));
1775			ctx.arc(cx+(cw*0.3),cy+(cw*0.3),(cw*0.3)-fc,deg2rad(0),deg2rad(360), false);
1776			ctx.moveTo(cx+(cw*0.905),cy+ch-(cw*0.3));
1777			ctx.arc(cx+(cw*0.7),cy+ch-(cw*0.3),(cw*0.3)-fc,deg2rad(0),deg2rad(360), false);
1778		break;
1779		case ".":
1780			ctx.moveTo(cx+(cw*0.25),cy+ch-fc-fc);
1781			ctx.arc(cx+(cw*0.25),cy+ch-fc-fc,fc,deg2rad(0),deg2rad(360), false);
1782			ctx.closePath();
1783		break;
1784		default:
1785		break;
1786	}
1787	ctx.stroke();
1788}
1789function drawBar(ctx,x,y,width,height,color,value,textdiv){
1790	var rw = width/2; var rh = rw/2;
1791	height = Math.max(height,rw);
1792	var dh = Math.max(height-(2*rh),0.1); var S2L;
1793	var xx = rw/8; var yy = rh/4;
1794	var yo = rh/2; y = y - yy;
1795	if(canvas_noshadow <= 0 && canvas_noshade <= 0) {
1796		ctx.save();
1797		S2L = ctx.createRadialGradient(x+rw+rh,y+height-rw+yy+rh,0,x+rw,y+height-rw+yy,rw);
1798		S2L.addColorStop(0, 'rgba(0,0,0,0.5)');
1799		S2L.addColorStop(0.7, 'rgba(0,0,0,0.25)');
1800		S2L.addColorStop(0.9, 'rgba(0,0,0,0.1)');
1801		S2L.addColorStop(1, 'rgba(0,0,0,0)');
1802		ctx.fillStyle = S2L;
1803		ctx.scale(1,0.5);
1804		ctx.translate(xx,y+height+yy);
1805		if(isOp){
1806			ctx.fillRect(x,y+yy+height-width,width,width);
1807		}else {
1808	  		ctx.arc(x+rw,y+yy+height-width,width,0,deg2rad(360), false);
1809			ctx.fill();
1810		}
1811		ctx.restore();
1812	}else if(canvas_noshadow <= 0 && canvas_noshade >= 1) {
1813  		ctx.fillStyle = 'rgba(0,0,0,0.2)';
1814		ctx.fillRect(x+yo,y+rh+yo+yo,width,dh);
1815	}
1816
1817	if(canvas_noshade <= 0) {
1818		ctx.beginPath();
1819	  	ctx.moveTo(x,y+rh);
1820		ctx.lineTo(x,y+rh+dh);
1821		ctx.bezierCurveTo(x,y+height,x+width,y+height,x+width,y+rh+dh)
1822		ctx.lineTo(x+width,y+rh);
1823		ctx.bezierCurveTo(x+width,y,x,y,x,y+rh)
1824		ctx.closePath();
1825		ctx.fillStyle = color;
1826		ctx.fill();
1827		S2L = ctx.createLinearGradient(x,y+(height/2),x+width,y+(height/2));
1828		S2L.addColorStop(0, 'rgba(255,255,255,0.75)');
1829		S2L.addColorStop(0.2, 'rgba(255,255,255,0)');
1830		S2L.addColorStop(0.3, 'rgba(0,0,0,0)');
1831		S2L.addColorStop(0.5, 'rgba(0,0,0,0.1)');
1832		S2L.addColorStop(0.9, 'rgba(0,0,0,0.35)');
1833		S2L.addColorStop(1, 'rgba(0,0,0,0.3)');
1834		ctx.beginPath();
1835	  	ctx.moveTo(x,y+rh);
1836		ctx.lineTo(x,y+rh+dh);
1837		ctx.bezierCurveTo(x,y+height,x+width,y+height,x+width,y+rh+dh)
1838		ctx.lineTo(x+width,y+rh);
1839		ctx.bezierCurveTo(x+width,y,x,y,x,y+rh)
1840		ctx.closePath();
1841		ctx.fillStyle = S2L;
1842		ctx.fill();
1843		ctx.beginPath();
1844		ctx.moveTo(x+width,y+rh);
1845		ctx.bezierCurveTo(x+width,y,x,y,x,y+rh)
1846		ctx.bezierCurveTo(x,y+(rh*2),x+width,y+(rh*2),x+width,y+rh)
1847		ctx.closePath();
1848		ctx.fillStyle = color;
1849		ctx.fill();
1850		S2L = ctx.createLinearGradient(x+rw-(width*0.15),y-2,x+rw+(width*0.15),y+(2.1*rh));
1851		S2L.addColorStop(0, 'rgba(255,255,255,0.9)');
1852		S2L.addColorStop(0.5, 'rgba(255,255,255,0)');
1853		S2L.addColorStop(0.6, 'rgba(0,0,0,0)');
1854		S2L.addColorStop(1, 'rgba(0,0,0,0.3)');
1855		ctx.beginPath();
1856		ctx.moveTo(x+width,y+rh);
1857		ctx.bezierCurveTo(x+width,y,x,y,x,y+rh)
1858		ctx.bezierCurveTo(x,y+(rh*2),x+width,y+(rh*2),x+width,y+rh)
1859		ctx.closePath();
1860		ctx.fillStyle = S2L;
1861		ctx.fill();
1862		S2L = ctx.createLinearGradient(x+rw-(width*0.15),y-2,x+rw+(width*0.15),y+(2.1*rh));
1863		S2L.addColorStop(0, 'rgba(255,255,255,0.9)');
1864		S2L.addColorStop(0.5, 'rgba(255,255,255,0)');
1865		S2L.addColorStop(0.6, 'rgba(0,0,0,0)');
1866		S2L.addColorStop(1, 'rgba(0,0,0,0.1)');
1867		ctx.beginPath();
1868		ctx.moveTo(x+width,y+rh);
1869		ctx.bezierCurveTo(x+width,y,x,y,x,y+rh)
1870		ctx.bezierCurveTo(x,y+(rh*2),x+width,y+(rh*2),x+width,y+rh)
1871		ctx.closePath();
1872		ctx.strokeStyle = S2L;
1873		ctx.stroke();
1874	}else {
1875  		ctx.fillStyle = color;
1876		ctx.fillRect(x,y+rh+yo,width,dh);
1877	}
1878	ctx.lineCap = "butt";
1879	ctx.lineWidth = 1;
1880	ctx.fillStyle = 'rgba(255,255,255,0.5)';
1881	var bw = width; var bh = bw/4;
1882	var th = roundTo(bh*0.75,0); var tf = bh/80;
1883	var c; var w;
1884	if(canvas_notext <= 0) {
1885		if(canvas_htmltext <= 0) {
1886			w = '"' + per + '"';
1887			if(w.indexOf(".")!=-1) {
1888				c = w.length+0.5;
1889				w = parseFloat(c-2)*parseFloat(48*tf);
1890				bw = parseFloat(c-1)*parseFloat(48*tf);
1891			}else {
1892				c = w.length;
1893				w = parseFloat(c-1)*parseFloat(48*tf);
1894				bw = parseFloat(c)*parseFloat(48*tf);
1895			}
1896			roundedRect(ctx,x+(width/2)-(bw/2),y,bw,bh,bh/4);
1897			ctx.fill();
1898			if(canvas_imgtext <= 0) {
1899				strokeString(ctx, value + "%","rgba(48,48,48,1)", th, x+(width/2)-(w/2), y+((bh-th)/2));
1900			}else {
1901				drawString(ctx, value + "%", tf, x+(width/2)-(w/2), y+((bh-th)/2.2));
1902			}
1903		}else {
1904			var bh = bw/3; var th = roundTo(bh*0.75,0);
1905			roundedRect(ctx,x,y,bw,bh,bh/4);
1906			ctx.fill();
1907			var obj = document.createElement('div');
1908			obj.style.position = "absolute";
1909			obj.style.overflow = "hidden";
1910            obj.style.textAlign = "center";
1911			obj.style.width = bw + "px";
1912			obj.style.left = x + "px";
1913			obj.style.top = y+((bh-th)/2.2) + "px";
1914			obj.appendChild(document.createTextNode(per + "%"));
1915			textdiv.appendChild(obj);
1916		}
1917
1918	}
1919}
1920function drawLine(ctx,x,y,width,height,dist,array,factor,color,fill){
1921	if(fill <= 0){
1922		var style = hex2rgb(color,0.5);
1923		ctx.lineJoin = "miter";
1924		ctx.beginPath();
1925	  	ctx.moveTo(x,y+height);
1926		for (var i = 0; i < array.length; i++) {
1927			ctx.lineTo(x+(i*dist),y+height-(array[i]*factor));
1928		}
1929		ctx.lineTo(x+width,y+height);
1930		ctx.lineTo(x,y+height);
1931		ctx.closePath();
1932		ctx.fillStyle = style;
1933		ctx.fill();
1934	}
1935	ctx.lineJoin = "round";
1936	ctx.beginPath();
1937  	ctx.moveTo(x,y+height-(array[0]*factor));
1938	for (var i = 0; i < array.length; i++) {
1939		ctx.lineTo(x+(i*dist),y+height-(array[i]*factor));
1940	}
1941	ctx.strokeStyle = color;
1942	ctx.stroke();
1943}
1944function setDataURL(cid) {
1945	if(cid.toDataURL) {
1946		var obj = document.getElementById(cid.id + "_link");
1947		if(obj) {
1948			obj.setAttribute("title", "To Data URL");
1949			obj.setAttribute("target", "_blank");
1950			obj.setAttribute("href", cid.toDataURL());
1951		}
1952	}
1953}
1954function get_input(dataobj,canvasobj,linechart) {
1955	var table = document.getElementById(dataobj);
1956	var canvas = document.getElementById(canvasobj);
1957	var row; var clm; var cnt = 0; var val = 0; var nme = ""; var col = "";
1958	if(canvas.getContext) {
1959		canvas_width = parseInt(canvas.style.width);
1960		canvas_height = parseInt(canvas.style.height);
1961		if(canvas_width >= 16 && canvas_height >= 16) {
1962			var tmp = table.getAttribute("summary");
1963			canvas_noshade = 0; canvas_noshadow = 0;
1964			canvas_notext = 0; canvas_imgtext = 0;
1965			canvas_htmltext = 0; canvas_nofill = 0;
1966			if(tmp.search(/noshadow/) != -1) canvas_noshadow = 1;
1967			if(tmp.search(/noshade/) != -1) canvas_noshade = 1;
1968			if(tmp.search(/nofill/) != -1) canvas_nofill = 1;
1969			if(tmp.search(/notext/) != -1) canvas_notext = 1;
1970			if(tmp.search(/htmltext/) != -1) canvas_htmltext = 1;
1971			if(tmp.search(/imgtext/) != -1) canvas_imgtext = 1;
1972			if(table.getAttribute("bgcolor")) {
1973				canvas_bgcolor = scanColor(table.getAttribute("bgcolor"));
1974			}
1975			ChartData = new Array(); colorSlice = new Array();
1976			if(table.getElementsByTagName("tr")[0].getElementsByTagName("th")[0]) cnt = 1;
1977			for(var r = cnt; r < table.getElementsByTagName("tr").length; r++) {
1978				row = table.getElementsByTagName("tr")[r];
1979				clm = row.getElementsByTagName("td").length;
1980				if(row.getElementsByTagName("td")[0].getAttribute("bgcolor")) {
1981					col = scanColor(row.getElementsByTagName("td")[0].getAttribute("bgcolor")); val = 0;
1982					nme = trim(row.getElementsByTagName("td")[1].innerHTML.replace(/<[^>]+>/g,""));
1983					if(!linechart) {
1984						if(clm > 3) {
1985							for(var z = 2; z < clm; z++) {
1986								val += parseFloat(row.getElementsByTagName("td")[z].innerHTML.replace(/<[^>]+>/g,""));
1987							}
1988						}else {
1989							val = parseFloat(row.getElementsByTagName("td")[2].innerHTML.replace(/<[^>]+>/g,""));
1990						}
1991						if(!isNaN(val) && val > 0 && nme != '') {
1992							colorSlice[r-cnt] = col; ChartData[nme] = Math.abs(val);
1993						}else {
1994							break;
1995						}
1996					}else {
1997						val = 0; i = 0;
1998						if(clm > 3 && nme != '') {
1999							ChartData[r-cnt] = new Array();
2000							colorSlice[r-cnt] = col;
2001							for(var z = 2; z < clm; z++) {
2002								val = Math.abs(parseFloat(row.getElementsByTagName("td")[z].innerHTML.replace(/<[^>]+>/g,"")));
2003								if(!isNaN(val) && val >= 0) {
2004									ChartData[r-cnt][i] = val; i++;
2005								}else {
2006									ChartData[r-cnt][i] = 0; i++;
2007								}
2008							}
2009						}else {
2010							break;
2011						}
2012					}
2013				}else {
2014					break;
2015				}
2016			}
2017		}
2018	}
2019}
2020function setPieChart(canvasobj,textobj) {
2021	var cd = (Math.min(canvas_width,canvas_height)/110)*100;
2022	var cp = cd*0.1; var cr = cd/2;
2023	var sr = cr*0.93; var cw = cd+cp; var ch = cw;
2024	var cx = (cd/2)+(cp/2); var cy = cx; var ct = 0;
2025	for (var data in ChartData) {
2026		ct += ChartData[data];
2027	}
2028	var poc = ct/100;
2029	var canvas = document.getElementById(canvasobj);
2030	if(canvas_htmltext >= 1) {
2031		if(document.getElementById(textobj)) {
2032	  		canvas.parentNode.removeChild(canvas.parentNode.lastChild);
2033		}
2034	}
2035	if(canvas.getContext) {
2036		var ctx = canvas.getContext('2d');
2037		if(canvas_bgcolor != "") {
2038  			ctx.fillStyle = canvas_bgcolor;
2039			ctx.fillRect(0,0,cw,ch);
2040		}else {
2041			ctx.clearRect(0,0,cw,ch);
2042		}
2043		if(canvas_noshadow <= 0) {
2044			if(!isOp) {
2045				ctx.beginPath();
2046				var B2B = ctx.createRadialGradient(cx+(cr*0.1),cy+(cr*0.1),cr,cx+(cr*0.1),cy+(cr*0.1),sr*0.9);
2047				B2B.addColorStop(0, 'rgba(0,0,0,0)');
2048				B2B.addColorStop(1, 'rgba(0,0,0,0.5)');
2049				ctx.arc(cx+(cr*0.1),cy+(cr*0.1),cr,0,deg2rad(360), false);
2050				ctx.closePath();
2051	   			ctx.fillStyle = B2B;
2052				ctx.fill();
2053			}else {
2054				var B2B = ctx.createRadialGradient(cx+(cr*0.1),cy+(cr*0.1),0,cx+(cr*0.1),cy+(cr*0.1),cr);
2055				B2B.addColorStop(0, 'rgba(0,0,0,0.5)');
2056				B2B.addColorStop(0.87, 'rgba(0,0,0,0.5)');
2057				B2B.addColorStop(1, 'rgba(0,0,0,0)');
2058				ctx.fillStyle = B2B;
2059				ctx.fillRect(0,0,cw,ch);
2060			}
2061		}
2062		var val = 0; var deg = 0; var idx = 0; var data;
2063		for (data in ChartData) {
2064			val = ChartData[data]; sdeg = deg;
2065			deg += (val/ct)*deg2rad(360); edeg = deg;
2066			ctx.beginPath();
2067  			ctx.moveTo(cx,cy);
2068			ctx.arc(cx,cy,cr,sdeg,edeg, false);
2069			ctx.lineTo(cx,cy);
2070			ctx.closePath();
2071  			ctx.fillStyle = colorSlice[(idx++)];
2072			ctx.fill();
2073		}
2074		if(canvas_noshade <= 0) {
2075			ctx.beginPath();
2076			var W2T = ctx.createLinearGradient(cp*2,cp*2,cx,cy);
2077			W2T.addColorStop(0, 'rgba(255,255,255,0.8)');
2078			W2T.addColorStop(1, 'rgba(255,255,255,0)');
2079			ctx.moveTo(cx,cy);
2080			ctx.arc(cx,cy,sr,deg2rad(135),deg2rad(315), false);
2081			ctx.closePath();
2082			ctx.fillStyle = W2T;
2083			ctx.fill();
2084			ctx.beginPath();
2085			var T2B = ctx.createLinearGradient(cx,cy,cw-(cp*2),ch-(cp*2));
2086			T2B.addColorStop(0, 'rgba(0,0,0,0)');
2087			T2B.addColorStop(1, 'rgba(0,0,0,0.5)');
2088			ctx.moveTo(cx,cy);
2089			ctx.arc(cx,cy,sr,deg2rad(-45),deg2rad(135), false);
2090			ctx.closePath();
2091			ctx.fillStyle = T2B;
2092			ctx.fill();
2093			ctx.beginPath();
2094			var B2T = ctx.createLinearGradient(cx,cy,cw-(cp*1.9),ch-(cp*1.9));
2095			B2T.addColorStop(0, 'rgba(0,0,0,0)');
2096			B2T.addColorStop(1, 'rgba(0,0,0,0.6)');
2097			ctx.lineWidth = cr*0.07;
2098			ctx.lineCap = "round";
2099			ctx.moveTo(cx,cy);
2100			ctx.arc(cx,cy,cr*0.965,deg2rad(-45),deg2rad(135), false);
2101			ctx.closePath();
2102			ctx.strokeStyle = B2T;
2103			ctx.stroke();
2104			ctx.beginPath();
2105			var T2W = ctx.createLinearGradient(cx,cy,(cp*1.9),(cp*1.9));
2106			T2W.addColorStop(0, 'rgba(255,255,255,0)');
2107			T2W.addColorStop(1, 'rgba(255,255,255,0.6)');
2108			ctx.lineWidth = cr*0.07;
2109			ctx.lineCap = "round";
2110			ctx.moveTo(cx,cy);
2111			ctx.arc(cx,cy,cr*0.965,deg2rad(135),deg2rad(315), false);
2112			ctx.closePath();
2113			ctx.strokeStyle = T2W;
2114			ctx.stroke();
2115		}
2116		ctx.lineCap = "butt";
2117		ctx.lineWidth = 1;
2118		ctx.fillStyle = 'rgba(255,255,255,0.5)';
2119		var mpos = 0; var per = 0; var gx = 0;
2120		var gy = 0; var tx = 0; var ty = 0;
2121		var obj = ""; var w = 0; var c = 0;
2122		var bw = cr*0.45; var bh = cr*0.125;
2123		var th = roundTo(bh*0.75,0); var tf = bh/80;
2124		if(canvas_notext <= 0) {
2125			if(canvas_htmltext >= 1) {
2126				bw = (cr*0.365);
2127				canvas.parentNode.style.position = "relative";
2128				if(!document.getElementById(textobj)) {
2129					obj = document.createElement('div');
2130					obj.id = textobj;
2131		            obj.style.color = "rgb(0,0,0)";
2132		            obj.style.fontFamily = "Arial,sans-serif";
2133					obj.style.fontSize = th + "px";
2134					obj.style.zIndex = 11;
2135					canvas.parentNode.appendChild(obj);
2136				}
2137				var textdiv = document.getElementById(obj.id);
2138			}
2139			for (data in ChartData) {
2140				val = ChartData[data];
2141				sdeg = deg; mpos = deg+(((val/2)/ct)*deg2rad(360));
2142				deg += (val/ct)*deg2rad(360); edeg = deg;
2143				per = roundTo(val/poc,2);
2144				gx = circle_point_x(mpos, cd);
2145				gy = circle_point_y(mpos, cd);
2146				tx = parseFloat((cx+(2*Math.floor(cx + gx)))/3);
2147				ty = (cy+(2*Math.floor(cy + gy)))/3;
2148				if(canvas_htmltext <= 0) {
2149					w = '"' + per + '"';
2150					if(w.indexOf(".")!=-1) {
2151						c = w.length+0.5;
2152						w = parseFloat(c-2)*parseFloat(48*tf);
2153						bw = parseFloat(c-1)*parseFloat(48*tf);
2154					}else {
2155						c = w.length;
2156						w = parseFloat(c-1)*parseFloat(48*tf);
2157						bw = parseFloat(c)*parseFloat(48*tf);
2158					}
2159					roundedRect(ctx,(tx-(bw/2)),ty-(bh/2),bw,bh,bh/4);
2160					ctx.fill();
2161					if(canvas_imgtext >= 1) {
2162						drawString(ctx, per + "%", tf, tx-(w/2), ty-(th/1.8));
2163					}else {
2164						strokeString(ctx, per + "%","rgba(48,48,48,1)", th, tx-(w/2), ty-(th/2));
2165					}
2166				}else {
2167					roundedRect(ctx,(tx-(bw/2)),ty-(bh/2),bw,bh,bh/4);
2168					ctx.fill();
2169					obj = document.createElement('div');
2170					obj.style.position = "absolute";
2171					obj.style.overflow = "hidden";
2172		            obj.style.textAlign = "center";
2173					obj.style.width = bw + "px";
2174					obj.style.left = (tx-(bw/2)) + "px";
2175					obj.style.top = ty-(th/1.8) + "px";
2176					obj.appendChild(document.createTextNode(per + "%"));
2177					textdiv.appendChild(obj);
2178				}
2179			}
2180		}
2181	}
2182}
2183function setBarChart(canvasobj,textobj) {
2184	var iw = canvas_width*0.9; var ih = canvas_height*0.9;
2185	var pw = canvas_width*0.05; var ph = canvas_height*0.05;
2186	var cm = 0; var ct = 0;
2187	for (var data in ChartData) {
2188		cm = Math.max(cm,ChartData[data]);
2189		ct += ChartData[data];
2190	}
2191	var hf = ih/cm; var bs = colorSlice.length;
2192	var bw = iw/(bs*1.1); var poc = ct/100;
2193	var th = roundTo((bw/3)*0.75,0);
2194	var canvas = document.getElementById(canvasobj);
2195	if(canvas.getContext) {
2196		var ctx = canvas.getContext('2d');
2197		if(canvas_bgcolor != "") {
2198  			ctx.fillStyle = canvas_bgcolor;
2199			ctx.fillRect(0,0,canvas_width,canvas_height);
2200		}else {
2201			ctx.clearRect(0,0,canvas_width,canvas_height);
2202		}
2203		if(canvas_htmltext >= 1) {
2204			if(document.getElementById(textobj)) {
2205	  			canvas.parentNode.removeChild(canvas.parentNode.lastChild);
2206			}
2207			canvas.parentNode.style.position = "relative";
2208			if(!document.getElementById(textobj)) {
2209				var obj = document.createElement('div');
2210				obj.id = textobj;
2211	            obj.style.color = "rgb(0,0,0)";
2212	            obj.style.fontFamily = "Arial,sans-serif";
2213				obj.style.fontSize = th + "px";
2214				obj.style.zIndex = 11;
2215				canvas.parentNode.appendChild(obj);
2216			}
2217			var textdiv = document.getElementById(obj.id);
2218		}
2219		var cc = ""; var bh = 0; var idx = 0; var t = 0; per = 0;
2220		for (var data in ChartData) {
2221			per = roundTo(ChartData[data]/poc,2);
2222			bh = ChartData[data]*hf;
2223			drawBar(ctx,pw+(t*(bw*1.1)),ph+ih-bh,bw,bh,colorSlice[(idx++)],per,textdiv);
2224			t++;
2225		}
2226	}
2227}
2228function setLineChart(canvasobj,textobj) {
2229	var iw = canvas_width*0.9;
2230	var ih = canvas_height*0.9;
2231	var pw = canvas_width*0.05;
2232	var ph = canvas_height*0.05;
2233	var cm = 0;
2234	for (var i = 0; i < ChartData.length; i++) {
2235		for (var j = 0; j < ChartData[i].length; j++) {
2236			cm = Math.max(cm,ChartData[i][j]);
2237		}
2238	}
2239	var hf = (ih*0.95)/cm; var bw = iw;
2240	var dw = iw/(ChartData[0].length-1)
2241	var dh = ih/(ChartData[0].length-1)
2242	var ps = Math.min(pw,ph); lw = ps/4;
2243	var B2T;
2244	var canvas = document.getElementById(canvasobj);
2245	if(canvas.getContext) {
2246		var ctx = canvas.getContext('2d');
2247		if(canvas_bgcolor != "") {
2248  			ctx.fillStyle = canvas_bgcolor;
2249			ctx.fillRect(0,0,canvas_width,canvas_height);
2250		}else {
2251			ctx.clearRect(0,0,canvas_width,canvas_height);
2252		}
2253		if(canvas_noshadow <= 0) {
2254			B2T = ctx.createLinearGradient(pw+ps,ph+ih+1,pw+ps+ps,ph+ih+1);
2255			B2T.addColorStop(0, 'rgba(0,0,0,0.0)');
2256			B2T.addColorStop(1, 'rgba(0,0,0,0.5)');
2257	  		ctx.fillStyle = B2T;
2258			ctx.beginPath();
2259	  		ctx.moveTo(pw+ps,ph+ih);
2260			ctx.lineTo(pw+ps,ph+ih+ps);
2261			ctx.lineTo(pw+ps+ps,ph+ih);
2262			ctx.closePath();
2263			ctx.fill();
2264			B2T = ctx.createLinearGradient(pw+ps+ps,ph+ih,pw+ps+ps,ph+ih+ps);
2265			B2T.addColorStop(0, 'rgba(0,0,0,0.5)');
2266			B2T.addColorStop(1, 'rgba(0,0,0,0.0)');
2267	  		ctx.fillStyle = B2T;
2268			ctx.beginPath();
2269	  		ctx.moveTo(pw+ps+ps,ph+ih);
2270			ctx.lineTo(pw+iw,ph+ih);
2271			ctx.lineTo(pw+ps+iw,ph+ih+ps);
2272			ctx.lineTo(pw+ps,ph+ih+ps);
2273			ctx.closePath();
2274			ctx.fill();
2275			var B2T = ctx.createLinearGradient(pw+iw+1,ph+ps,pw+iw+1,ph+ps+ps);
2276			B2T.addColorStop(0, 'rgba(0,0,0,0.0)');
2277			B2T.addColorStop(1, 'rgba(0,0,0,0.35)');
2278	  		ctx.fillStyle = B2T;
2279			ctx.beginPath();
2280	  		ctx.moveTo(pw+iw,ph+ps);
2281			ctx.lineTo(pw+iw,ph+ps+ps);
2282			ctx.lineTo(pw+iw+ps,ph+ps);
2283			ctx.closePath();
2284			ctx.fill();
2285			B2T = ctx.createLinearGradient(pw+iw,ph+ps+ps,pw+iw+ps,ph+ps+ps);
2286			B2T.addColorStop(0, 'rgba(0,0,0,0.35)');
2287			B2T.addColorStop(1, 'rgba(0,0,0,0.0)');
2288	  		ctx.fillStyle = B2T;
2289			ctx.beginPath();
2290	  		ctx.moveTo(pw+iw,ph+ps+ps);
2291			ctx.lineTo(pw+iw,ph+ih);
2292			ctx.lineTo(pw+iw+ps,ph+ih+ps);
2293			ctx.lineTo(pw+iw+ps,ph+ps);
2294			ctx.closePath();
2295			ctx.fill();
2296		}
2297		ctx.lineCap = "butt";
2298		ctx.lineWidth = lw/2;
2299		ctx.strokeStyle = "rgba(255,255,255,0.25)";
2300		if(canvas_nofill <= 0) {
2301  			ctx.fillStyle = "rgba(240,240,240,0.8)";
2302			ctx.strokeStyle = "rgba(255,255,255,1)";
2303			ctx.fillRect(pw,ph,iw,ih);
2304		}
2305		for (var i = 0; i < ChartData[0].length-1; i++) {
2306		  	ctx.beginPath();
2307  			ctx.moveTo(pw+(i*dw),ph);
2308			ctx.lineTo(pw+(i*dw),ph+ih);
2309			ctx.stroke();
2310		}
2311		for (var i = 1; i < ChartData[0].length; i++) {
2312		  	ctx.beginPath();
2313  			ctx.moveTo(pw,ph+(i*dh));
2314			ctx.lineTo(pw+iw,ph+(i*dh));
2315			ctx.stroke();
2316		}
2317		ctx.lineWidth = lw;
2318		var cc = ""; var bh = 0; var idx = 0; var t = 0;
2319		for (var i = 0; i < ChartData.length; i++) {
2320			for (var j = 0; j < ChartData[i].length; j++) {
2321				t = Math.max(t,ChartData[i][j]);
2322			}
2323			bh = t*hf; cc = colorSlice[(idx++)];
2324			drawLine(ctx,pw,ph+ih-bh,bw,bh,dw,ChartData[i],hf,cc,canvas_nofill);
2325		}
2326  		ctx.beginPath();
2327  		ctx.moveTo(pw,ph);
2328		ctx.lineTo(pw,ph+ih);
2329		ctx.lineTo(pw+iw+(lw/2),ph+ih);
2330		ctx.strokeStyle = "rgba(48,48,48,1)";
2331		ctx.stroke();
2332		ctx.lineWidth = lw/2;
2333		B2T = ctx.createLinearGradient(pw,ph+ih,pw,ph+ih+ps);
2334		B2T.addColorStop(0, 'rgba(0,0,0,1)');
2335		B2T.addColorStop(0.5, 'rgba(0,0,0,1)');
2336		B2T.addColorStop(1, 'rgba(0,0,0,0)');
2337  		ctx.strokeStyle = B2T;
2338		for (var i = 0; i < ChartData[0].length; i++) {
2339  			ctx.beginPath();
2340  			ctx.moveTo(pw+(i*dw),ph+ih);
2341			ctx.lineTo(pw+(i*dw),ph+ih+ps);
2342			ctx.stroke();
2343		}
2344		B2T = ctx.createLinearGradient(pw-ps,ph,pw,ph);
2345		B2T.addColorStop(0, 'rgba(0,0,0,0)');
2346		B2T.addColorStop(0.5, 'rgba(0,0,0,1)');
2347		B2T.addColorStop(1, 'rgba(0,0,0,1)');
2348  		ctx.strokeStyle = B2T;
2349  		for (var i = 1; i < ChartData[0].length; i++) {
2350  			ctx.beginPath();
2351  			ctx.moveTo(pw-ps,ph+(i*dh));
2352			ctx.lineTo(pw,ph+(i*dh));
2353			ctx.stroke();
2354		}
2355	}
2356}
2357function generateCanvas() {
2358	if(canvasSupport) {
2359		var canvasID; var tdataID; var textID;
2360		var tmp; var dat; var i; var j;
2361		for(i=0; i < piecharts.length; i++) {
2362			tmp = piecharts[i].id.split("_");
2363			tdataID = piecharts[i].id;
2364			canvasID = tmp[0] + "_canvas";
2365			textID = tmp[0] + "_text";
2366			if(document.getElementById(tdataID)) {
2367				get_input(tdataID,canvasID);
2368				if(colorSlice.length > 0) {
2369					j = 0; dat = ""; for(dat in ChartData) {j++; }
2370					if(j > 0 && j == colorSlice.length) {
2371						setPieChart(canvasID,textID);
2372					}
2373				}
2374			}
2375		}
2376		for(i=0; i < barcharts.length; i++) {
2377			tmp = barcharts[i].id.split("_");
2378			tdataID = barcharts[i].id;
2379			canvasID = tmp[0] + "_canvas";
2380			textID = tmp[0] + "_text";
2381			if(document.getElementById(tdataID)) {
2382				get_input(tdataID,canvasID);
2383				if(colorSlice.length > 0) {
2384					j = 0; dat = ""; for(dat in ChartData) {j++; }
2385					if(j > 0 && j == colorSlice.length) {
2386						setBarChart(canvasID,textID);
2387					}
2388				}
2389			}
2390		}
2391		for(i=0; i < linecharts.length; i++) {
2392			tmp = linecharts[i].id.split("_");
2393			tdataID = linecharts[i].id;
2394			canvasID = tmp[0] + "_canvas";
2395			textID = tmp[0] + "_text";
2396			if(document.getElementById(tdataID)) {
2397				get_input(tdataID,canvasID,true);
2398				if(colorSlice.length > 0) {
2399					if(ChartData.length == colorSlice.length) {
2400						setLineChart(canvasID,textID);
2401					}
2402				}
2403			}
2404		}
2405	}
2406}
2407// canvas chart extension
2408
2409// invisible select extension
2410function setListPos(opt) {
2411	if(!isIE) { //(degrade IE)
2412		var ref = document.getElementById('list');
2413		var x = findPosX(ref); var y = findPosY(ref);
2414		var obj = document.getElementById('jumplist');
2415		obj.style.position = 'fixed'; obj.style.left = x + 'px'; obj.style.top = y + 'px';
2416		var vol = document.getElementById('volumelist');
2417		ref = document.getElementById('volume');
2418		x = findPosX(ref); if(isOp) {y = window.innerHeight-imgHeight; }else {y = findPosY(ref);}
2419		vol.style.position = 'fixed'; vol.style.left = x + 'px'; vol.style.top = y + 'px';
2420		var del = document.getElementById('delaylist');
2421		ref = document.getElementById('delay');
2422		x = findPosX(ref); if(isOp) {y = window.innerHeight-imgHeight; }else {y = findPosY(ref);}
2423		del.style.position = 'fixed'; del.style.left = x + 'px'; del.style.top = y + 'px';
2424		var pnl = document.getElementById('navLinks');
2425	}
2426	if(opt) {
2427		if(isIE) {
2428			//(degrade IE)
2429			//pnl.style.filter = "alpha(opacity=80)";
2430		}else {
2431			obj.style.opacity = 0.0;
2432			vol.style.opacity = 0.0;
2433			del.style.opacity = 0.0;
2434			pnl.style.opacity = 0.8;
2435		}
2436	}
2437}
2438// invisible select extension
2439
2440// transition extension
2441function switchFade() {
2442	if(tranSitions && s5mode && fadeModus) {
2443		fadeModus = false;
2444		playDelay = playDelay-(2*fadeDuration);
2445		var obj = document.getElementById('fade'); changeClass(obj,'isoff');
2446	}else if(tranSitions && s5mode && !fadeModus) {
2447		fadeModus = true;
2448		playDelay = playDelay+(2*fadeDuration);
2449		var obj = document.getElementById('fade'); changeClass(obj,'ison');
2450	}
2451	currentSlide();
2452}
2453function opacity(ids, opacStart, opacEnd, millisec) {
2454	var speed = Math.round(millisec / 100);
2455	var timer = 0;
2456	if(opacStart > opacEnd) {
2457		for(var i = opacStart; i >= opacEnd; i--) {
2458			window.setTimeout("changeOpac(" + i + ",'" + ids + "')",(timer * speed));
2459			timer++;
2460		}
2461	} else if(opacStart < opacEnd) {
2462		for(var i = opacStart; i <= opacEnd; i++) {
2463			window.setTimeout("changeOpac(" + i + ",'" + ids + "')",(timer * speed));
2464			timer++;
2465		}
2466	}
2467}
2468function changeOpac(opacity, ids) {
2469	var obj = document.getElementById(ids);
2470	if (isIE) {
2471		obj.style.filter = "alpha(opacity=" + opacity + ")";
2472	} else {
2473		obj.style.opacity = (opacity / 100);
2474	}
2475}
2476function shiftOpacity(ids, millisec) {
2477	if(document.getElementById(ids).style.opacity != '') {
2478		var currentOpac = document.getElementById(ids).style.opacity * 100;
2479	} else {
2480		var currentOpac = 0;
2481	}
2482	if(currentOpac == 0) {
2483		opacity(ids, currentOpac, 100, millisec);
2484	} else if(currentOpac > 0) {
2485		opacity(ids, currentOpac, 0, millisec);
2486	}
2487}
2488// transition extension
2489
2490// autoplay extension
2491function autoPlay() {
2492	if (s5mode && autoMatic && !playPause) {
2493		if ((snum >= (smax-1)) && playLoop) {
2494			goTo(0);
2495			autoRun = setTimeout('autoPlay();',playDelay);
2496		}else if ((snum >= (smax-1)) && !playLoop) {
2497			stopPlay();
2498		}else {
2499			if (!incrementals[snum] || incpos >= incrementals[snum].length) {
2500				go(1);
2501				if (incrementals[snum].length >0) {
2502					clearTimeout(autoRun); autoRun = null;
2503					incrDelay = parseInt(playDelay/(incrementals[snum].length+1));
2504					remainDer = parseInt(playDelay-(incrDelay*incrementals[snum].length));
2505					autoRun = setTimeout('autoPlayIncr()',incrDelay);
2506				}
2507			} else {
2508				clearTimeout(autoRun); autoRun = null;
2509				incrDelay = incrDuration;
2510				remainDer = parseInt(playDelay-(incrementals[snum].length*incrDuration));
2511				autoRun = setTimeout('autoPlayIncr()',incrDelay);
2512			}
2513			autoRun = setTimeout('autoPlay();',playDelay);
2514		}
2515	}
2516}
2517function autoPlayIncr() {
2518	if (incpos < incrementals[snum].length) {
2519		subgo(1);
2520		autoRun = setTimeout('autoPlayIncr();',incrDelay);
2521	}else {
2522		autoRun = setTimeout('nop();',remainDer);
2523	}
2524}
2525function nop() {
2526	// no operation dummy
2527}
2528function togglePlay() {
2529	if (autoRun && s5mode) {
2530		stopPlay();
2531	}else if (!autoRun && s5mode) {
2532		startPlay();
2533	}
2534}
2535function stopPlay() {
2536	if (autoRun && s5mode) {
2537		clearTimeout(autoRun); autoRun = null;
2538		autoMatic = false; playPause = false; var obj = '';
2539		obj = document.getElementById('auto'); changeClass(obj,'isoff');
2540		obj = document.getElementById('pause'); changeClass(obj,'isoff');
2541		currentSlide();
2542	}
2543}
2544function startPlay() {
2545	if (!autoRun && s5mode) {
2546		playPause = false; autoMatic = true; var obj = '';
2547		obj = document.getElementById('auto'); changeClass(obj,'ison');
2548		obj = document.getElementById('pause'); changeClass(obj,'isoff');
2549		autoRun = setTimeout('autoPlay();',playDelay);
2550		currentSlide();
2551	}
2552}
2553function pausePlay() {
2554	if (s5mode && autoMatic) {
2555		if (playPause) {
2556			playPause = false; autoRun = setTimeout('autoPlay();',playDelay);
2557			var obj = document.getElementById('pause'); changeClass(obj,'isoff');
2558		}else {
2559			if (autoRun){
2560				clearTimeout(autoRun); autoRun = null; playPause = true;
2561				var obj = document.getElementById('pause'); changeClass(obj,'ison');
2562			}
2563		}
2564		currentSlide();
2565	}
2566}
2567function switchLoop() {
2568	if(s5mode) {
2569		if (playLoop) {
2570			playLoop = false;
2571			var obj = document.getElementById('loop'); changeClass(obj,'isoff');
2572		}else {
2573			playLoop = true;
2574			var obj = document.getElementById('loop'); changeClass(obj,'ison');
2575		}
2576	}
2577	currentSlide();
2578}
2579function setDelay() {
2580	var val = document.getElementById('delaylist');
2581	if(s5mode) {
2582		var delay = Math.max(5,Math.min(parseInt(val.value),300));
2583		playDelay = (fadeModus == true) ? ((delay*1000)+(2*fadeDuration)) : (delay*1000);
2584	}
2585}
2586// autoplay extension
2587
2588// audio extension
2589function createSoundManagerScript() {
2590	if(typeof soundManager=="undefined") {
2591		onerrorSM2();
2592	}else {
2593		var script=document.createElement('SCRIPT');
2594		var tx=document.createTextNode("soundManager.createMovie();");
2595		script.appendChild(tx);
2596		document.getElementsByTagName("body")[0].appendChild(script);
2597	}
2598}
2599//soundManager.onload = function() {
2600function onloadSM2() {
2601	if(!isIE) { //(degrade IE)
2602		swfUnloaded = false;
2603		preloadSounds();
2604	}
2605}
2606//soundManager.onerror = function() {
2607function onerrorSM2() {
2608	if(typeof soundManager!="undefined") {
2609		soundManager.destruct;
2610		delete soundManager;
2611	}
2612	audioSupport = false; swfUnloaded = true;
2613//	if(audioError && !isIE && !isOp) {
2614//		var dv = document.createElement('div'); dv.id = "guru";
2615//		var d2=document.createElement('div'); dv.appendChild(d2);
2616//		var tx=document.createTextNode('Guru Meditation - SoundManager failed to load/initialize!');
2617//		d2.appendChild(tx);	document.getElementById('slide0').appendChild(dv);
2618//	}
2619}
2620function audioSetup() {
2621	if(sound[0]) {
2622		playSound(0);
2623	}else if(sound[bgSoundItem] && !sound[0]) {
2624		playSound(bgSoundItem);
2625	}
2626}
2627function fadeoutSound(ids, option) {
2628	if(curSoundID >= 0  && !swfUnloaded) {
2629		if(isNaN(ids)) {
2630			if(ids == "bgSound") {
2631				var cnum = parseInt(bgSoundItem);
2632			}else {
2633				for (var i = 0; i < (sound.length); i++) {
2634					if(sound[i] && ids == sound[i]["id"]) {
2635						var cnum = i;
2636						break;
2637					}
2638				}
2639			}
2640		}else {
2641			var cnum = ids;
2642			ids = sound[cnum]["id"];
2643		}
2644		var vol = getMaxVolume(sound[cnum]["volume"]);
2645		var millisec = fadeDuration;
2646		var speed = Math.round(millisec / vol);
2647		var timer = 0;
2648		for(var i = vol; i > 0; i--) {
2649			setTimeout("fadeout(" + i + ",'" + ids + "')",(timer * speed));
2650			timer++;
2651		}
2652		if(option) setTimeout("stopSound('"+ids+"')",millisec);
2653	}
2654}
2655function fadeout(volume, id) {
2656	soundManager.setVolume(id,volume);
2657}
2658function stopSound(ids) {
2659	var sid;
2660	if(isNaN(ids)) {
2661		sid = ids;
2662	}else if(sound[ids]) {
2663		sid = sound[ids]["id"];
2664	}
2665	if(sid!='' && curSoundID >= 0) {
2666		soundManager.stop(sid);
2667		curSoundID = -1;
2668	}
2669}
2670function toggleSounds() {
2671	if(audioSupport && !swfUnloaded) {
2672		stopAllSounds();
2673	}else if (!audioSupport && !swfUnloaded) {
2674		allowSounds();
2675	}
2676}
2677function allowSounds() {
2678	if(!swfUnloaded) {
2679		audioSupport = true;
2680		var obj = document.getElementById('audio'); changeClass(obj,'ison');
2681		currentSlide();
2682	}
2683}
2684function stopAllSounds() {
2685	if(curSoundID >= 0) {
2686		stopSound(curSoundID);
2687	}else {
2688		soundManager.stopAll();
2689		curSoundID = -1;
2690	}
2691	audioSupport = false;
2692	var obj = document.getElementById('audio'); changeClass(obj,'isoff');
2693	currentSlide();
2694}
2695function playSound(id) {
2696	if(audioSupport && !swfUnloaded) {
2697		var url, sid, vol, lps, cnum;
2698		if(isNaN(id)) {
2699			sid = id;
2700			if(sid == "bgSound") {
2701				cnum = parseInt(bgSoundItem);
2702			}else {
2703				cnum = getSoundID(id);
2704			}
2705		}else {
2706			cnum = parseInt(id);
2707			if(sound[cnum]) sid = sound[cnum]["id"];
2708		}
2709		if(sound[cnum] && sound[cnum]["url"]!='' && sid!=''){
2710			url = sound[cnum]["url"];
2711			vol = (sound[cnum]["volume"]!='')?getMaxVolume(sound[cnum]["volume"]):getMaxVolume(100);
2712			lps = (sound[cnum]["loops"])?true:false;
2713			if(lps) {
2714				soundManager.play(sid,{volume:vol,onplay:function(){curSoundID=cnum;},onfinish:function(){soundManager.play(sid,{volume:getMaxVolume(sound[cnum]["volume"])});}});
2715			}else {
2716				soundManager.play(sid,{volume:vol,onplay:function(){curSoundID=cnum;},onfinish:function(){curSoundID=-1;}});
2717			}
2718		}
2719	}
2720}
2721function getSoundID(str) {
2722	for (var i = 0; i < (sound.length); i++) {
2723		if(sound[i] && str == sound[i]["id"]) {
2724			var id = i;
2725			break;
2726		}
2727	}
2728	return id;
2729}
2730function setVolume() {
2731	var vol = document.getElementById('volumelist');
2732	if(audioSupport && !swfUnloaded) {
2733		audioVolume = parseInt(vol.value);
2734		if(curSoundID >= 0) {
2735			if(sound[curSoundID]) {
2736				var sid = sound[curSoundID]["id"];
2737				var vid = getMaxVolume(sound[curSoundID]["volume"]);
2738				soundManager.setVolume(sid,vid);
2739			}
2740		}
2741	}
2742}
2743function getMaxVolume(value) {
2744	if(audioVolume>0) {var factor = audioVolume/100;}else {var factor = 0;}
2745	return Math.max(0,Math.min(parseInt(value*factor),audioVolume));
2746}
2747function preloadSounds() {
2748	var temp = ''; var parm = ''; var t = ''; var cl = '';
2749	var objects = document.getElementsByTagName('object');
2750	for (var i=0; i < objects.length; i++) {
2751		if(objects[i].type.toLowerCase() == 'audio/mp3' && objects[i].data != '') {
2752			objects[i].width = 0; objects[i].height = 0;
2753			if(objects[i].parentNode.tagName == 'DIV') {
2754				cl = objects[i].parentNode.className.toLowerCase();
2755				if(cl == 'presentation' || cl == 'slide') {
2756					if(cl == 'presentation') {
2757						t = parseInt(bgSoundItem);
2758					}else {
2759						t = parseInt(objects[i].parentNode.id.slice(5, objects[i].parentNode.id.length));
2760					}
2761					sound[t] = new Object();
2762					if(t < bgSoundItem) {
2763						sound[t]["id"] = objects[i].parentNode.id;
2764					}else {
2765						sound[t]["id"] = "bgSound";
2766					}
2767					sound[t]["url"] = objects[i].data;
2768					sound[t]["volume"] = 100; sound[t]["loops"] = false;
2769					if(objects[i].archive != '') {
2770						parm = objects[i].archive.toLowerCase().split(',');
2771						for (var j=0; j < parm.length; j++) {
2772							if(parm[j] == 'loop') sound[t]["loops"] = true;
2773							if(parm[j].search(/^volume/) != -1) {
2774								var tmp = parm[j].split(':');
2775								sound[t]["volume"] = parseInt(tmp[1]);
2776							}
2777						}
2778					}
2779					soundManager.createSound(sound[t]["id"],sound[t]["url"]);
2780				}
2781			}
2782		}
2783	}
2784}
2785// audio extension
2786
2787// help extension
2788function createHelpReq() {
2789	if(!document.getElementById("HelpReq")) {
2790		var obj = document.getElementsByTagName("body")[0].firstChild;
2791		var pg = document.createElement('div');
2792		pg.id = "HelpReq";
2793		if (pg.addEventListener) {
2794			pg.addEventListener("onclick",dumpHelpReq,false);
2795		} else if (pg.attachEvent) {
2796			pg.attachEvent("onclick",dumpHelpReq);
2797		}
2798		pg.style.position = 'absolute';
2799		pg.style.left = 0 + 'px';
2800		pg.style.top = 0 + 'px';
2801		pg.style.width = 100 + '%';
2802		pg.style.height = 100 + '%';
2803		pg.style.margin = 0 + 'px';
2804		pg.style.padding = 0 + 'px';
2805		if (isIE) {
2806			pg.style.filter = "alpha(opacity=90)";
2807		} else {
2808			pg.style.opacity = 0.9;
2809		}
2810		pg.style.zIndex = 9999;
2811		pg.style.backgroundColor="rgb(64,64,64)";
2812		pg.style.textAlign = "center";
2813		pg.style.verticalAlign = "middle";
2814		pg.style.backgroundPosition="center center";
2815		pg.style.backgroundRepeat="no-repeat";
2816		pg.style.backgroundImage="url("+s5Path+"ui/graphic_support/help.jpg)";
2817		document.getElementsByTagName("body")[0].insertBefore(pg,obj);
2818		if(document.getElementById("HelpReq")) {
2819			helpmode = true;
2820		}
2821	}
2822}
2823function dumpHelpReq() {
2824	if(document.getElementById("HelpReq")) {
2825		document.body.removeChild(document.getElementById('HelpReq'));
2826		helpmode = false;
2827	}
2828}
2829// help extension
2830
2831//DEBUG
2832function ConsoleLog(value) {
2833	if(window.console) {
2834		window.console.log(value);
2835	}
2836}
2837//DEBUG
2838
2839document.write('<style type="text/css" media="screen" id="blockStyle">.presentation, .layout {display: none; }</style>');
2840
2841if(!isIE && !isOp) {
2842	document.write('<script type="text/javascript" src="'+s5Path+'ui/audio_support/soundmanager2.js"></script>');
2843	if(typeof soundManager!="undefined") {
2844		var allMetas = document.getElementsByTagName('meta');
2845		for (var i = 0; i< allMetas.length; i++) {
2846			if (allMetas[i].name == 'audioDebug') {
2847				var audioDebug = (allMetas[i].content == "true") ? true : false;
2848				soundManager.defaultOptions.debugMode = audioDebug;
2849			}
2850		}
2851	}
2852}
2853
2854window.onload = createSlideShow;
2855window.onresize = function(){setTimeout('windowChange()',5);}