var Class = require('./Class')

var mobileRegex = /mobile/i;

var Client = Class(function() {
	
	this.init = function(userAgent) {
		this._userAgent = userAgent
		this._parseBrowser()
		this._parseOS()
		this._parseDevice()
	}
	
	this._parseBrowser = function() {
		(this.isChrome = this._isBrowser('Chrome'))
			|| (this.isFirefox = this._isBrowser('Firefox'))
			|| (this.isIE = this._isBrowser('MSIE'))
			|| (this.isSkyfire = this._isBrowser('Skyfire', 'Skyfire')) // Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Safari/530.17 Skyfire/2.0
			|| (this.isSafari = this._isBrowser('Safari', 'Version'))
			|| (this.isOpera = this._isBrowser('Opera', 'Version'))
		
		if (this.isOpera) {
			if (this._userAgent.match('Opera Mini')) { this.isOperaMini = true } // Opera mini is a cloud browser - Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/ADR-1110171336; U; en) Presto/2.9.201 Version/11.50
		}
		
		try {
			document.createEvent("TouchEvent")
			this.isTouch = true
		} catch (e) {
			this.isTouch = false
		}
	}
	
	this._parseDevice = function() {
		((this.isIPhone = this._is('iPhone'))
			|| (this.isIPad = this._is('iPad'))
			|| (this.isIPod = this._is('iPod')))
		
		if (this.isOpera && this._userAgent.match('Opera Mobi')) { this.isMobile = true } // Opera mobile is a proper mobile browser - Opera/9.80 (Android; Opera Mini/6.5.26571/ 26.1069; U; en) Presto/2.8.119 Version/10.54
		if (this.isSkyfire) { this.isMobile = true }
		if (this.isIPhone) { this.isMobile = true }
		if (this.isAndroid) {
			if (this._userAgent.match(mobileRegex)) { this.isMobile = true }
			if (this.isFirefox) { this.isMobile = true } // Firefox Android browsers do not seem to have an indication that it's a phone vs a tablet: Mozilla/5.0 (Android; Linux armv7l; rv:7.0.1) Gecko/20110928 Firefox/7.0.1 Fennec/7.0.1
		}
		
		this.isTablet = this.isIPad
	}
	
	this._parseOS = function() {
		this.isAndroid = this._isBrowser('Android', 'Version')
		if (this.isSafari) {
			this.isIOS = (this.isIPhone || this.isIPad || this.isIPod)
			if (this.isIOS) { this.osVersion = parseFloat(this._userAgent.match(/ OS (\d+_\d+)/)[1].replace('_', '.'), 10) }
		}
		return this
	}
	
	this.isQuirksMode = function(doc) {
		// in IE, if compatMode is undefined (early ie) or explicitly set to BackCompat, we're in quirks
		return this.isIE && (!doc.compatMode || doc.compatMode == 'BackCompat')
	}
	
	this._isBrowser = function(name, versionString) {
		if (!this._is(name)) { return false }
		if (versionString) { var index = agent.indexOf(versionString) }
		this.version = parseFloat(this._userAgent.substr(index + (versionString || name).length + 1))
		this.name = name
		return true
	}

	this._is = function(name) {
		return (this._userAgent.indexOf(name) >= 0)
	}
})

if (typeof window != 'undefined') { module.exports = new Client(window.navigator.userAgent) }
else { module.exports = {} }

module.exports.parse = function(userAgent) { return new Client(userAgent) }

@@ -181,26 +181,8 @@
 r()%0A
-%09%09this._parseOS()%0A
 %09%09th
@@ -1207,24 +1207,145 @@
 iPod')))%0A%09%09%0A
+%09%09this.isAndroid = this._isBrowser('Android', 'Version')%0A%09%09this.isIOS = (this.isIPhone %7C%7C this.isIPad %7C%7C this.isIPod)%0A%09%09%0A
 %09%09if (this.i
@@ -2009,319 +2009,8 @@
 %7D%0A%09%0A
-%09this._parseOS = function() %7B%0A%09%09this.isAndroid = this._isBrowser('Android', 'Version')%0A%09%09if (this.isSafari) %7B%0A%09%09%09this.isIOS = (this.isIPhone %7C%7C this.isIPad %7C%7C this.isIPod)%0A%09%09%09if (this.isIOS) %7B this.osVersion = parseFloat(this._userAgent.match(/ OS (%5Cd+_%5Cd+)/)%5B1%5D.replace('_', '.'), 10) %7D%0A%09%09%7D%0A%09%09return this%0A%09%7D%0A%09%0A
 %09thi

Move the OS parsing into parseDevice. They're too tightly coupled