// GrowThing
// version 1.0
// by Antone Roundy
// (c) 2009 Gecko Tribe, LLC

growThings=new Array();
growThingSkip=0.02;
growThingDelay=10;
growThingsToGo=0;
growThingDontAdd=0;
growThingMaxAttempts=20;

function AddGrowThing(n,notImg) {
	if (growThingDontAdd) setTimeout('AddGrowThing("'+n+'",'+notImg+')',30);
	else {
		growThingDontAdd=1;
		growThings[growThings.length]=new Array(n,0,0,1,notImg); // name, element, steps done or failed element gets, continue, isn't an image
		growThingsToGo++;
		if (growThingsToGo==1) setTimeout('GrowThing()',growThingDelay);
		growThingDontAdd=0;
	}
}

function GrowThing() {
	var i,c,t;
	growThingDontAdd=1;
	if (growThingsToGo) {
		for (i=0;i<growThings.length;i++) {
			if (growThings[i][3]) {
				if (growThings[i][1]) {
					if (growThings[i][4]||growThings[i][1].complete) {
						growThings[i][2]+=growThingSkip;
						if (growThings[i][2]>=1) {
							growThings[i][2]=1;
							growThings[i][3]=0;
							growThingsToGo--;
						}
						t='scaleX('+growThings[i][2]+')scaleY('+growThings[i][2]+')';
						growThings[i][1].style.webkitTransform=t;
						growThings[i][1].style.MozTransform=t;
						growThings[i][1].style.transform=t;
					}
				} else {
					growThings[i][1]=document.getElementById(growThings[i][0]);
					if (growThings[i][1]) growThings[i][2]=0;
					else {
						growThings[i][2]++;
						if (growThings[i][2]>growThingMaxAttempts) {
							growThings[i][3]=0;
							growThingsToGo--;
						}
					}
				}
			}
		}
		if (growThingsToGo) setTimeout('GrowThing()',growThingDelay);
	}
	growThingDontAdd=0;
}