/**
 * @author	Tim Wittenberg
 * @copyright	GneX
 * @license	techNex License - Plugin (TNLP) <http://technex.org/license/plugin/>
 */
function Tapatalk() {
	/**
	 * Detect phone for tapatalk support.
	 */
	this.detectPhone = function() {
    // check cookies
    if (document.cookie.indexOf('tapatalk_redirect=false') < 0) {
      // check browser
      if (!navigator.userAgent.match(/Opera/i) && !navigator.userAgent.match(/Dolphin/i)) {
        // iphone and ipod touch
        if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
          // set cookies
          this.setCookies();
          
          // check support
          if (confirm(tapatalkLanguage['iphone'])) {
            window.location = 'http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=307880732&mt=8';
          }
        }
        // ipad
        else if (navigator.userAgent.match(/iPad/i)) {
          // set cookies
          this.setCookies();
          
          // check support
          if (confirm(tapatalkLanguage['ipad'])) {
            window.location = 'http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=307880732&mt=8';
          }
        }
        // android phone
        else if (navigator.userAgent.match(/android/i)) {
          // set cookies
          this.setCookies();
          
          // check support
          if (confirm(tapatalkLanguage['androidphone'])) {
            window.location = 'market://details?id=com.quoord.tapatalkpro.activity';
          }
        }
        // windows phone
        else if ((navigator.userAgent.match(/Windows Phone/i)) || (navigator.userAgent.match(/ZuneWP7/i))) {
          // set cookies
          this.setCookies();
          
          // check support
          if (confirm(tapatalkLanguage['windowsphone'])) {
            window.location = 'zune://navigate/?phoneAppID=ac6eeb5d-e7da-df11-a844-00237de2db9e';
          }
        }
        // webos phone
        else if (navigator.userAgent.match(/webOS/i)) {
          // set cookies
          this.setCookies();
          
          // check support
          if (confirm(tapatalkLanguage['webosphone'])) {
            window.location = 'http://developer.palm.com/appredirect/?packageid=com.newnessdevelopments.forums';
          }
        }
      }
    }
	}
	
	/**
	 * Set cookies for tapatalk support.
	 */
	this.setCookies = function() {
    // get default values
    var date = new Date();
    var days = 90;
    
    // set time
    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
    var expires = "; expires=" + date.toGMTString();
    
    // set cookie
    document.cookie = "tapatalk_redirect=false" + expires; 
	}
}
