
/**********************************************************************************************************************************************/
/* CONTROLLO MOBILE ***************************************************************************************************************************/
/**********************************************************************************************************************************************/

var _isMobile = function (ua) {

    ua = ua.toLowerCase();
    //var orientation = '';
    //document.documentElement.ontouchstart = '';

    // detect series60, symbian e windows mobile. alcuni nokia iniziano con NOKIA
    var isOther = ua.match(/(series60|symbian|windows ce)/gi) != null || ua.indexOf('nokia') == 0;

    // detect blackberry playbook (Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.8+)
    var isPlaybook = ua.match(/(playbook)/gi) != null;

    // detect blackberry
    var isBlackberry = ua.match(/(blackberry)/gi) != null && !isPlaybook;

    // detect ipad
    var isIpad = ua.match(/(ipad)/gi) != null;

    // detect iphone / ipod touch
    var isIphone = ua.match(/(iphone|ipod)/gi) != null && !isIpad;

    // detect kindle
    var isKindle = ua.match(/(kindle)/gi) != null;
    var kindleVersion = 0;
    if (/kindle[\/\s](\d+\.\d+)/.test(ua)) {
        kindleVersion = RegExp.$1;
    }

    // detect general android
    var isAndroid = ua.match(/android/gi) != null;

    // If the screen orientation is defined we are in a modern mobile OS
    var mobileOS = typeof orientation != 'undefined' ? true : false;

    // If touch events are defined we are in a modern touch screen OS
    var touchOS = ('ontouchstart' in document.documentElement) ? true : false;

    // detect most android tablets
    var isAndroidTablet = isAndroid && ua.match(/(gt-p1000|gt-p7100|gt-p7300|gt-p7500|gt-p7510|xoom|tsb_cloud_companion|transformer|htc flyer|olipad|lg-v900|sony tablet|dell streak|s7 build|ziio)/gi) != null;

    // detect ambiguous tablet
    var isAmbiguousTablet = (ua.match(/(a500|a100)/gi) != null && ua.match(/(hri66)/gi) != null) || (ua.match(/(a70|a101)/gi) != null && ua.match(/(eclair|cupcake)/gi) != null);

    // detect android smartphone
    var isAndroidSmartphone = isAndroid && mobileOS && touchOS && !isAndroidTablet && !isAmbiguousTablet;

    // kindle < 3.0, android smartphone, blackberry, symbian, iphone are mobile devices
    return ((isKindle && kindleVersion < 3.0) || isAndroidSmartphone || isOther || isBlackberry || isIphone) && !isPlaybook && !isAndroidTablet && !isAmbiguousTablet && !isIpad;

}

/**********************************************************************************************************************************************/
/**********************************************************************************************************************************************/

