http://www.hawkee.com/snippet.php?snippet_id=1692
Odd how your script is very similar to the one above...