$(document).ready(function () {
    $('.country').mouseover(function () {
        $('#international_dropdown').show();
    });

    $('.country').mouseout(function () {
        $('#international_dropdown').hide();
    });

    $('#nav li:last-child').css('cssText', 'background-image: none !important');

    $("#findNero").hover(
        function () {
            window.clearTimeout(timeoutID);
            $("#nav_searchTerm").show();
            $("#findNero").css("background-position", "0 0");
        },
        function () {
            timeoutID = window.setTimeout(hideSearch, 2000);
        }
    );

    $("#nav_searchTerm").hover(
        function () {
            window.clearTimeout(timeoutID);
            $("#nav_searchTerm").show();
            $("#findNero").css("background-position", "0 0");
        },
        function () {
            timeoutID = window.setTimeout(hideSearch, 2000);
        }
    );

    $("#international_dropdown").hover(
        function () {
            $("#international_dropdown").show();
        },
        function () {
            $("#international_dropdown").hide();
        }
    );

    $("#nav_address").keyup(function (event) {
        if (event.keyCode == 13) {
            $("#btnSearch").click();
        }
    });

    $("#uae-stores div").click(function (e) {
        if ($(this).hasClass('open')) {
            $(this).removeClass('open');
            $(this).find('.uae-search-content').hide();
        } else {
            $(".search").removeClass('open').find('.uae-search-content').hide();

            $(this).find('.uae-search-content').show();
            if ($(this).hasClass('open'))
                $(this).removeClass('open');
            else
                $(this).addClass('open');
        }
    });
});

var timeoutID;

function hideSearch() {
    $("#nav_searchTerm").hide();
    $("#findNero").css("background-position", "0 -23px");
    window.clearTimeout(timeoutID);
}

function clearNavDefaultMessage(obj) {
    if (obj.value == 'Postcode/Location') {
        //Change style
        obj.value = '';
    }
}

function putInNavDefaultMessageIfBlank(obj) {
    if (obj.value == '') {
        //Change style
        obj.value = 'Postcode/Location';
    }
}

function search() {
    clearNavDefaultMessage(document.getElementById("nav_address"));
    var txt_address = document.getElementById("nav_address").value;
    window.location = "http://www.caffenero.com/findnero/default.aspx?searchterm=" + txt_address;
}
