Help Modifying Fade Script

I have a fade out script that I like a lot, but I wanted to change one thing.

When I click an action, I want the script to run on the div (which I’m currently doing), but when a hidden frame page finishes loading, I want it to reverse the fade and fade back in. So, either stop the fade out in progress and then fade back in from that point or, if the fade has completed to zero, fade in the div layer all the way again.

Here is the script:


// @name      Slowly Fade
// @version   0.88
// @author    Richard D. LeCour
// @namespace http://www.richardsramblings.com/?p=486

var opacity = 96; // Avoid starting at 100% due to Mozilla bug
var slowly = {
	fade : function (id) {
		this.fadeLoop(id, opacity);
	},
	fadeLoop : function (id, opacity) {
		var o = document.getElementById(id);
		if (opacity >= 5) {
			slowly.setOpacity(o, opacity);
			opacity -= 4;
			window.setTimeout("slowly.fadeLoop('" + id + "', " + opacity + ")", 50);
		} else {
			o.style.display = "none";
		}
	},
	setOpacity : function (o, opacity) {
		o.style.filter = "alpha(style=0,opacity:" + opacity + ")";	// IE
		o.style.KHTMLOpacity = opacity / 100;				// Konqueror
		o.style.MozOpacity = opacity / 100;					// Mozilla (old)
		o.style.opacity = opacity / 100;					// Mozilla (new)
	}
}

I call the script as I send a GET request to a hidden frame on page (which swaps out a div on the page with innerHTML. The div fades out beautifully and I edited the script to fade it back in automatically once it gets to opacity of 4. But, I’d rather have the script fade back in once a call has been made to javascript to reverse the fade. Right now I am just guessing when the page might be finished loading, but would like to be more exact on the switch of fade. So the iframe loads and does:

parent.javascriptaction(‘divlayer’);

I have everything set to go but the script (and call) to do the reverse.

All help appreciated.

Cheers
Ryan

Maybe I can make this question a bit easier. I just want to have a secondary function for fading back in.

So, to fade out I’ve been doing


onClick="slowly.fade('divid');"

How can I add to this code so if I did:


onClick="slowly.appear('divid');"

The div layer will then return.

Suggestions?
Thanks
Ryan

onclick=“faded?slowly.appear(‘divid’),faded=0:slowly.fade(‘divid’),faded=1;”

I tried adding that to the onclick but got:

Error: missing : in conditional expression
Line: 1, Column: 37
Source Code:
faded?slowly.appear(‘friendactivity’),faded=0:slowly.fade(‘friendactivity’),faded=1;

Thanks
Ryan

Do I need to edit the primary function too?

Cheers
Ryan

Nevermind. I rewrote it and got it to work.

Thx
Ryan