// Tw Effects API - built over mootools Fx package - (c) www.timewalker.net
var Tw = new TwAPI();
function TwAPI(){
	this.popUpEffectMap   = new Object();
	this.originalStateMap = new Object();
	this.effectList       = new Array();
	this.stateList        = new Array();
}
TwAPI.prototype.backupState=function(id){
	var obj = $(id);
	var s = { id: obj.id , width: obj.width , height: obj.height , x: $(obj.id).getStyle('left').toInt() , y: $(obj.id).getStyle('top').toInt() };
	this.originalStateMap[id] = s;
	this.stateList.push(s);
}
TwAPI.prototype.restoreState=function(id){
	var obj = $(id);
	var s = this.originalStateMap[id];
	obj.setStyle('width',s.width);
	obj.setStyle('height',s.height);
	obj.setStyle('left',s.x+"px");
	obj.setStyle('top',s.y+"px");
}
TwAPI.prototype.popUpEffectOnEnter=function(e){
	var obj = Tw.getEventTarget(e);
    var state = Tw.originalStateMap[obj.id];
	Tw.popUpEffectMap[obj.id].start({width:state.width*1.2,
                                     height:state.height*1.2,
                                     left:state.x-0.1*state.width,
                                     top:state.y-0.1*state.height});
}
TwAPI.prototype.popUpEffectOnLeave=function(e){
	var obj = Tw.getEventTarget(e);
	var state = Tw.originalStateMap[obj.id];
	Tw.popUpEffectMap[obj.id].start({width:state.width,
                                     height:state.height,
                                     left:state.x,
                                     top:state.y});
}
TwAPI.prototype.addPopUpBehavior=function(id){
	this.backupState(id);
    $(id).addEvent('mouseover',this.popUpEffectOnEnter);
	$(id).addEvent('mouseout',this.popUpEffectOnLeave);
	var e = new Fx.Morph(id,{duration:250,transition:Fx.Transitions.Quad.easeOut,fps:30,link:'cancel'});
	this.popUpEffectMap[id] = e;
	this.effectList.push(e);
}
TwAPI.prototype.getEventTarget=function(e){
	var t;
	if (!e) var e = window.event;
	if (e.target) t = e.target;
	else if (e.srcElement) t = e.srcElement;
	if (t.nodeType == 3) // defeat Safari bug
		t = targ.parentNode;
	return t;
}
TwAPI.prototype.reset=function(){
	$each(this.effectList,function(e) { e.cancel(); });
	$each(this.stateList,function(s) { Tw.restoreState(s.id); });
	this.stateList = new Array();
}

