﻿var acquaOpened;
var energiaOpened;
var lavoroOpened;
var giuridicoOpened;
var sefitOpened;
var cercaOpened;
var chisiamoOpened;
var attivitaOpened;

var someOpened;

$(document).ready(function() {
    //imposto il valore del delay per l'evento
    var showDelay = 500;
    var showTimer = null;

    ResetState();

    $('#MENU_ROW').mouseleave(function() {
        if (someOpened == 0) {
            ResetState();
        }
    });

    $('.menu_middle').mouseleave(function() {
        ResetState();
    });

    $('#top_chisiamo').click(function() {
        if (chisiamoOpened == 0) {
            $('#menu_chisiamo').show('fast');
            chisiamoOpened = 1;
            someOpened = 1;
        }
        else {
            $('#menu_chisiamo').hide();
            chisiamoOpened = 0;
            someOpened = 0;
        }
    });

    $('#top_attivita').click(function() {
        if (attivitaOpened == 0) {
            $('#menu_attivita').show('fast');
            attivitaOpened = 1;
            someOpened = 1;
        }
        else {
            $('#menu_attivita').hide();
            attivitaOpened = 0;
            someOpened = 0;
        }
    });

    $('#top_acqua').click(function() {
        if (acquaOpened == 0) {
            $('#menu_acqua').show('fast');
            acquaOpened = 1;
            someOpened = 1;
        }
        else {
            $('#menu_acqua').hide();
            acquaOpened = 0;
            someOpened = 0;
        }
    });

    $('#top_energia').click(function() {
        if (energiaOpened == 0) {
            $('#menu_energia').show('fast');
            energiaOpened = 1;
            someOpened = 1;
        }
        else {
            $('#menu_energia').hide();
            energiaOpened = 0;
            someOpened = 0;
        }
    });

    $('#top_lavoro').click(function() {
        if (lavoroOpened == 0) {
            $('#menu_lavoro').show('fast');
            lavoroOpened = 1;
            someOpened = 1;
        }
        else {
            $('#menu_lavoro').hide();
            someOpened = 0;
            lavoroOpened = 0;
        }
    });

    $('#top_servizi').click(function() {
        if (serviziOpened == 0) {
            $('#menu_servizi').show('fast');
            serviziOpened = 1;
            someOpened = 1;
        }
        else {
            $('#menu_servizi').hide();
            serviziOpened = 0;
            someOpened = 0;
        }
    });

    $('#top_varie').click(function() {
        if (varieOpened == 0) {
            $('#menu_varie').show('fast');
            varieOpened = 1;
            someOpened = 1;
        }
        else {
            $('#menu_varie').hide();
            varieOpened = 0;
            someOpened = 0;
        }
    });

//    $('#top_cerca').click(function() {
//        if (cercaOpened == 0) {
//            $('#menu_cerca').show('fast');
//            cercaOpened = 1;
//            someOpened = 1;
//        }
//        else {
//            $('#menu_cerca').hide();
//            cercaOpened = 0;
//            someOpened = 0;
//        }
//    });

    $('#top_chisiamo').mouseenter(function() {
        ResetState();
        MarkChisiamo();
    });

    $('#top_attivita').mouseenter(function() {
        ResetState();
        MarkAttivita();
    });

    $('#top_acqua').mouseenter(function() {
        ResetState();
        $("#H_ENERGIA").hide()
        $("#H_LAVORO").hide()
        $("#H_MISSION").hide()
        $("#H_ACQUA").show()
        MarkAcqua();
    });

    $('#top_energia').mouseenter(function() {
        ResetState();
        $("#H_ACQUA").hide()
        $("#H_LAVORO").hide()
        $("#H_MISSION").hide()
        $("#H_ENERGIA").show()
        MarkEnergia();
    });

    $('#top_lavoro').mouseenter(function() {
        ResetState();
        $("#H_ACQUA").hide()
        $("#H_ENERGIA").hide()
        $("#H_MISSION").hide()
        $("#H_LAVORO").show()
        MarkLavoro();
    });
    $('#top_varie').mouseenter(function() {
        ResetState();
        MarkVarie();
    });

    $('#top_servizi').mouseenter(function() {
        ResetState();
        MarkServizi();
    });

    $('#top_cerca').mouseenter(function() {
        ResetState();
        MarkCerca();
    });

    $('#top_chisiamo_selected').click(function() {
        if (chisiamoOpened == 0) {
            $('#menu_chisiamo').show('fast');
            chisiamoOpened = 1;
            someOpened = 1;
        }
        else {
            $('#menu_chisiamo').hide();
            chisiamoOpened = 0;
            someOpened = 0;
        }
    });

    $('#top_attivita_selected').click(function() {
        if (attivitaOpened == 0) {
            $('#menu_attivita').show('fast');
            attivitaOpened = 1;
            someOpened = 1;
        }
        else {
            $('#menu_attivita').hide();
            attivitaOpened = 0;
            someOpened = 0;
        }
    });

    $('#top_acqua_selected').click(function() {
        if (acquaOpened == 0) {
            $('#menu_acqua').show('fast');
            acquaOpened = 1;
            someOpened = 1;
        }
        else {
            $('#menu_acqua').hide();
            acquaOpened = 0;
            someOpened = 0;
        }
    });

    $('#top_energia_selected').click(function() {
        if (energiaOpened == 0) {
            $('#menu_energia').show('fast');
            energiaOpened = 1;
            someOpened = 1;
        }
        else {
            $('#menu_energia').hide();
            energiaOpened = 0;
            someOpened = 0;
        }
    });

    $('#top_lavoro_selected').click(function() {
        if (lavoroOpened == 0) {
            $('#menu_lavoro').show('fast');
            lavoroOpened = 1;
            someOpened = 1;
        }
        else {
            $('#menu_lavoro').hide();
            lavoroOpened = 0;
            someOpened = 0;
        }
    });

    $('#top_varie_selected').click(function() {
        if (varieOpened == 0) {
            $('#menu_varie').show('fast');
            varieOpened = 1;
            someOpened = 1;
        }
        else {
            $('#menu_varie').hide();
            varieOpened = 0;
            someOpened = 0;
        }
    });

    $('#top_servizi_selected').click(function() {
        if (serviziOpened == 0) {
            $('#menu_servizi').show('fast');
            serviziOpened = 1;
            someOpened = 1;
        }
        else {
            $('#menu_servizi').hide();
            serviziOpened = 0;
            someOpened = 0;
        }
    });

//    $('#top_cerca_selected').click(function() {
//        if (cercaOpened == 0) {
//            $('#menu_cerca').show('fast');
//            cercaOpened = 1;
//            someOpened = 1;
//        }
//        else {
//            $('#menu_cerca').hide();
//            cercaOpened = 0;
//            someOpened = 0;
//        }
//    });

    $('#top_chisiamo_selected').mouseenter(function() {
        ResetState();
        MarkChisiamo();
    });

    $('#top_attivita_selected').mouseenter(function() {
        ResetState();
        MarkAttivita();
    });

    $('#top_acqua_selected').mouseenter(function() {
        ResetState();
        $("#H_ENERGIA").hide()
        $("#H_LAVORO").hide()
        $("#H_MISSION").hide()
        $("#H_ACQUA").hide()
        MarkAcqua();
    });

    $('#top_energia_selected').mouseenter(function() {
        ResetState();
        $("#H_ACQUA").hide()
        $("#H_LAVORO").hide()
        $("#H_MISSION").hide()
        $("#H_ENERGIA").show()
        MarkEnergia();
    });

    $('#top_lavoro_selected').mouseenter(function() {
        ResetState();
        $("#H_ACQUA").hide()
        $("#H_ENERGIA").hide()
        $("#H_MISSION").hide()
        $("#H_LAVORO").show()
        MarkLavoro();
    });


    $('#top_varie_selected').mouseenter(function() {
        ResetState();
        MarkVarie();
    });

    $('#top_servizi_selected').mouseenter(function() {
        ResetState();
        MarkServizi();
    });

    $('#top_cerca_selected').mouseenter(function() {
        ResetState();
        MarkCerca();
    });
});

function ResetState() {
    acquaOpened = 0;
    energiaOpened = 0;
    lavoroOpened = 0;
    serviziOpened = 0;
    varieOpened = 0;
    cercaOpened = 0;
    chisiamoOpened = 0;
    attivitaOpened = 0;
    someOpened = 0;
    $('#top_chisiamo').css('background-position', '-9px -12px');
    $('#top_attivita').css('background-position', '-135px -12px');
    $('#top_acqua').css('background-position', '-261px -12px');
    $('#top_energia').css('background-position', '-387px -12px');
    $('#top_lavoro').css('background-position', '-513px -12px');
    $('#top_varie').css('background-position', '-639px -12px');
    $('#top_servizi').css('background-position', '-765px -12px');
    $('.top_cerca').css('background-position', '-891px -12px');
    $('#menu_chisiamo').hide();
    $('#menu_attivita').hide();
    $('#menu_acqua').hide();
    $('#menu_energia').hide();
    $('#menu_lavoro').hide();
    $('#menu_varie').hide();
    $('#menu_servizi').hide();
    $('#menu_cerca').hide();
    
    $("#H_ACQUA").hide()
    $("#H_ENERGIA").hide()
    $("#H_LAVORO").hide()
    $("#H_MISSION").show()
    
    if (document.getElementById("top_acqua_selected") != null) {
        $("#H_MISSION").hide()
        $("#H_ACQUA").show()
    }
    if (document.getElementById("top_energia_selected") != null) {
        $("#H_MISSION").hide()
        $("#H_ENERGIA").show()
    }
    if (document.getElementById("top_lavoro_selected") != null) {
        $("#H_MISSION").hide()
        $("#H_LAVORO").show()
    }
}

function MarkChisiamo() {
    $('#top_chisiamo').css('background-position', '-9px -44px');
    cercaOpened = 0;
    someOpened = 0;
}
function MarkAttivita() {
    $('#top_attivita').css('background-position', '-135px -44px');
    cercaOpened = 0;
    someOpened = 0;
}
function MarkAcqua() {
    $('#top_acqua').css('background-position', '-261px -44px');
    acquaOpened = 0;
    someOpened = 0;
}
function MarkEnergia() {
    $('#top_energia').css('background-position', '-387px -44px');
    energiaOpened = 0;
    someOpened = 0;
}
function MarkLavoro() {
    $('#top_lavoro').css('background-position', '-513px -44px');
    lavoroOpened = 0;
    someOpened = 0;
}
function MarkVarie() {
    $('#top_varie').css('background-position', '-639px -44px');
    sefitOpened = 0;
    someOpened = 0;
}
function MarkServizi() {
    $('#top_servizi').css('background-position', '-765px -44px');
    giuridicoOpened = 0;
    someOpened = 0;
}
function MarkCerca() {
    $('.top_cerca').css('background-position', '-891px -44px');
    cercaOpened = 0;
    someOpened = 0;
}






