
	function updateDisplay() {

		var canvas = document.getElementById('litebox');

		if (canvas.getContext){

			var timeStamp = new Date();
			var context = canvas.getContext('2d');
			context.clearRect(0,0,600,600);
			
			try {

				context.save();
					
					for (p=0;p<photos.length;p++) {
					
						if (photos[p].photo.loaded == true) {

							w = photos[p].photo.width;
							h = photos[p].photo.height;

							context.save();

								context.translate(photos[p].xCoord, photos[p].yCoord);

								context.scale(photos[p].scale,photos[p].scale);

								if (photos[p].highlight) {
									context.lineWidth = 1;
									context.strokeStyle = "#000000";
									context.globalAlpha = 0.2;
								} else {
									context.lineWidth = 32;
									context.strokeStyle = "#FF0000";
									context.globalAlpha = 0.8;
								}

								context.beginPath();
								context.arc(0,0,photos[p].photo.deltaRadius,(Math.PI/180)*0,(Math.PI/180)*360,false);
								context.stroke();
								
								if (photos[p].highlight==false) {
								
									context.lineWidth = 10;
									context.strokeStyle = "#FF4444";
									context.globalAlpha = 0.5;
									
									context.beginPath();
									context.arc(0,0,photos[p].photo.deltaRadius-21,(Math.PI/180)*0,(Math.PI/180)*(360*photos[p].alpha),false);
									context.stroke();
								}

								context.globalAlpha = photos[p].alpha;

								context.rotate((Math.PI/180)*photos[p].angle);
								context.translate(-(w/2),-(h/2));
								context.drawImage(photos[p].photo,0,0);

							context.restore();

						}

					}

				context.restore();

			} catch (e) {

				alert('Failed to draw photos '+e.message);
			
			}

			try {

				if (buttons.loaded) {
					context.save();
					context.drawImage(buttons,0,470);
					context.restore();
				}

			} catch (e) {
			
				alert('Failed to draw litebox buttons '+e.message);
			
			}

			try {

				context.save();

					sm.renderString(context,10,6,'Photos loaded: '+photos.length.toString(),'l');
					sm.renderString(context,300,6,'"'+photos[photoSelected].photo.src+'"','c');
					sm.renderString(context,590,6,timeStamp.getDate()+'/'+(1+timeStamp.getMonth())+'/'+timeStamp.getFullYear()+' '+timeStamp.getHours()+':'+((timeStamp.getMinutes()<10)?'0'+timeStamp.getMinutes():timeStamp.getMinutes()),'r');

				context.restore();

			} catch (e) {
			
				alert('Failed to draw text '+e.message);
			
			}

		}

	}

	function Font(fontFile,fontWidth,fontHeight,fontPadding,fontSpacing) {
	
		this.fontFile    = fontFile;
		this.fontWidth   = fontWidth;
		this.fontHeight  = fontHeight;
		this.fontPadding = fontPadding;
		this.fontSpacing = fontSpacing;

		this.charPosStr = 'abcdefghijklmnopqrstuvwxyz0123456789;:.\'"/\\@$?+- ';

		try {
			this.fontImage = new Image();
			this.fontImage.src = this.fontFile;
		} catch (e) {
			logTA.value = 'Loading font: '+fontFile+' - Failed\n'+logTA.value;
		}
		
		this.renderString = fontRenderString;

	}
	
	function fontRenderString(context,x,y,s,align) {
	
		var alignOffset, charPos, xOffset;
		var c = 0;

		switch (align) {
			case 'l':
				var alignOffset = 0;
				break;
			case 'r':
				var alignOffset = ((s.length)*(this.fontWidth+this.fontSpacing));
				break;
			case 'c':
				var alignOffset = Math.round(((s.length)*(this.fontWidth+this.fontSpacing))/2);
				break;
		}

		for (c=0;c<s.length;c++) {
			
			try {
				if (s.charAt(c)!=' ') { //Opera won't do charAt() on a space. Whack.
					charPos = this.charPosStr.indexOf(s.charAt(c).toLowerCase());
					xOffset = (c*(this.fontWidth+this.fontSpacing));
					context.drawImage(this.fontImage,(charPos*(this.fontWidth+this.fontPadding)),0,this.fontWidth,this.fontHeight,x-alignOffset+xOffset,y,this.fontWidth,this.fontHeight);
				}

			} catch (e) {

			}
		}
	
	}
	