/*
   by Brandon Tearse
   Designed for use with the TreeGenes Database Interface.
 */


var Animations = new function() {

    //function crossFade(message)
    this.crossFade = function(message)
    {
	var clickedIndex = message.currentTarget.panePtr.index;
	WM.activateWindow(clickedIndex);
    }

    this.fadeOut = function(index)
    { 
	if(Options.bgFade)
	{
	    var o = WM.byIndex(index);
	    o.shield = container.appendChild(document.createElement('div'));
	    dojo.style.setOpacity(o.shield,0.5);
	    o.shield.style.backgroundColor='#fff';
	    o.shield.style.padding='1px';
	    o.shield.style.position='absolute';
	    o.shield.style.left=o.domNode.style.left;
	    o.shield.style.right=o.domNode.style.right;
	    o.shield.style.top=o.domNode.style.top;
	    o.shield.style.bottom=o.domNode.style.bottom;
	    o.shield.style.width=o.domNode.style.width;
	    o.shield.style.height=o.domNode.style.height;
	    o.shield.style.zIndex=o.domNode.style.zIndex;
	    eval('o.shield.clickfun = function(){WM.activateWindow(' + index + ');}');
	    dojo.event.connect(o.shield,"onclick",o.shield.clickfun);     
	}

	//dojo.lfx.html.fadeOut(this.byIndex(index).domNode,300).play(); 
    }
    
    this.fadeIn = function(index)
    { 
	if(Options.bgFade)
	{
	    var o = WM.byIndex(index);
	    if(o.shield)
	    {
		container.removeChild(o.shield);;
		delete(o.shield);
	    }
	}
	//	dojo.lfx.html.fadeIn(this.byIndex(index).domNode,300).play(); 
    }
    
    this.fadeBack = function(index)
    { 
	this.fadeOut(index);
//	this.fadeBack_engine(this.byIndex(index).domNode,300).play(); 
    }

    this.fadeBack_engine = function(nodes, duration, easing, callback)
    {
	nodes = dojo.lfx.html._byId(nodes);
	dojo.lfx.html._makeFadeable(nodes);
	var anim = dojo.lfx.propertyAnimation(nodes, [
		{       property: "opacity",
			start: dojo.style.getOpacity(nodes[0]),
			end: 0.5 } ], duration, easing);
	if(callback){
	    var oldOnEnd = (anim["onEnd"]) ? dojo.lang.hitch(anim, "onEnd") : function(){};
	    anim.onEnd = function(){ oldOnEnd(); callback(nodes, anim); };
	}
	return anim;
    }

}
