http://www.flipcode.com/archives/Sav...unctions.shtml

http://www.dreamincode.net/forums/showtopic67586.htm

Hope this helps