/*
Code by: Alex Kuzmenok
http://graphicmaniacs.com

Freely use and modify 
*/

function BrowserDetector() {
  this.ua = navigator.userAgent;
  this.iIE = false;
  this.iFF = false;
  this.iOpera = false;
  this.iChrome = false;
  this.iSafari = false;
  this.iMaxthon = false;
  this.iBrowser = '';
  this.iVersion = '';
  this.iOS = '';
  this.iOSVersion = '';
  
  this.go = function() {
    var info = this.ua;
    
    v = null;
    if (v = info.match(/MAXTHON\s(\S*)\)/)) {
      this.iBrowser = 'Maxthon';
      this.iMaxthon = true;
      this.iVersion = v[1];
    } else if (v = info.match(/MSIE\s(\S*);/)) { // IE check
      this.iBrowser = 'Microsoft Internet Explorer';
      this.iIE = true;
      this.iVersion = v[1];
    } else if (v = info.match(/Firefox\/(\S*)/)) { // FF check
      this.iBrowser = 'Mozilla Firefox';
      this.iFF = true;
      this.iVersion = v[1];
    } else if (info.match(/Opera/)) { // Opera check
      v = info.match(/Version\/(\S*)/);
      this.iBrowser = 'Opera';
      this.iOpera = true;
      this.iVersion = v[1];
    } else if (v = info.match(/Chrome\/(\S*)/)) { // Chrome check
      this.iBrowser = 'Google Chrome';
      this.iChrome = true;
      this.iVersion = v[1];
    } else if (v = info.match(/Version\/(\S*) Safari\/(\S*)/)) { // Safari 
      this.iBrowser = 'Apple Safari';
      this.iSafari = true;
      this.iVersion = v[1];
    } else if (v = info.match(/Namoroka\/(\S*)/)) {
      this.iBrowser = 'Namoroka';
      this.iVersion = v[1];
    } else if (v = info.match(/BonEcho\/(\S*)/)) {
      this.iBrowser = 'BonEcho';
      this.iVersion = v[1];
    }
    
    if (v = info.match(/Windows NT (\S*);/)) {
      this.iOS = 'Microsoft Windows';
      if (v[1] == '4.0')
        this.iOSVersion = 'NT 4.0';
      else if (v[1] == '5.0')
        this.iOSVersion = '2000';
      else if (v[1] == '5.1')
        this.iOSVersion = 'XP';
      else if (v[1] == '5.2')
        this.iOSVersion = 'XP 64bit / Server 2003';
      else if (v[1] == '6.0')
        this.iOSVersion = 'Vista / Server 2008';
      else if (v[1] == '6.1')
        this.iOSVersion = '7 / Server 2008 R2';
    } else if (v = info.match(/Intel Mac ([\w .]*)/)) {
      this.iOS = 'Intel Mac';
      this.iOSVersion = v[1];
    } else if (v = info.match(/Linux ([\w .]*)/)) {
      this.iOS = 'Linux';
      this.iOSVersion = v[1];
    }
    
  }
  
  this.isFF = function() {
    return this.iFF;
  }
  
  this.isIE = function() {
    return this.iIE;
  }
  
  this.isOpera = function() {
    return this.iOpera;
  }
  
  this.isChrome = function() {
    return this.iChrome;
  }
  
  this.isSafari = function() {
    return this.iSafari;
  }
  
  this.browserName = function() {
    return this.iBrowser;
  }
  
  this.browserVersion = function() {
    return this.iVersion;
  }
  
  this.browserString = function() {
    return this.browserName()+' '+this.browserVersion();
  }
  
  this.OSName = function() {
    return this.iOS;
  }
  
  this.OSVersion = function() {
    return this.iOSVersion;
  }
  
  this.OSString = function() {
    return this.OSName()+' '+this.OSVersion();
  }
  
  this.go();
}
