var isIE = navigator.userAgent.indexOf('MSIE') + 1;
var isSafari = navigator.userAgent.indexOf('Apple') + 1;


function ani(e, t, p1) {
	this.e = e;
	this.t = t;
	this.p1 = p1;
}

function dropStack(e, t, p1) {
	this.anim = new Array();
	var a = new ani(e, t, p1);
	if (e) { this.anim.push(a); }
}

function pushAnim (e, index, t, p1) {
	var tempa = new ani(e, t, p1);
	for (var i = 0; i <= index; i++) {
		if (!a[index]) {
			a.push(new dropStack(null, null, null));
		}
	}
	a[index].anim.push(tempa);
}

function dePX (s) {
	if (s.substr(s.length - 2) == 'px') {
		return parseInt(s.substr(0, s.length - 2));
	}
	else {
		if (!s) {
			s = 0;
		}
		return parseInt(s);	
	}
}

var ECONOMY = 1000 / 24;
var AVERAGE = 40;
var QUALITY = 20;

var an = setInterval(Animate, ECONOMY);
var idle = false;
var noClick = false; var clicked = false;
var a = new Array();
a.push(new dropStack(function () { idle = true; noClick = false; }, null, null));
//a.pushAnim(function () { alert("Huh?"); }, 5, "Me!", null);

function deIdle() {
	idle = false;
}	

function Animate() {
	var curAnims = a.shift();
	if (curAnims != undefined) {
		for (var i = 0; i < curAnims.anim.length; i++) {
			//if (curAnims[i].t) { alert(curAnims[i].t.id); }
			curAnims.anim[i].e(curAnims.anim[i].t, curAnims.anim[i].p1);
		}
	}
}

function fadeIn(ppf, delay) {
	if (!ppf) { ppf = 100; }
	var frames = Math.ceil(100 / ppf);
	pushAnim(function (t) { t.style.visibility = 'visible'; }, delay + 1, this);
	for (var i = 1; i <= frames; i++) {
		pushAnim(function (t, p1) { t.style.opacity = (p1 / 100); t.style.filter = "alpha(opacity=" + p1 +")";}, delay + i, this, i * ppf)	
	}
}

function pushUL(ppf, delay) {
	var sh = 10;
	var sw = 30;
	var xd = 15;
	var frames;
	if (!this.offsetHeight) {
		oh = 60;
		ow = 150;
	}
	else {
		oh = this.offsetHeight;
		ow = this.offsetWidth;
	}
	var aspect = (ow - sw) / (oh - sh);
	if (!ppf) { ppf	 = frames; }
	frames = Math.ceil(oh / ppf);
	xv = xd / frames;
	var b = dePX(this.style.top) + oh;
	var r = dePX(this.style.left) + ow;
	pushAnim(function (t) { t.style.visibility = 'visible';}, delay + 1, this);
	//alert(this.offsetHeight);
	for (var i = 0; i < frames; i++) {
		pushAnim(function (t, p1) { t.style.left = p1 + 'px';}, delay + i, this.pNode, r - sw - (i * aspect * ppf) - (xd - (i * xv)));
		pushAnim(function (t, p1) { t.style.top = p1 + 'px'; }, delay + i, this.pNode, b - sh - (i * ppf));
		pushAnim(function (t, p1) { t.style.width = p1 + 'px'; }, delay + i, this.pNode, (i * aspect * ppf) + sw);
		pushAnim(function (t, p1) { t.style.height = p1 + 'px'; }, delay + i, this.pNode, (i * ppf) + sh);
		pushAnim(function (t, p1) { t.style.left = p1 + 'px'; }, delay + i, this, (i * aspect * ppf) - ow + sw);
		pushAnim(function (t, p1) { t.style.top = p1 + 'px'; }, delay + i, this, (i * ppf) - oh + sh);
	}
	
}


