<scriptlet id=timer>
<implements id=Behavior type=Behavior default />
<implements id=Automation type=Automation>
	<method name=start />
	<method name=stop />
	<method name=pause />
	<method name=ms_tick />
	<property dispid=0 name=t>
		<get internalName=getTime />
	</property>
	<property name=duration />
	<property name=interval />
	<property name=autostart />
</implements>

<script language=javascript>

var base = 0
var divisor = 1

element.time = 0

if (typeof(duration) == "undefined")
	duration = 0

if (typeof(interval) == "undefined")
	interval = 100

if (typeof(units) == "undefined")
	element.units = "ms"

if (units == "seconds")
	divisor = 1000
else if (units == "minutes")
	divisor = 60000


if (typeof(autostart) == "undefined")
	autostart = "no"

if (autostart == "immediate")
	start()
else if (autostart == "document")
	attachNotification(notify)

function notify(notification)
{
	if (notification == "documentReady")
		start()
}

function ms_tick()
{
	var tNow = new Date()

	var t = (tNow - base) / divisor

	if ((duration == 0) || (t <= duration))
	{
		time = t
	}
	else
	{
			time = duration
			clearInterval(idTimer)
	}
}

function start()
{
	if (base == 0)
	{
		base = new Date()
	}
	idTimer = setInterval(uniqueID + ".ms_tick()", interval)
}

function stop()
{
	clearInterval(idTimer)
	base = 0
}

function pause()
{
	clearInterval(idTimer)
}

function getTime()
{
	return element.time
}

</script>
</scriptlet>
