To detect retina display use window.devicePixelRatio
.
To detect iPad version use data at UA. Watch this answer. This list of iDevices UAs would helps you to find solution. As you see each model has it's own build number, you can use it for your purposes.