temp=function(){};
$pr=temp.prototype;

$pr.tweentype='outCirc';
$pr.defaultlength=100;
$pr.animationnum=0;
// took the following two properties out because of an assumption on my part about how prototypal properties work
// I had thought that, like flash prototypes, they become instanciated at the point at which they are altered in
// the instanciated object itself.
//$pr.eventnum=0;
//$pr.eventindex={};
$pr.setupanimate=function()
{
	this.animationnum++;
	var obj={};
	obj.num=this.animationnum;
	
	if(!this.animatorindex)
		this.animatorindex={};
		
	this.animatorindex['an'+this.animationnum]=obj;
	
	return obj;
}
$pr.cleanupanimate=function()
{
	this.animatorindex=null;
}
// animateprop ( prop:String [, end: Number [, start: Number [, length: Number [, delay: Number [, type:String ]]]]] )
$pr.animateprop=function(prop,e,s,l,d,t)
{
	if(isNaN(e))
		return false;
		
	var obj=this.setupanimate();
	
	// this is kind of an ugly hack but needs to be done this way
	// until I can think up a mmore elegant solution.
	// basically I need to convert this value to an int for the change calculation
	// but this doesn't work so well with non-numeric values. So I then need to 
	// work out what a non-numeric value should be passed. The below assumes that
	// any value that can't be converted to a float should be assumed to be one of
	// these special case values.
	// sucks, I know..
	var s=olds=(s==null || typeof s == 'undefined') ? this.get(prop) : s;
	s=parseFloat(!s ? 0 : s);
	var start=isNaN(s) ? olds : s;
	
	var c=e-s;
	
	var type=typeof t == 'string' ? t : this.tweentype;

	obj.a=new phocus.Animator(1,100,isNaN(l) ? this.defaultlength : l, type);
	obj.a.ontick(this,'tickprop',[prop,e,c,start]);
	obj.a.onend(this,'endprop',[prop,e,obj.num]);
	obj.a.run(d);
}
// wrapper animation kickers
// general animation wrapper 
// should add some error checking to this
// 20080131 - added cascading properties to this
$pr.animate=function(params)
{
	var end=0;
	var length=0;
	var delay=0;
	var type=this.tweentype;
	for(var i in params)
	{
		var op=params[i];
		var prop=i;
		start=op[0];
		end=isNaN(op[1]) ? end : op[1];
		length=isNaN(op[2]) ? length : op[2];
		delay=isNaN(op[3]) ? delay : op[3];
		type=!op[4] ? type : op[4];
		this.animateprop(prop,end,start,length,delay,type);
	}
}
// close ( [ length:Number [, start:Number [, delay: Number [, type:String ]]]] )
$pr.close=function(l,s,d,t)
{
	// setting the overflow property
	this.set('overflow','hidden');
	
	var s=(isNaN(s)) ? this.getdims().x : s;
	
	this.animateprop('w',1,s,l,d,t);
}
$pr.shrink=function(l,sw,sh,d,t)
{
	// setting the overflow property
	this.set('overflow','hidden');
	
	var sw=(isNaN(sw)) ? this.getdims().x : sw;
	var sh=(isNaN(sh)) ? this.getdims().y : sh;
	
	this.animateprop('w',1,sw,l,d,t);
	this.animateprop('h',1,sh,l,d,t);
}

$pr.fadein=function(l,d,t)
{
	this.animateprop('alpha',100,0,l,d,t);
}
$pr.fadeout=function(l,d,t)
{
	this.animateprop('alpha',0,100,l,d,t);
}

$pr.killanimations=function()
{
	for(var i in this.animatorindex)
		this.animatorindex[i].a.kill();
	this.cleanupanimate();
}

// event functionality
// over: Object, out:Object
// no error checking currently on the over and out objects
// error checking should be done at the point of property setting
$pr.setuprollinout=function(over,out)
{
	if(typeof this.eventindex != 'object')
		this.eventindex={};
	if(typeof this.eventnum == 'undefined')
		this.eventnum=0;

	var namespace='rio';

	this.delfxevent(namespace);
	
	// setting the initial values
	for(var i in out)
		this.set(i,out[i][1]);

	// using a closure here, should try to work out if there's any problems with doing so...
	var obj={};
	obj.namespace=namespace;
	obj.name='event'+this.eventnum;
	obj.over=over;
	obj.out=out;
	obj.rolledover=false;
	var onrollover=function(e)
	{
		if(obj.rolledover) return;
		
		var node=phocus.DOM.getNode(this);
		
		node.killanimations(); // should work out how to kill specific, related animations here
		node.animate(obj.over);
		
		phocus.DOM.stopEvent(e);
		
		obj.rolledover=true;
	}
	var onrollout=function(e)
	{
		if(!obj.rolledover)
			return;
	
		var node=phocus.DOM.getNode(this);

		node.killanimations();
		node.animate(obj.out);
		phocus.DOM.stopEvent(e);
		
		obj.rolledover=false;
	}
	
	obj._in=this.setevent('mouseover',onrollover);
	obj._out=this.setevent('mouseout',onrollout);
	this.eventindex['event'+this.eventnum++]=obj;
}
$pr.setupclick=function(click)
{
	if(typeof this.eventindex != 'object')
		this.eventindex={};
	if(typeof this.eventnum == 'undefined')
		this.eventnum=0;

	var namespace='cl';

	this.delfxevent(namespace);

	// using a closure here, should try to work out if there's any problems with doing so...
	var obj={};
	obj.namespace=namespace;
	obj.name='event'+this.eventnum;
	obj.click=click;
	var onclick=function(e)
	{
		if(obj.rolledover) return;
		
		var node=phocus.DOM.getNode(this);
		
		node.killanimations(); // should work out how to kill specific, related animations here
		node.animate(obj.click);
		
		phocus.DOM.stopEvent(e);
		
		obj.rolledover=true;
	}
	
	obj._in=this.setevent('mousedown',onclick);
	this.eventindex['event'+this.eventnum++]=obj;
}
$pr.delfxevent=function(namespace)
{
	for(var i in this.eventindex)
	{
		var op=this.eventindex[i];
		if(op.namespace==namespace)
		{
			switch(op.namespace)
			{
				case 'rio' :
					this.unsetevent(op._in);
					this.unsetevent(op._out);
					break;
			}
			op=null;
			delete op;
		}
	}
}

// ticker functions
$pr.tickhandlers=
{
	color:				'tickcolour',
	colour:				'tickcolour',
	backgroundColor:	'tickcolour',
	bgColour:			'tickcolour',
	bgColor:			'tickcolour'
};
$pr.tickprop=function(percentile,prop,end,change,startval)
{
	if(typeof this.tickhandlers[prop] != 'undefined')
		this[this.tickhandlers[prop]](percentile,prop,end,change,startval);
	else
	{
		var v=startval+(change/100*percentile);
		this.set(prop,v);
	}
}
$pr.tickcolour=function(percentile,prop,end,change,startval)
{
	var b=new phocus.Colour(startval);
	var e=new phocus.Colour(end);
	var dif=e.subtract(b);
	
	var nowcol=b.add(dif.scale(percentile));
	
	this.set(prop,nowcol.toString());
}
$pr.endprop=function(value,prop,endval,num)
{
	this.set(prop,endval);
	delete this.animatorindex['an'+num];
}

temp1=function(){};
$pr=temp1.prototype;
// over: Object, out:Object
// no error checking currently on the over and out objects
// error checking should be done at the point of property setting
$pr.setuprollinout=function(over,out)
{
	for(var i=this.nodeset.length-1;i>=0;i--)
		this.nodeset[i].setuprollinout(over,out);
}
$pr.setupclick=function(click)
{
	for(var i=this.nodeset.length-1;i>=0;i--)
		this.nodeset[i].setupclick(click);
}

phocus.Util.snapin(temp,phocus.DOM_node);
phocus.Util.snapin(temp1,phocus.DOM_nodeset);
temp=null;
temp1=null;
$pr=null;