﻿
$(document).ready(function () {

    var agent = navigator.userAgent.toLowerCase();

    // 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;

    // iPhone and iPad can be reliably identified with the navigator.platform
    // string, which is currently only available on these devices.
    var iOS = (navigator.platform.indexOf("iPhone") != -1) || (navigator.platform.indexOf("iPad") != -1) ? true : false;

    // If the user agent string contains "android" then it's Android. If it
    // doesn't but it's not another browser, not an iOS device and we're in
    // a mobile and touch OS then we can be 99% certain that it's Android.
    var android = (agent.indexOf("android") != -1) || (!iOS && touchOS && mobileOS) ? true : false;

    if (mobileOS || touchOS || iOS || android) {

        // rimuovo gli hover
        $('.hoverable').removeClass('hoverable');

        var _fnCloseTapped = function () {
            $('.top .menu .tapped').removeClass('tapped').children('ul').css({ 'display': 'none' });
        }

        $('.top .menu > li > ul').bind('click', function (ev) {
            ev.stopPropagation();
        });

        $('.top .menu > li > a').bind('click', function (ev) {
            ev.preventDefault();
            ev.stopPropagation();
            var reopen = !$(this).parent().hasClass('tapped');
            _fnCloseTapped();
            if (reopen) {
                $(this).parent().addClass('tapped').children('ul').css({ 'display': 'block' });
            }
        });

        $('html, body').bind('click', function (ev) {
            _fnCloseTapped();
        });

        $(window).bind('click', function (ev) {
            _fnCloseTapped();
        });

    }

    if ($('#wrap').hasClass('container-special-home')) {

        // sempre aperti in caso di home speciale prodotti
        $('.leftMenu > ul > li > ul').css('display', 'block');
        $('.leftMenu > ul > li > ul > li').parent().css('display', 'block');

    }
    else {

        // se ho un terzo livello current, aggiorno il parent con la voce current per la selezione
        $('.leftMenu > ul > li > ul > li > ul > li.current').parent().parent().addClass('current');

        // apro il corrente
        $('.leftMenu > ul > li.current > ul').css('display', 'block');
        $('.leftMenu > ul > li > ul > li.current').parent().css('display', 'block');

    }

    // fogli informativi
    $('a[href*="web.cr-altogarda.net"]').click(function (ev) {
        ev.preventDefault();
        ShowPdf(null, null, $(this).attr('href'));
    });

    // banca online a nuova finestra
    $('.onlineBank a').click(function (ev) {
        ev.preventDefault();
        window.open($(this).attr('href'));
    });

});

