var	ie = true;
var	sbwidth = 20;

var	speed_slowest = 10;
var	speed_slow = 25;
var	speed_normal = 50;
var	speed_fast = 75;
var	speed_fastest = 100;

var	frame_slowest = 2000;
var	frame_slow = 1000;
var	frame_normal = 500;
var	frame_fast = 250;
var	frame_fastest = 100;

if	(navigator.appName.indexOf('Microsoft') == -1)
{
	ie = false;
	sbwidth = 16;
}

function
script_run(name)
{
	var	code = 'script_' + name + '()';
	eval(code);
}
function
cleanup()
{
	clear_audio();
}
function
pagesize()
{
	trademark();
}
var	_menu = null;

var	_imagelist = new Array();
var	_imagemap = new Array();
var	_badimages = new Array();

var	_players = new Array();
var	_playerInterval = null;

function
check_players()
{
	var	player;
	var	count;
	var	i;

	for (i = count = 0; i < _players.length; i++)
	{
		player = _players[i];

		if (player.style.visibility == 'visible')
		{
			if (player.playState == 1)
			{
				if (player._frame != null)
				{
					clear_frame(player._frame);
				}
			}
			else
			{
				count++;
			}
		}
	}
	if (count == 0)
	{
		clearInterval(_playerInterval);
		_playerInterval = null;
	}
}

var	transitions = new Array();
var	durations = new Array();
var	clears = new Array();

function
filter_handler()
{
	if (this._player != null)
	{
		this._player.url = this._url;
		this._player.controls.play();
	}

	this._url = null;
	this._player = null;
}

function
Point(x,y)
{
	this._x = x;
	this._y = y;
}
function
Rectangle()
{
	this._left = 0;
	this._top = 0;
	this._right = 0;
	this._bottom = 0;
	this.getWidth = Rectangle_getWidth;
	this.getHeight = Rectangle_getHeight;
	this.getCenter = Rectangle_getCenter;
	this.center = Rectangle_center;
	this.offset = Rectangle_offset;
	this.scale = Rectangle_scale;
	this.copy = Rectangle_copy;
	this.set = Rectangle_set;
	this.move = Rectangle_move;
	this.toString = Rectangle_toString;
}

function
Rectangle_getWidth()
{
	return(parseInt(this._right - this._left));
}

function
Rectangle_getHeight()
{
	return(parseInt(this._bottom - this._top));
}

function
Rectangle_getCenter()
{
	var	x = this._left + (this.getWidth() / 2);
	var	y = this._top + (this.getHeight() / 2);
	return(new Point(x,y));
}

function
Rectangle_center(r)
{
	var	center = this.getCenter();
	var	w = r.getWidth();
	var	h = r.getHeight();

	var	rect = new Rectangle();

	rect._left = parseInt(center._x - (w / 2));
	rect._right = parseInt(center._x + (w / 2));
	rect._top = parseInt(center._y - (h / 2));
	rect._bottom = parseInt(center._y + (h / 2));

	return(rect);
}

function
Rectangle_set(x,y,width,height)
{
	this._left = parseInt(x);
	this._right = parseInt(x + width);
	this._top = parseInt(y);
	this._bottom = parseInt(y + height);
}

function
Rectangle_move(x,y)
{
	var	width = this.getWidth();
	var	height = this.getHeight();
	this._left = x;
	this._right = parseInt(x + width);
	this._top = y;
	this._bottom = parseInt(y + height);
}

function
Rectangle_offset(x,y)
{
	this._left -= parseInt(x);
	this._right -= parseInt(x);
	this._top -= parseInt(y);
	this._bottom -= parseInt(y);
}

function
Rectangle_copy()
{
	var	rect = new Rectangle();

	rect._left = this._left;
	rect._top = this._top;
	rect._right = this._right;
	rect._bottom = this._bottom;

	return(rect);
}

function
Rectangle_scale(ratio)
{
	this._left *= ratio;
	this._top *= ratio;
	this._right *= ratio;
	this._bottom *= ratio;
}

function
Rectangle_toString()
{
	var	s = "";

	s += "left=" + this._left;
	s += ",top=" + this._top;
	s += ",right=" + this._right;
	s += ",bottom=" + this._bottom;
	s += ",width=" + this.getWidth();
	s += ",height=" + this.getHeight();

	return(s);
}
function
hand()
{
	document.body.style.cursor = 'pointer';
}
function
pointer()
{
	document.body.style.cursor = '';
}

function
trademark()
{
	var	tm = document.getElementById('tm');
	var	width = tm.offsetWidth;

	tm.style.left = document.body.scrollLeft + document.body.clientWidth - tm.offsetWidth;
	tm.style.top = document.body.scrollTop + document.body.clientHeight - tm.offsetHeight;
	tm.style.width = width;
}

function
clicked()
{
	if (_menu != null)
	{
		_menu._clicks++;
	}
	clear_menus(false);
}
function
getBounds(id)
{
	var	rect = new Rectangle();
	var	pic = document.getElementById('page_div');

	if (pic == null)
	{
		return(rect);
	}

	var	object = document.getElementById(id);

	if (object == null)
	{
		return(rect);
	}

	if (object.tagName.toLowerCase() == 'area')
	{
		var	idx;
		var	num;
		var	s;
		var	x;
		var	y;
		var	done = false;
		var	start = 0;
		var	minX = 0;
		var	minY = 0;
		var	maxX = 0;
		var	maxY = 0;

		while (done == false)
		{
			if ((idx = object.coords.indexOf(',',start)) == -1)
			{
				break;
			}

			s = object.coords.substring(start,idx);
			x = parseInt(s);
			start = idx + 1;

			if ((idx = object.coords.indexOf(',',start)) == -1)
			{
				s = object.coords.substring(start);
				done = true;
			}
			else
			{
				s = object.coords.substring(start,idx);
			}

			y = parseInt(s);
			start = idx + 1;

			if (minX == 0 || x < minX)
			{
				minX = x;
			}

			if (minY == 0 || y < minY)
			{
				minY = y;
			}

			if (x > maxX)
			{
				maxX = x;
			}

			if (y > maxY)
			{
				maxY = y;
			}
		}

		rect._left = minX;
		rect._top = minY;
		rect._right = minX + (maxX - minX);
		rect._bottom = minY + (maxY - minY);
	}
	else
	{
		rect._left = parseInt(object.style.left);
		rect._top = parseInt(object.style.top);
		rect._right = rect._left + object.offsetWidth;
		rect._bottom = rect._top + object.offsetHeight;
	}

	return(rect);
}

function
scrollhandler()
{
	trademark();
}

function
clear_frame(frame)
{

	var	container = document.getElementById(frame);

	if (container != null)
	{
		if (container._slideshow != null)
		{
			container._slideshow.destroy();
		}
	}


	var	iframe;
	var	div;

	if ((iframe = document.getElementById(frame + '-iframe')) != null)
	{
		iframe.src = '';
		iframe.style.display = 'none';
	}

	if ((div = document.getElementById(frame + '-video-div')) != null)
	{
		div.style.visibility = 'hidden';

		var	player = document.getElementById(frame + '-video');

		if (player != null)
		{
			player.style.visibility = 'hidden';
			player.controls.stop();
		}
	}

	if ((div = document.getElementById(frame + '-image-link-div')) != null)
	{
		div.style.display = 'none';
	}

	if ((div = document.getElementById(frame + '-image-div')) != null)
	{
		div.style.display = 'none';
	}

	clear_menus(false);
}
function
show_page(frame,url,audio,ratio)
{
	if (frame == '_self')
	{
		if (audio != null)
		{
			play_audio(null,audio,null,null,1);
		}
		window.location.href = url;
		return;
	}
	else if (frame == '_blank')
	{
		if (audio != null)
		{
			play_audio(null,audio,null,null,1);
		}
		window.open(url);
		return;
	}

	var	bounds = getBounds(frame);

	var	iframe = document.getElementById(frame + '-iframe');

	if (iframe != null && clears[1])
	{
		clear_frame(frame);
	}

	var	div = document.getElementById(frame);
	if (ie)
	{
		div.style.filter = transitions[1];
		if (div.style.filter.length > 0)
		{
			div.filters[0].apply();
		}
	}
	if (iframe != null && clears[1] == false)
	{
		clear_frame(frame);
	}

	var	center = bounds.getCenter();

	if (iframe != null)
	{
		var	w = bounds.getWidth() * (ratio / 100);
		var	h = bounds.getHeight() * (ratio / 100);
		var	rect = new Rectangle();

		rect._left = center._x - (w / 2);
		rect._right = center._x + (w / 2) - frameBw * 2;
		rect._top = center._y - (h / 2);
		rect._bottom = center._y + (h / 2) - frameBw * 2;

		rect.offset(bounds._left,bounds._top);

		iframe._container = div;
		iframe.style.left = rect._left;
		iframe.style.top = rect._top;
		iframe.style.width = rect.getWidth();
		iframe.style.height = rect.getHeight();
		iframe.style.display = 'block';
		iframe.src = url;

		if (audio != null)
		{
			play_audio(null,audio,null,null,1);
		}

	}
	else
	{
		if (audio != null)
		{
			play_audio(null,audio,null,null,1);
		}
		window.open(url);
	}

	clear_menus(false);
}

function
frame_loaded(frame)
{
	if (ie && frame._container != null && frame._container.style.filter.length > 0)
	{
		frame._container.filters[0].play(durations[1]);
	}
}

function
descendant(element,tag)
{
	var	descendants = element.getElementsByTagName(tag);

	if (descendants.length == 0)
	{
		return(null);
	}

	return(descendants.item(0));
}

function
getImageRect(url,bounds,ratio,aspect)
{
	var	rect = new Rectangle();
	var	image = getImage(url);
	var	imagerect = new Rectangle();
	imagerect.set(0,0,image.width,image.height);
	var	center = bounds.getCenter();
	var	w;
	var	h;

	if (ratio == 0)
	{
		w = imagerect.getWidth();
		h = imagerect.getHeight();
	}
	else
	{
		w = bounds.getWidth() * (ratio / 100);
		h = bounds.getHeight() * (ratio / 100);
	}

	rect._left = center._x - (w / 2);
	rect._right = center._x + (w / 2);
	rect._top = center._y - (h / 2);
	rect._bottom = center._y + (h / 2);

	if (aspect)
	{
		w = imagerect.getWidth();
		h = imagerect.getHeight();

		var	num;

		if (w >= h)
		{
			num = rect._top + (rect.getWidth() * (h / w));

			if (num > rect._bottom)
			{
				rect._right = rect._left + (rect.getHeight() * (w / h));
			}
			else
			{
				rect._bottom = num;
			}
		}
		else
		{
			num = rect._left + (rect.getHeight() * (w / h));

			if (num > rect._right)
			{
				rect._bottom = rect._top + (rect.getWidth() * (h / w));
			}
			else
			{
				rect._right = num;
			}
		}

		rect = bounds.center(rect);
		rect.offset(bounds._left,bounds._top);
	}
	else
	{
		rect.offset(bounds._left,bounds._top);
	}

	return(rect);
}

function
getContentKey(url)
{
	var	key = url;
	var	idx;

	if ((idx = url.indexOf('files/')) != -1)
	{
		key = url.substring(idx);
	}
	else if ((idx = url.indexOf('custom/')) != -1)
	{
		key = url.substring(idx);
	}

	return(key);
}

function
getImage(url)
{
	var	image = _imagemap[url];

	if (image == null)
	{
		image = new Image();
		image.src = url;
		var	key = getContentKey(url);
		_imagemap[key] = image;
	}

	return(image);
}

function
image_loaded(image)
{
	image.error = false;

	var	total = 0;
	var	loaded = 0;
	var	errors = 0;
	var	i;

	for (i = 0; i < _imagelist.length; i++, total++)
	{
		if (_imagelist[i] == image)
		{
			loaded++;
		}
		else if (_imagelist[i].complete)
		{
			loaded++;
		}
		else if (_imagelist[i].error)
		{
			errors++;
			loaded++;
		}
	}

	var	status = "";

	if (loaded < total)
	{
		status += loaded;
		status += " out of ";
		status += total;
		status += " images loaded";

		if (errors > 0)
		{
			status += " with";
			status += errors;

			if (errors > 1)
			{
				status += " errors";
			}
			else
			{
				status += " error";
			}
		}

		status += ".";
	}

	window.status = status;
}

function
image_error(image)
{
	image.error = true;

	var	key = getContentKey(image.src);

	_badimages[key] = image;
}
function
Expression(resolver)
{
	this._resolver = resolver;
	this.evaluate = Expression_evaluate;
}

function
Expression_evaluate(text)
{
	var expression = "";
	var variable = "";
	var invariable = false;
	var value;
	var c;
	var i;

	for (i = 0; i < text.length; i++)
	{
		c = text.charAt(i);

		if (c == '[')
		{
			invariable = true;
		}
		else if (c == ']')
		{
			invariable = false;

			if (this._resolver != null)
			{
				value = this._resolver.getValue(variable);
				expression += value;
			}
			else
			{
				expression += "0";
			}

			variable = "";
		}
		else if (invariable)
		{
			variable += c;
		}
		else
		{
			expression += c;
		}
	}

	var result = 0;

	try
	{
		result = eval(expression);
	}
	catch (e)
	{
		alert(e);
	}

	if (isNaN(result))
	{
		result = 0;
	}

	return(result);
}

function
random(lower,upper)
{
	var	num = lower + Math.random() * (upper - lower);
	return(parseInt(num));
}


var	_retries = new Array();

function
Retry(id,code,seconds)
{
	if (id == null)
	{
		id = "window";
	}

	var	r = _retries[id];

	if (r != null)
	{
		r._code = code;
	}
	else
	{
		this._id = id;
		this._code = code;
		this._seconds = seconds;
		this._interval = setInterval("retry('" + id + "')",seconds * 1000);
		_retries[id] = this;
	}
}

function
retry(id)
{
	var	r = _retries[id];

	if (r != null)
	{
		var	status = eval(r._code);

		if (status != null)
		{
			window.status = status;
		}
		else
		{
			clearInterval(r._interval);
		}
	}
}

function
getElementByAttribute(tag,name,value)
{
	var	elements = document.getElementsByTagName(tag);
	var	element;
	var	i;

	for (i = 0; i < elements.length; i++)
	{
		element = elements.item(i);

		if (element.getAttribute(name) == value)
		{
			return(element);
		}
	}

	return(null);
}

var	_menu = null;

function
clear_menus(clearall)
{
	var	divs = document.getElementsByTagName('div');
	var	div;
	var	i;

	for (i = 0; i < divs.length; i++)
	{
		div = divs.item(i);

		if (div.id.indexOf('-menu-div') != -1)
		{
			if (clearall)
			{
				div.style.display = 'none';
				div.style.visibility = 'hidden';
			}
			else if (div.className.indexOf('static') == -1)
			{
				if (div.className.indexOf('flyover') != -1)
				{
					div.style.display = 'none';
					div.style.visibility = 'hidden';
				}
				else if (div == _menu)
				{
					if (_menu._clicks > 1)
					{
						div.style.display = 'none';
						div.style.visibility = 'hidden';
					}
				}
			}
		}
	}
}

function
show_menu(id,alignment,bw)
{
	clear_menus(false);

	var	object = document.getElementById(id);

	if (object == null)
	{
		alert('Cannot find menu: ' + id);
		return;
	}

	var	div = document.getElementById(id + '-menu-div');
	var	table = document.getElementById(id + '-table');

	if (div == null || table == null)
	{
		alert('Cannot find menu: ' + id);
		return;
	}

	if (ie)
	{
		div.style.filter = transitions[3];
		if (div.style.filter.length > 0)
		{
			div.filters[0].apply();
		}
	}

	if (_menu != null && _menu != div)
	{
		_menu.style.display = 'none';
		_menu.style.visibility = 'hidden';
	}

	_menu = div;
	_menu._clicks = 0;

	var	rect = getBounds(id);

	div.style.display = 'block';
	var	menuWidth = table.offsetWidth;
	var	scrolling = false;

	if (div.style.overflow == 'auto')
	{
		scrolling = true;
		menuWidth += sbwidth;
		menuWidth += (bw * 2);
	}

	if (alignment == 'align-left' || alignment == 'align-right')
	{
		div.style.width = menuWidth;

		div.style.top = rect._top;

		if (alignment == 'align-left')
		{
			div.style.left = rect._left - menuWidth;
		}
		else
		{
			div.style.left = rect._right;
		}
	}
	else if (alignment == 'align-top' || alignment == 'align-bottom')
	{
		var	width = rect.getWidth();

		if (menuWidth <= width)
		{
			if (ie == false)
			{
				width -= (bw * 2);
			}

			div.style.width = width;

			if (scrolling)
			{
				width -= sbwidth;
			}

			if (ie)
			{
				width -= (bw * 2);
				table.style.width = width;
			}
			else
			{
				table.style.width = '100%';
			}

		}
		else if (ie == false)
		{
			if (scrolling)
			{
				menuWidth += 3;
			}
			div.style.width = menuWidth;
		}
		else
		{
			div.style.width = menuWidth;
		}

		if (alignment == 'align-top')
		{
			div.style.left = rect._left;
			div.style.top = rect._top - div.offsetHeight;
		}
		else
		{
			div.style.left = rect._left;
			div.style.top = rect._bottom;
		}
	}

	div.style.visibility = 'visible';
	div.style.zIndex = 10000;
	if (ie)
	{
		if (div.style.filter.length > 0)
		{
			div.filters[0].play(durations[3]);
		}
	}
}

function
clear_menu(name)
{
	var	div = document.getElementById(name + '-menu-div');

	if (div == null)
	{
		alert('Cannot find menu div: ' + name + '-menu-div');
		return;
	}

	div.style.display = 'none';
	div.style.visibility = 'hidden';
}
function
row_class(cell,classname)
{
	var	sibling = cell;

	for (;;)
	{
		sibling = sibling.previousSibling;

		if (sibling == null)
		{
			break;
		}

		if (cell.nodeName.toLowerCase() == 'td')
		{
			cell = sibling;
		}
	}

	if (cell == null)
	{
		return;
	}

	while (cell != null)
	{
		if (cell.nodeName.toLowerCase() == 'td')
		{
			cell.className = classname;
		}

		cell = cell.nextSibling;

		if (cell == null)
		{
			break;
		}
	}
}
function
AnimationModel(x,y,heading,speed,layer,destroy,frameindex,framerate,size,instances,halign,valign,reset)
{
	this._x = x;
	this._y = y;
	this._heading = heading;
	this._speed = speed;
	this._layer = layer;
	this._destroy = destroy;
	this._frameindex = frameindex;
	this._framerate = framerate;
	this._size = size;
	this._instances = instances;
	this._halign = halign;
	this._valign = valign;
	this._reset = reset;
}


var	PerSecond = 10;

var	_animations = new Array();
var	_animationmodels = new Array();
var	_animationframes = new Array();
function
AnimationFrame(url)
{
	this._url = url;
}


var	_animationInterval = null;

function
Animation(container,name)
{
	var	model = _animationmodels[name];

	if (model == null)
	{
		return;
	}

	if ((this._frame = document.getElementById(container)) == null)
	{
		this._frame = document.body;
		this._bounds = new Rectangle();
		this._bounds.set(0,0,document.body.clientWidth,document.body.clientHeight);
	}
	else
	{
		this._bounds = getBounds(container);
	}

	this._model = model;
	this._rect = new Rectangle();
	this._left = 0;
	this._top = 0;

	this._expression = new Expression(this);

	this.destroy = Animation_destroy;
	this.stop = Animation_stop;
	this.run = Animation_run;
	this.delta = Animation_delta;
	this.move = Animation_move;
	this.setX = Animation_setX;
	this.setY = Animation_setY;
	this.setHeading = Animation_setHeading;
	this.setLayer = Animation_setLayer;
	this.setFrameindex = Animation_setFrameindex;
	this.setFramerate = Animation_setFramerate;
	this.calculateHeading = Animation_calculateHeading;
	this.setSpeed = Animation_setSpeed;
	this.setSize = Animation_setSize;
	this.calculateSpeed = Animation_calculateSpeed;
	this.reset = Animation_reset;
	this.getValue = Animation_getValue;
	this.setIndex = Animation_setIndex;

	this._frame.style.overflow = 'hidden';

	var	image = document.createElement('img');
	image._animation = this;
	image.style.position = 'absolute';
	image.style.visibility = 'hidden';
	this._frame.appendChild(image);

	this._name = name;
	this._frames = _animationframes[name];
	this._image = image;
	this._index = -1;
	this._isDestroyed = false;
	this._stop = false;
	this._paused = false;

	this._sine = 0.0;
	this._cosine = 0.0;

	this.setSize(this._model._size);

	this.setX(this._model._x);
	this.setY(this._model._y);

	this.setLayer(this._model._layer);
	this.setFrameindex(this._model._frameindex);
	this.setFramerate(this._model._framerate);

	this._deltaX = 0;
	this._deltaY = 0;

	this._cycle = 0;

	this.setHeading(model._heading);
	this.setSpeed(model._speed);

	var	i;

	for (i = 0; i < _animations.length; i++)
	{
		if (_animations[i] == null)
		{
			_animations[i] = this;
			break;
		}
	}

	if (i == _animations.length)
	{
		_animations.push(this);
	}

	if (_animationInterval == null)
	{
		_animationInterval = setInterval('animations()',50);
	}

	this._age = 0;
	this._frameswitch = new Date(0);
	this._born = new Date().getSeconds();
}

function
Animation_reset()
{
	this.setSize(this._model._size);
	this.setX(this._model._x);
	this.setY(this._model._y);
	this.setHeading(this._model._heading);
	this.setSpeed(this._model._speed);
	this.setLayer(this._model._layer);
}

function
Animation_run(date)
{
	if (this._stop)
	{
		return;
	}

	this._age = date.getSeconds() - this._born;

	if (this._expression.evaluate(this._model._destroy))
	{
		this.destroy();
		return;
	}

	var	moveX = 0;
	var	moveY = 0;

	if (this._speed > 0)
	{
		if (++this._cycle == PerSecond)
		{
			this._cycle = 0;
		}

		var	speedX = this._deltaX;
		var	speedY = this._deltaY;

		if (speedX < 0)
		{
			speedX = -speedX;
		}

		if (speedY < 0) 
		{
			speedY = -speedY;
		}

		if (speedX < PerSecond)
		{
			if (this._deltaX != 0)
			{
				var	mod = PerSecond / this._deltaX;

				if (mod != 0 && this._cycle % mod == 0)
				{
					if (this._deltaX < 0)
					{
						moveX = -1;
					}
					else
					{
						moveX = 1;
					}
				}
			}
		}
		else
		{
			moveX = this._deltaX / PerSecond;
		}

		if (speedY < PerSecond)
		{
			if (this._deltaY != 0)
			{
				var	mod = PerSecond / this._deltaY;

				if (mod != 0 && this._cycle % mod == 0)
				{
					if (this._deltaY < 0)
					{
						moveY = -1;
					}
					else
					{
						moveY = 1;
					}
				}
			}
		}
		else
		{
			moveY = this._deltaY / PerSecond;
		}

	}

	var	index = -1;

	if (this._framerate > 0)
	{
		if (date - this._frameswitch >= this._framerate)
		{
			index = this._index;
		}
	}

	if (index != -1)
	{
		index++;

		if (index >= this._frames.length)
		{
			index = 0;
		}

		this.setIndex(index,date);
	}

	this.delta(moveX,moveY);
}
function
Animation_destroy()
{
	this._isDestroyed = true;
}

function
Animation_getValue(variable)
{
	var	value = 0;

	if (variable == "x")
	{
		value = this._x;
	}
	else if (variable == "y")
	{
		value = this._y;
	}
	else if (variable == "speed")
	{
		value = this._speed;
	}
	else if (variable == "heading")
	{
		value = this._heading;
	}
	else if (variable == "size")
	{
		value = this._size;
	}
	else if (variable == "age")
	{
		value = this._age;
	}

	return(value);
}
function
Animation_pause()
{
	this._paused = true;
}

function
Animation_continue()
{
	this._paused = false;
}

function
Animation_stop()
{
	this._stop = true;
}

function
Animation_delta(deltaX,deltaY)
{
	this.move(this._left + deltaX,this._top + deltaY);
}

function
Animation_move(x,y)
{
	this._left = x;
	this._top = y;

	var	rect = new Rectangle();

	rect.set(x,y,this._rect.getWidth(),this._rect.getHeight());

	var	left = rect._left;
	var	top = rect._top;

	if (this._model._halign == 1)
	{
		left -= parseInt(rect.getWidth() / 2);
	}
	else if (this._model._halign == 2)
	{
		left -= rect.getWidth();
	}

	if (this._model._valign == 1)
	{
		top -= parseInt(rect.getHeight() / 2);
	}
	else if (this._model._valign == 2)
	{
		top -= rect.getHeight();
	}

	rect.move(left,top);

	this._rect = rect.copy();

	this._image.style.left = rect._left;
	this._image.style.top = rect._top;
	this._image.style.width = rect.getWidth();
	this._image.style.height = rect.getHeight();
	this._image.style.visibility = 'visible';
}
function
Animation_setX(value)
{
	var	x = this._expression.evaluate(value);
	this._x = parseInt(x);
	this._left = this._x / 100 * this._bounds.getWidth();
}

function
Animation_setY(value)
{
	var	y = this._expression.evaluate(value);
	this._y = parseInt(y);
	this._top = this._y / 100 * this._bounds.getHeight();
}

function
Animation_setHeading(heading)
{
	this._heading = this._expression.evaluate(heading) % 360;
	this.calculateHeading();
	this.calculateSpeed();
}

function
Animation_calculateHeading()
{
	var	geometricHeading = -this._heading + 90;
	var	angle = 3.14 * geometricHeading / 180;

	this._sine = Math.sin(angle);
	this._cosine = Math.cos(angle);
}

function
Animation_setSpeed(speed)
{
	this._speed = this._expression.evaluate(speed);
	this.calculateSpeed();
}

function
Animation_calculateSpeed()
{
	var	rise = this._sine;
	var	run = this._cosine;

	if (rise < 0)
	{
		rise = -rise;
	}

	if (run < 0)
	{
		run = -run;
	}

	var	ratio = rise / run;
	var	deltaX;
	var	deltaY;

	if (rise > run)
	{
		deltaX = this._speed / ratio;
		deltaY = this._speed;
	}
	else
	{
		deltaX = this._speed;
		deltaY = this._speed * ratio;
	}

	if (this._sine < 0)
	{
		deltaY = -deltaY;
	}

	if (this._cosine < 0)
	{
		deltaX = -deltaX;
	}

	deltaY = -deltaY;

	this._deltaX = parseInt(deltaX);
	this._deltaY = parseInt(deltaY);
}

function
Animation_setSize(value)
{
	var	size = this._expression.evaluate(value);
	if (size != this._size);
	{
		this._size = size;
		this.setIndex(this._index);
	}
	if (size <= 0)
	{
		this.destroy();
	}
}

function
Animation_setLayer(value)
{
	this._layer = this._expression.evaluate(value);
	this._image.style.zIndex = this._layer;
}
function
Animation_setFrameindex(value)
{
	var	index = this._expression.evaluate(value);
	this.setIndex(index,new Date());
}

function
Animation_setFramerate(value)
{
	this._framerate = this._expression.evaluate(value);
}

function
Animation_setIndex(index,date)
{
	if (index < 0 || index >= this._frames.length)
	{
		return;
	}

	if (this._index != index)
	{
		this._index = index;
		this._image.src = this._frames[index]._url;
	}

	url = this._frames[this._index]._url;

	if (date != null)
	{
		this._frameswitch = date;
	}

	this._rect = getImageRect(url,this._bounds,this._size,true);
}
function
animation_loaded(name)
{
	var	frames = _animationframes[name];

	if (frames == null)
	{
		return('Cannot find animation');
	}

	var	frame;
	var	image;
	var	loaded = 0;
	var	target = frames.length;
	var	i;

	for (i = 0; i < frames.length; i++)
	{
		frame = frames[i];

		if ((image = getImage(getContentKey(frame._url))) != null)
		{
			if (image.complete)
			{
				loaded++;
			}
			else if (_badimages[frame._url] != null)
			{
				target--;
			}
		}
	}

	if (loaded < target)
	{
		return('The animation is not ready, ' + loaded + ' out of ' + frames.length + ' slides have loaded');
	}

	return(null);
}

function
animations()
{
	if (_animations.length == 0)
	{
		clearInterval(_animationInterval);
		_animationInterval = null;
		return;
	}

	var	date = new Date();

	var	animation;
	var	destroy;
	var	i;

	for (i = 0; i < _animations.length; i++)
	{
		animation = _animations[i];

		if (animation == null)
		{
			continue;
		}

		if (animation._isDestroyed)
		{
			animation._frame.removeChild(animation._image);
			_animations[i] = null;
			continue;
		}

		animation.run(date);

		destroy = false;

		if (animation._deltaX < 0)
		{
			if (animation._rect._right < 0)
			{
				destroy = true;
			}
		}
		else if (animation._rect._left > animation._bounds.getWidth())
		{
			destroy = true;
		}

		if (animation._deltaY < 0)
		{
			if (animation._rect._bottom < 0)
			{
				destroy = true;
			}
		}
		else if (animation._rect._top > animation._bounds.getHeight())
		{
			destroy = true;
		}

		if (destroy)
		{
			if (animation._model._reset == true)
			{
				animation.reset();
			}
			else
			{
				animation.destroy();
			}
		}
	}
}

function
animation_play(frame,name,count)
{
	var	status = animation_loaded(name);

	if (status != null)
	{
		window.status = status;
		var	id = frame + '.' + name;
		var	code = "animation_play('" + frame + "','" + name + "'," + count + ")";
		new Retry(id,code,2);
		return;
	}

	if (count == 0)
	{
		count = 1;
	}

	var	i;

	for (i = 0; i < count; i++)
	{
		new Animation(frame,name);
	}
}

function
animation_stop(frame,name)
{
	var	div = document.getElementById(frame);
	var	i;

	for (i = 0; i < _animations.length; i++)
	{
		if (_animations[i] == null)
		{
			continue;
		}

		if (_animations[i]._name == name)
		{
			if (div == null || _animations[i]._frame == div)
			{
				_animations[i].destroy();
			}
		}
	}
}
function
animation_heading(frame,name,value)
{
	var	div = document.getElementById(frame);
	var	i;

	for (i = 0; i < _animations.length; i++)
	{
		if (_animations[i] == null)
		{
			continue;
		}

		if (_animations[i]._name != name)
		{
			continue;
		}

		if (div != null && _animations[i]._frame != div)
		{
			continue;
		}

		_animations[i].setHeading(value);
	}
}

function
animation_speed(frame,name,value)
{
	var	div = document.getElementById(frame);
	var	i;

	for (i = 0; i < _animations.length; i++)
	{
		if (_animations[i] == null)
		{
			continue;
		}

		if (_animations[i]._name != name)
		{
			continue;
		}

		if (div != null && _animations[i]._frame != div)
		{
			continue;
		}

		_animations[i].setSpeed(value);
	}
}

function
animation_x(frame,name,value)
{
	var	div = document.getElementById(frame);
	var	i;

	for (i = 0; i < _animations.length; i++)
	{
		if (_animations[i] == null)
		{
			continue;
		}

		if (_animations[i]._name != name)
		{
			continue;
		}

		if (div != null && _animations[i]._frame != div)
		{
			continue;
		}

		_animations[i].setX(value);
	}
}

function
animation_y(frame,name,value)
{
	var	div = document.getElementById(frame);
	var	i;

	for (i = 0; i < _animations.length; i++)
	{
		if (_animations[i] == null)
		{
			continue;
		}

		if (_animations[i]._name != name)
		{
			continue;
		}

		if (div != null && _animations[i]._frame != div)
		{
			continue;
		}

		_animations[i].setY(value);
	}
}

function
animation_framerate(frame,name,value)
{
	var	div = document.getElementById(frame);
	var	i;

	for (i = 0; i < _animations.length; i++)
	{
		if (_animations[i] == null)
		{
			continue;
		}

		if (_animations[i]._name != name)
		{
			continue;
		}

		if (div != null && _animations[i]._frame != div)
		{
			continue;
		}

		_animations[i].setFramerate(value);
	}
}

function
animation_frameindex(frame,name,value)
{
	var	div = document.getElementById(frame);
	var	i;

	for (i = 0; i < _animations.length; i++)
	{
		if (_animations[i] == null)
		{
			continue;
		}

		if (_animations[i]._name != name)
		{
			continue;
		}

		if (div != null && _animations[i]._frame != div)
		{
			continue;
		}

		_animations[i].setFrameindex(value);
	}
}

function
animation_size(frame,name,value)
{
	var	div = document.getElementById(frame);
	var	i;

	for (i = 0; i < _animations.length; i++)
	{
		if (_animations[i] == null)
		{
			continue;
		}

		if (_animations[i]._name != name)
		{
			continue;
		}

		if (div != null && _animations[i]._frame != div)
		{
			continue;
		}

		_animations[i].setSize(value);
	}
}

function
show_picture(frame,url,text,hyperlink,target,audio,ratio,aspect)
{
	var	image = getImage(url);

	if (image == null)
	{
		alert('Cannot find the image');
		return;
	}

	if (image.complete == false)
	{
		var	key = getContentKey(image.src);

		if (_badimages[key] != null)
		{
			alert('There was an error loading image ' + key);
		}
		else
		{
			alert('The image is loading, please wait');
		}

		return;
	}

	var	divId;
	var	imageId;
	var	captionId;
	var	cellId;
	var	link;
	if (hyperlink != null)
	{
		divId = frame + '-image-link-div';
		imageId = frame + '-link-image';
		captionId = frame + '-link-caption';
		cellId = frame + '-link-caption-cell';

		link = document.getElementById(frame + '-image-link');

		if (link == null)
		{
			alert('No pic image link: ' + frame + '-image-link');
			return;
		}

		link.href = hyperlink;

		if (target != null && target.length > 0)
		{
			link.target = target;
		}
		else
		{
			link.target = '_self';
		}
	}
	else
	{
		divId = frame + '-image-div';
		imageId = frame + '-image';
		captionId = frame + '-caption';
		cellId = frame + '-caption-cell';
	}

	var	div = document.getElementById(divId);
	if (div == null)
	{
		alert('No div found: ' + divId);
		return;
	}

	if (clears[0])
	{
		clear_frame(frame);
	}
	if (ie)
	{
		div.style.filter = transitions[0];
		if (div.style.filter.length > 0)
		{
			div.filters[0].apply();
		}
	}
	if ((image = document.getElementById(imageId)) == null)
	{
		alert('No image found: ' + imageId);
		return;
	}

	var	caption = document.getElementById(captionId);

	if (caption == null)
	{
		alert('No caption found: ' + captionId);
		return;
	}

	var	cell = document.getElementById(cellId);

	if (cell == null)
	{
		alert('No cell found: ' + cellId);
		return;
	}

	if (text != null)
	{
		cell.innerHTML = text;
		caption.style.display = 'block';
		caption.style.height = captionHeight;
		image.style.height = imageHeight;
	}
	else
	{
		cell.innerHTML = '';
		caption.style.display = 'none';
		image.style.height = '100%';
	}
	image.style.width = '100%';

	if (clears[0] == false)
	{
		clear_frame(frame);
	}

	var	bounds = getBounds(frame);

	if (ie == false)
	{
		bounds._right -= imageBw * 2;
		bounds._bottom -= imageBw * 2;
	}

	var	rect = getImageRect(url,bounds,ratio,aspect);

	div.style.left = rect._left;
	div.style.top = rect._top;
	div.style.width = rect.getWidth();
	div.style.height = rect.getHeight();
	div.style.display = 'block';
	image.src = url;
	if (ie)
	{
		if (div.style.filter.length > 0)
		{
			div.filters[0].play(durations[0]);
		}
	}

	if (audio != null)
	{
		play_audio(null,audio,null,null,1);
	}

}

function
play_video(frame,video,uimode,ratio,playcount)
{
	var	div = document.getElementById(frame + '-video-div');

	if (div == null)
	{
		alert('Cannot find the media player');
		return;
	}

	var	player = document.getElementById(frame + '-video');

	if (player == null)
	{
		var	html = "<object id='" + frame + "-video' classid='clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6' style='visibility:hidden;width:100%;height:100%'></object>";
		div.innerHTML = html;
		player = document.getElementById(frame + '-video');
		_players.push(player);
	}

	var	bounds = getBounds(frame);

	if (player == null || bounds == null)
	{
		alert('Cannot find the media player');
		return;
	}
	if (player.playState == 2)
	{
		player.controls.play();
		return;
	}

	var	container = document.getElementById(frame);
	if (ie)
	{
		container.style.filter = transitions[2];
		if (container.style.filter.length > 0)
		{
			container.filters[0].apply();
		}
	}
	clear_frame(frame);

	if (ie == false)
	{
		bounds._right -= videoBw * 2;
		bounds._bottom -= videoBw * 2;
	}

	var	center = bounds.getCenter();
	var	rect = new Rectangle();
	var	w = bounds.getWidth() * (ratio / 100);
	var	h = bounds.getHeight() * (ratio / 100);

	rect._left = center._x - (w / 2);
	rect._right = center._x + (w / 2);
	rect._top = center._y - (h / 2);
	rect._bottom = center._y + (h / 2);
	rect.offset(bounds._left,bounds._top);

	player.url = '';
	div.style.left = rect._left;
	div.style.top = rect._top;
	div.style.width = rect.getWidth();
	div.style.height = rect.getHeight();
	player.uimode = uimode;
	if (playcount > 0)
	{
		player.settings.playCount = playcount;
		player.settings.setMode('loop',false);
	}
	else
	{
		player.settings.playCount = 1;
		player.settings.setMode('loop',true);
	}
	div.style.visibility = 'visible';
	player.style.visibility = 'visible';
	if (ie)
	{
		if (container.style.filter.length > 0)
		{
			container.filters[0].play(durations[2]);
			container._url = video;
			container._player = player;
			container.onfilterchange = filter_handler;
		}
		else
		{
			player.url = video;
			player.controls.play();
		}
	}
	else
	{
		player.url = video;
		player.controls.play();
	}

	player._frame = frame;

	if (_playerInterval == null)
	{
		_playerInterval = setInterval('check_players()',2000);
	}
}

function
pause_video(frame)
{
	if ((div = document.getElementById(frame + '-video-div')) != null)
	{
		var	player = document.getElementById(frame + '-video');

		if (player != null)
	{
		player.controls.pause();
		}
	}
}

var	audioPlayer = null;

function
play_audio(frame,url,uimode,ratio,playcount)
{
	if (frame != null && frame.length > 0)
	{
		play_video(frame,url,uimode,ratio,playcount);
		return;
	}

	if (audioPlayer == null)
	{
		audioPlayer = document.getElementById('page-audio-player');
	}

	if (audioPlayer == null)
	{
		var	span = document.getElementById('page-audio-container');
		span.innerHTML = "<object id='page-audio-player' classid='clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6' style='visibility:hidden;display:none'></object>";
		audioPlayer = document.getElementById('page-audio-player');
	}

	if (audioPlayer != null)
	{
		audioPlayer.url = url;

		audioPlayer.repeat = true;
		audioPlayer.controls.play();
		if (playcount > 0)
		{
			audioPlayer.settings.playCount = playcount;
			audioPlayer.settings.setMode('loop',false);
		}
		else
		{
			audioPlayer.settings.playCount = 1;
			audioPlayer.settings.setMode('loop',true);
		}
	}
}

function
clear_audio()
{
	if (audioPlayer != null)
	{
		audioPlayer.url = '';
		audioPlayer.controls.stop();
	}
}

function
Slide(type,url,caption,hyperlink,target,audio,ratio,aspect)
{
	this._type = type;
	this._url = url;
	this._caption = caption;
	this._hyperlink = hyperlink;
	this._target = target;
	this._audio = audio;
	this._ratio = ratio;
	this._aspect = aspect;
}

var	_slides = new Array();
var	_slideshowAudios = new Array();
function
slideshow_loaded(name)
{
	var	slides = _slides[name];

	if (slides == null)
	{
		return('Cannot find slideshow');
	}

	var	slide;
	var	image;
	var	loaded = 0;
	var	target = slides.length;
	var	i;

	for (i = 0; i < slides.length; i++)
	{
		slide = slides[i];

		if (slide._type == 'picture')
		{
			if ((image = getImage(getContentKey(slide._url))) != null)
			{
				if (image.complete)
				{
					loaded++;
				}
				else if (_badimages[slide._url] != null)
				{
					target--;
				}
			}
		}
	}

	if (loaded < target)
	{
		return('The slideshow is not ready, ' + loaded + ' out of ' + slides.length + ' slides have loaded');
	}

	return(null);
}

function
show_slides(frame,name,delay,repeat,manual)
{
	var	status = slideshow_loaded(name);

	if (status != null)
	{
		window.status = status;
		var	id = frame + '.' + name;
		var	code = "show_slides('" + frame + "','" + name + "'," + delay + "," + repeat + "," + manual + ")";
		new Retry(id,code,2);
		return;
	}

	var	s = _slides[name];
	var	audio = _slideshowAudios[name];

	var	show = new Slideshow(frame,s,delay,repeat,manual,audio);
}

var	_slideshows = new Array();

function
next_slide(id)
{
	var	slideshow = _slideshows[id];

	if (slideshow == null)
	{
		var	container = document.getElementById(id);

		if (container != null && container._slideshow != null)
		{
			slideshow = container._slideshow;
		}
	}

	if (slideshow != null && slideshow._container != null)
	{
		slideshow.next();
	}
}

function
prev_slide(id)
{
	var	slideshow = _slideshows[id];

	if (slideshow == null)
	{
		var	container = document.getElementById(id);

		if (container != null && container._slideshow != null)
		{
			slideshow = container._slideshow;
		}
	}

	if (slideshow != null && slideshow._container != null)
	{
		slideshow.prev();
	}
}
function
getSlideshowId()
{
	var	id = -1;
	var	i;

	for (i = 0; i < _slideshows.length; i++)
	{
		if (_slideshows[i] == null)
		{
			id = i;
		}
		else if (_slideshows[i]._isDestroyed)
		{
			_slideshows[i] = null;
		}
	}

	if (id == -1)
	{
		id = i;
	}

	return(id);
}

function
Slideshow(frame,slides,delay,repeat,manual,audio)
{
	this._id = getSlideshowId();
	this._audio = audio;
	_slideshows[this._id] = this;

	this._container = document.getElementById(frame);

	if (this._container == null)
	{
		alert('Cannot find the target for the slideshow');
		return;
	}

	if (this._container._slideshow != null)
	{
		this._container._slideshow.destroy();
	}

	this._frame = frame;
	this._slides = slides;
	this._delay = delay;
	this._repeat = repeat;
	this._manual = manual;
	this._interval = null;
	this._index = -1;
	this._stop = false;

	this.next = Slideshow_next;
	this.prev = Slideshow_prev;
	this.stop = Slideshow_stop;
	this.destroy = Slideshow_destroy;

	if (this._audio != null)
	{
		
			play_audio(null,this._audio,null,null,1);
	}

	this.next();
}

function
Slideshow_next()
{
	if (this._interval != null)
	{
		clearInterval(this._interval);
		this._interval = null;
	}

	if (this._stop)
	{
		this.destroy();
		return;
	}

	if (this._audio != null && audioPlayer != null)
	{
		if (audioPlayer.currentMedia.duration == 0)
		{
			this._interval = setInterval("next_slide(" + this._id + ")",2000);
			return;
		}
	}

	this._index++;

	if (this._index >= this._slides.length)
	{
		if (this._repeat)
		{
			this._index = 0;
		}
		else
		{
			this.destroy();
			clear_frame(this._frame);
			return;
		}
	}

	var	slide = this._slides[this._index];

	this._container._slideshow = null;
	if (slide._type == 'picture')
	{
		show_picture(this._frame,slide._url,slide._caption,slide._hyperlink,slide._target,slide._audio,slide._ratio,slide._aspect);
	}
	else if (slide._type == 'page')
	{
		show_page(this._frame,slide._url,slide._audio,slide._ratio);
	}
	this._container._slideshow = this;

	if (this._manual == false)
	{
		var	interval = this._delay * 1000;

		if (this._audio != null && audioPlayer != null)
		{
			var	audioInterval = 0;
			var	secondsLeft = audioPlayer.currentMedia.duration - audioPlayer.controls.currentPosition;
			var	slidesLeft = this._slides.length - this._index - 1;

			if (slidesLeft > 0)
			{
				audioInterval = secondsLeft / (slidesLeft + 1) * 1000;
			}

			if (audioInterval > interval)
			{
				interval = audioInterval;
			}

			if (audioPlayer.playState == 1)
			{
				audioPlayer.controls.play();
			}
		}

		this._interval = setInterval("next_slide(" + this._id + ")",interval);
	}
}

function
Slideshow_prev()
{
	if (this._stop)
	{
		return;
	}

	this._index--;

	if (this._index < 0)
	{
		if (this._repeat)
		{
			this._index = this._slides.length - 1;
		}
		else
		{
			this.destroy();
			clear_frame(this._frame);
			return;
		}
	}

	var	slide = this._slides[this._index];
	this._container._slideshow = null;

	if (slide._type == 'picture')
	{
	show_picture(this._frame,slide._url,slide._caption,slide._hyperlink,slide._target,slide._audio,slide._ratio,slide._aspect);
	}
	else if (slide._type == 'page')
	{
		show_page(this._frame,slide._url,slide._audio,slide._ratio);
	}
	this._container._slideshow = this;
}

function
Slideshow_stop()
{
	this._stop = true;
}

function
Slideshow_destroy()
{
	if (this._interval != null)
	{
		clearInterval(this._interval);
		this._interval = null;
	}

	if (this._audio != null)
	{
		clear_audio();
	}
	this._isDestroyed = true;
	this._container = null;
}
var	_timers = new Array();
var	_timermodels = new Array();
function
TimerModel(code,interval,repetitions)
{
	this._code = code;
	this._interval = interval;
	this._repetitions = repetitions;
}

function
fire(id)
{
	var	timer = _timers[id];

	if (timer != null)
	{
		timer.fired();
	}
}

function
Timer(name)
{
	var	model = _timermodels[name];

	if (model == null)
	{
		return;
	}

	this._name = name;
	this._id = getTimerId();
	_timers[this._id] = this;

	this._model = model;
	this._repetition = 0;
	this._isDestroyed = false;
	this._interval = setInterval("fire(" + this._id + ")",this._model._interval * 1000);

	this.fired = Timer_fired;
	this.destroy = Timer_destroy;
}

function
Timer_fired()
{
	if (this._isDestroyed)
	{
		clearInterval(this._interval);
		return;
	}

	eval(this._model._code);
	if (this._model._repetitions > 0)
	{
		this._repetition++;
		if (this._repetition == this._model._repetitions)
		{
			this.destroy();
			clearInterval(this._interval);
		}
	}
}

function
Timer_destroy()
{
	this._isDestroyed = true;
}

function
getTimerId()
{
	var	id = -1;
	var	i;

	for (i = 0; i < _timers.length; i++)
	{
		if (_timers[i] == null)
		{
			id = i;
		}
		else if (_timers[i]._isDestroyed)
		{
			_timers[i] = null;
		}
	}

	if (id == -1)
	{
		id = i;
	}

	return(id);
}

function
timer_start(name)
{
	new Timer(name);
}

function
timer_stop(name)
{
	var	timer;
	var	i;
	for (i = 0; i < _timers.length; i++)
	{
		timer = _timers[i];
		if (timer == null)
		{
			continue;
		}
		if (timer._name == name)
		{
			timer.destroy();
		}
	}
}

