$(document).ready(
    function() {
        firstShow();
        setListenerVipMenu();
        setListenerBtnOpenCloseMenu();
    });

var bEnableMenu = true;
var bMenuOpen = false;
var bCallAjax = false;

function firstShow() {
    $('.contentBg').fadeIn(600, function() {
        $('.wrapSection').css({ 'visibility': 'visible' });
        setTimeout(showIntroMenu, 2000);
    });
}

function showIntroMenu() {
    $('.modelMenuMask').css({ 'height': '230px' });
    $('.modelMenuVoices').animate({ 'top': '0px', easing: "easeOutQuad" }, 500, function() {
        $('#btnOpenCloseMenu').attr({ 'class': 'collapse up' });
        $('#btnOpenCloseMenu').attr({ 'title': 'Chiudi il menu' });
        bMenuOpen = true;
        bEnableMenu = true;
        //setTimeout(closeIntroMenu, 4000);
    }); 
}

function closeIntroMenu() {
    $('.modelMenuVoices').animate({ 'top': '-210px', easing: "easeOutQuad" }, 500, function() {
        $('.modelMenuMask').css({ 'height': '6px' });
        $('#btnOpenCloseMenu').attr({ 'class': 'collapse down' });
        $('#btnOpenCloseMenu').attr({ 'title': 'Apri il menu' });
    });
}

function showContentNoFade() {
    $('.contentBg').fadeIn(600, function() {
        $('.wrapSection').css({ 'visibility': 'visible' });
    });
}

function showContent() {
    $('.contentBg').fadeIn(600, function() {
        setTimeout(function() {
            $('.contentBg').fadeTo(600, 0.2, function() {
                $('.wrapSection').css({ 'visibility': 'visible' });
            });
        }, 1000);
    });
}

function showMenu() {
    bMenuOpen = true;
    $('.modelMenuMask').css({ 'width': '221px' });
    $('.modelMenuMask').css({ 'height': '230px' });
    $('.modelMenuVoices').animate({ 'top': '0px', easing: "easeOutQuad" }, 500, function() {
        $('#btnOpenCloseMenu').attr({ 'class': 'collapse up' });
        $('#btnOpenCloseMenu').attr({ 'title': 'Chiudi il menu' });
        bEnableMenu = true;
    });
}

function closeMenu() {
    bMenuOpen = false;
    $('.modelMenuVoices').animate({ 'top': '-210px', easing: "easeOutQuad" }, 500, function() {
        $('.modelMenuMask').css({ 'height': '6px' });
        $('#btnOpenCloseMenu').attr({ 'class': 'collapse down' });
        $('#btnOpenCloseMenu').attr({ 'title': 'Apri il menu' });
        bEnableMenu = true;
    });
}

function setListenerBtnOpenCloseMenu() {
    $('#btnOpenCloseMenu').bind('click', function() {
        if (bEnableMenu) {
            bEnableMenu = false;
            if (bMenuOpen) {
                closeMenu();
            } else {
                showMenu();
            }
        }
    });
}

function setListenerVipMenu() {
    $('.lnkContent').bind('click', function() {
        if (bCallAjax) {
            var objCurentLink = $(this);
            var sCurentLinkLink = $(this).attr('href');
            var sCurentLinkLinkSend = sCurentLinkLink + '?GetSectionContent=true';
            objCurentLink.attr({ 'href': 'javascript:;' });
            $('.sectionContent').load(sCurentLinkLinkSend, null, function() {
                bMenuOpen = false;
                //closeMenu();
                objCurentLink.attr({ 'href': sCurentLinkLink });
                showContent();
            });
        }
    });
    $('.lnkContentNoFade').bind('click', function() {
        if (bCallAjax) {
            var objCurentLink = $(this);
            var sCurentLinkLink = $(this).attr('href');
            var sCurentLinkLinkSend = sCurentLinkLink + '?GetSectionContent=true';
            objCurentLink.attr({ 'href': 'javascript:;' });
            $('.sectionContent').load(sCurentLinkLinkSend, null, function() {
                bMenuOpen = false;
                //closeMenu();
                objCurentLink.attr({ 'href': sCurentLinkLink });
                showContentNoFade();
            });
        }
    });
}
