I went looking through Raphael.js\'s source code to find out how he converted RGB values to HSB. I found out the function he did it in and I was in the process
Raphael.js
Yes, it's right (apart from capitalisation differences). Yet, it may be cleaner written without any parentheses, readable as elseif:
if (C == 0) h = null; else if (V == r) h = (g - b) / C; else if (V == g) h = (b - r) / C + 2; else h = (r - g) / C + 4;