// Common Javascript
//
// Copyright 2006 Pointy Computers Limited
// All Rights Reserved.
//
// http://www.pointycomputers.co.uk/web

function addEvent(elm, evType, fn, useCapture)
{
	// REQUIRES:
	//	Credit: Function written by Scott Andrews
	//	(slightly modified)

	var ret = 0;

	if (elm.addEventListener)
		ret = elm.addEventListener(evType, fn, useCapture);
	else if (elm.attachEvent)
		ret = elm.attachEvent('on' + evType, fn);
	else	elm['on' + evType] = fn;

	return ret;
}

function arrayPos( thing, arr) {
	var i;

	for( i = 0; i < arr.length; i++)
	if( arr[ i] == thing)
		return i;

	return -1;
}

function myRand( max, min) {
	return Math.round( Math.random() * (max - ( min? min: 0))) + ( min? min: 0);
}

function sineGetStep( start, end, current, steps) {
	var thisStep;
	var direc = ( start > end);
	var range = end - start;
	var i;

	for( i = 0; i < steps; i++) {
		if( !direc)		// Going up!
		if( current >= start + Math.round( range * Math.sin((i / steps) * (Math.PI /2))))
			thisStep = i + 1;

		if( direc)		// Going down!
		if( current <= start + Math.round( range * Math.sin((i / steps) * (Math.PI /2))))
			thisStep = i + 1;
	}

	return thisStep;
}

function sineGetVal( start, end, step, steps, inc) {
	var val;
	var range = end - start;

	val = start + Math.round( range * Math.sin((step / steps) * (Math.PI /2)));

	return val;
}
