Try using the AddTimer function and OnTimer() event for the delay.
Custom functions? Do you mean like this?
code:
function myFunctionName(Param1,Param2){
...
...
...
}
To call the function:
code:
myFunctionName("Param1 Value","Param2 Value");
Hope this is what you wanted