

$(document).ready(function() {
    $(".menuoverstate").each(function(i) {

        preload_image = new Image();
        preload_image.src = this.src.replace(".jpg", "_o.jpg");

        $(this).hover(
            function() {
                if (this.src.indexOf("_o.jpg") == -1) {
                    this.src = this.src.replace(".jpg", "_o.jpg");
                }

            },

            function() {
                this.src = this.src.replace("_o.jpg", ".jpg");

            });

    }
        );
});

var aboutStates = { "menuAbout": false, "menuAboutDropDown": false };

var railStates = { "menuRail": false, "menuRailDropDown": false };

var constructionStates = { "menuConstruction": false, "menuConstructionDropDown": false };

var roadStates = { "menuRoad": false, "menuRoadDropDown": false };

var environmentalStates = { "menuEnvironmental": false, "menuEnvironmentalDropDown": false };

var trainingStates = { "menuTraining": false, "menuTrainingDropDown": false };

var recruitmentStates = { "menuRecruitment": false, "menuRecruitmentDropDown": false };

var newsStates = { "menuNews": false, "menuNewsDropDown": false };

var TRANSITION_SPEED = 100;

function checkAboutMenu() {

    if (aboutStates["menuAbout"] == false && aboutStates["menuAboutDropDown"] == false) {
        jQuery("#menuAboutDropDown").slideUp(TRANSITION_SPEED);

    }
}

function checkRailMenu() {

    if (railStates["menuRail"] == false && railStates["menuRailDropDown"] == false) {
        jQuery("#menuRailDropDown").slideUp(TRANSITION_SPEED);

    }
}

function checkConstructionMenu() {

    if (constructionStates["menuConstruction"] == false && constructionStates["menuConstructionDropDown"] == false) {
        jQuery("#menuConstructionDropDown").slideUp(TRANSITION_SPEED);

    }
}

function checkRoadMenu() {

    if (roadStates["menuRoad"] == false && roadStates["menuRoadDropDown"] == false) {
        jQuery("#menuRoadDropDown").slideUp(TRANSITION_SPEED);

    }
}

function checkEnvironmentalMenu() {

    if (environmentalStates["menuEnvironmental"] == false && environmentalStates["menuEnvironmentalDropDown"] == false) {
        jQuery("#menuEnvironmentalDropDown").slideUp(TRANSITION_SPEED);

    }
}

function checkTrainingMenu() {

    if (trainingStates["menuTraining"] == false && trainingStates["menuTrainingDropDown"] == false) {
        jQuery("#menuTrainingDropDown").slideUp(TRANSITION_SPEED);

    }
}

function checkRecruitmentMenu() {

    if (recruitmentStates["menuRecruitment"] == false && recruitmentStates["menuRecruitmentDropDown"] == false) {
        jQuery("#menuRecruitmentDropDown").slideUp(TRANSITION_SPEED);

    }
}

function checkNewsMenu() {

    if (newsStates["menuNews"] == false && newsStates["menuNewsDropDown"] == false) {
        jQuery("#menuNewsDropDown").slideUp(TRANSITION_SPEED);

    }
}

jQuery(document).ready(function() {

    // About menu dropdowns //

    jQuery("#menuAbout").hover(function() {
        aboutStates["menuAbout"] = true;

        var src = jQuery("#menuAbout").attr("src");

        if (aboutStates["menuAboutDropDown"] == false) {
            jQuery("#menuAboutDropDown").slideDown(TRANSITION_SPEED);
        }
    },

function() {
    aboutStates["menuAbout"] = false;

    setTimeout("checkAboutMenu();", 100);
});


    jQuery("#menuAboutDropDown").hover(function() {
        aboutStates["menuAboutDropDown"] = true;



    },
    function() {
        aboutStates["menuAboutDropDown"] = false;
        setTimeout("checkAboutMenu();", 100);
    });

    // Rail menu dropdowns //

    jQuery("#menuRail").hover(function() {
        railStates["menuRail"] = true;

        var src = jQuery("#menuRail").attr("src");

        if (railStates["menuRailDropDown"] == false) {
            jQuery("#menuRailDropDown").slideDown(TRANSITION_SPEED);
        }
    },

function() {
    railStates["menuRail"] = false;

    setTimeout("checkRailMenu();", 100);
});


    jQuery("#menuRailDropDown").hover(function() {
        railStates["menuRailDropDown"] = true;



    },
    function() {
        railStates["menuRailDropDown"] = false;
        setTimeout("checkRailMenu();", 100);
    });

    // Construction menu dropdowns //

    jQuery("#menuConstruction").hover(function() {
        constructionStates["menuConstruction"] = true;

        var src = jQuery("#menuConstruction").attr("src");

        if (constructionStates["menuConstructionDropDown"] == false) {
            jQuery("#menuConstructionDropDown").slideDown(TRANSITION_SPEED);
        }
    },

function() {
    constructionStates["menuConstruction"] = false;

    setTimeout("checkConstructionMenu();", 100);
});


    jQuery("#menuConstructionDropDown").hover(function() {
        constructionStates["menuConstructionDropDown"] = true;



    },
    function() {
        constructionStates["menuConstructionDropDown"] = false;
        setTimeout("checkConstructionMenu();", 100);
    });

    // Road menu dropdowns //

    jQuery("#menuRoad").hover(function() {
        roadStates["menuRoad"] = true;

        var src = jQuery("#menuRoad").attr("src");

        if (roadStates["menuRoadDropDown"] == false) {
            jQuery("#menuRoadDropDown").slideDown(TRANSITION_SPEED);
        }
    },

function() {
    roadStates["menuRoad"] = false;

    setTimeout("checkRoadMenu();", 100);
});


    jQuery("#menuRoadDropDown").hover(function() {
        roadStates["menuRoadDropDown"] = true;



    },
    function() {
        roadStates["menuRoadDropDown"] = false;
        setTimeout("checkRoadMenu();", 100);
    });

    // Environmental menu dropdowns //

    jQuery("#menuEnvironmental").hover(function() {
        environmentalStates["menuEnvironmental"] = true;

        var src = jQuery("#menuEnvironmental").attr("src");

        if (environmentalStates["menuEnvironmentalDropDown"] == false) {
            jQuery("#menuEnvironmentalDropDown").slideDown(TRANSITION_SPEED);
        }
    },

function() {
    environmentalStates["menuEnvironmental"] = false;

    setTimeout("checkEnvironmentalMenu();", 100);
});


    jQuery("#menuEnvironmentalDropDown").hover(function() {
        environmentalStates["menuEnvironmentalDropDown"] = true;



    },
    function() {
        environmentalStates["menuEnvironmentalDropDown"] = false;
        setTimeout("checkEnvironmentalMenu();", 100);
    });

    // Training menu dropdowns //

    jQuery("#menuTraining").hover(function() {
        trainingStates["menuTraining"] = true;

        var src = jQuery("#menuTraining").attr("src");

        if (trainingStates["menuTrainingDropDown"] == false) {
            jQuery("#menuTrainingDropDown").slideDown(TRANSITION_SPEED);
        }
    },

function() {
    trainingStates["menuTraining"] = false;

    setTimeout("checkTrainingMenu();", 100);
});


    jQuery("#menuTrainingDropDown").hover(function() {
        trainingStates["menuTrainingDropDown"] = true;



    },
    function() {
        trainingStates["menuTrainingDropDown"] = false;
        setTimeout("checkTrainingMenu();", 100);
    });

    // Recruitment menu dropdowns //

    jQuery("#menuRecruitment").hover(function() {
        recruitmentStates["menuRecruitment"] = true;

        var src = jQuery("#menuRecruitment").attr("src");

        if (recruitmentStates["menuRecruitmentDropDown"] == false) {
            jQuery("#menuRecruitmentDropDown").slideDown(TRANSITION_SPEED);
        }
    },

function() {
    recruitmentStates["menuRecruitment"] = false;

    setTimeout("checkRecruitmentMenu();", 100);
});


    jQuery("#menuRecruitmentDropDown").hover(function() {
        recruitmentStates["menuRecruitmentDropDown"] = true;



    },
    function() {
        recruitmentStates["menuRecruitmentDropDown"] = false;
        setTimeout("checkRecruitmentMenu();", 100);
    });


    // News menu dropdowns //

    jQuery("#menuNews").hover(function() {
        newsStates["menuNews"] = true;

        var src = jQuery("#menuNews").attr("src");

        if (newsStates["menuNewsDropDown"] == false) {
            jQuery("#menuNewsDropDown").slideDown(TRANSITION_SPEED);
        }
    },

function() {
    newsStates["menuNews"] = false;

    setTimeout("checkNewsMenu();", 100);
});


    jQuery("#menuNewsDropDown").hover(function() {
        newsStates["menuNewsDropDown"] = true;



    },
    function() {
        newsStates["menuNewsDropDown"] = false;
        setTimeout("checkNewsMenu();", 100);
    });
});
