/* legacy.js
 * Functions that are part of the javascript spec but not defined in IE 5.0 
 * and perhaps other older browsers. They are defined here to add support to these older browsers.
 * Modified from http://www.crockford.com/javascript/remedial.html to remove external dependencies */
 
if (!(typeof Function.apply == 'function'))
{	Function.prototype['apply'] =  function (o, a)
	{	var r, x = '____apply';
		if (!isObject(o))
			o = {};
		
		o[x] = this;
		switch ((a && a.length) || 0)
		{	case 0:  r = o[x]();  break;
			case 1:  r = o[x](a[0]);  break;
			case 2:  r = o[x](a[0], a[1]);  break;
			case 3:  r = o[x](a[0], a[1], a[2]);  break;
			case 4:  r = o[x](a[0], a[1], a[2], a[3]);  break;
			case 5:  r = o[x](a[0], a[1], a[2], a[3], a[4]);  break;
			case 6:  r = o[x](a[0], a[1], a[2], a[3], a[4], a[5]);  break;
			case 7:  r = o[x](a[0], a[1], a[2], a[3], a[4], a[5], a[6]);  break;
			case 8:  r = o[x](a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]);  break;
			default:
				alert('Too many arguments to apply in Function.apply.');
		}
		delete o[x];
		return r;
	}
} 

if (!(typeof Array.prototype.pop == 'function'))
{	Array.prototype['pop'] =  function()
	{	return this.splice(this.length - 1, 1)[0];
	}
}

if (!(typeof Array.prototype.push == 'function'))
{	Array.prototype['push'] =  function ()
	{	this.splice.apply(this,
			[this.length, 0].concat(Array.prototype.slice.apply(arguments)));
		return this.length;
	}
}

if (!(typeof Array.prototype.shift == 'function'))
{	Array.prototype['shift'] = function ()
	{	return this.splice(0, 1)[0];
	}
}

if (!(typeof Array.prototype.splice == 'function'))
{	Array.prototype['splice'] =  function (s, d)
	{	var max = Math.max,
			min = Math.min,
			a = [], // The return value array
			e,  // element
			i = max(arguments.length - 2, 0),   // insert count
			k = 0,
			l = this.length,
			n,  // new length
			v,  // delta
			x;  // shift count

		s = s || 0;
		if (s < 0)
			s += l;		
		s = max(min(s, l), 0);  // start point
		d = max(min(isNumber(d) ? d : l, l - s), 0);	// delete count
		v = i - d;
		n = l + v;
		while (k < d)
		{	e = this[s + k];
			if (!isUndefined(e))
				a[k] = e;			
			k += 1;
		}
		x = l - s - d;
		if (v < 0)
		{	k = s + i;
			while (x)
			{	this[k] = this[k - v];
				k += 1;
				x -= 1;
			}
			this.length = n;
		} else if (v > 0)
		{	k = 1;
			while (x)
			{	this[n - k] = this[l - k];
				k += 1;
				x -= 1;
			}
		}
		for (k = 0; k < i; ++k)
			this[s + k] = arguments[k + 2];		
		return a;
	}
}

if (!(typeof Array.prototype.unshift == 'function'))
{	Array.prototype['unshift'] = function()
	{   this.splice.apply(this,	[0, 0].concat(Array.prototype.slice.apply(arguments)));
		return this.length;
	}
} 