﻿$(function () {

    if ($(window).width < 480) {
        $("#Triangle, .icon").hide();
    }
    $(".content").hide();
    $(".content p").hide();

    var hoverContent = [];
    hoverContent["Triangle-left"] = false;
    hoverContent["Triangle-right"] = false;
    hoverContent["Triangle-top"] = false;


    $(".touch #Triangle").data("href", $("#Map area:first").attr("href"));
    $(".touch #Map").remove();
    $(".touch #Triangle").attr("src", "/customers/bere/bennett2011/skin/images/triangle_touch.png");

    // ON TOUCH DEVICES
    $(".touch #Triangle").bind("click", function () {
        location.href = $(this).data("href");
    });

    // ON HOVER ENAABLE DEVICES
    $(".content").hover(function () {
        var id = $(this).attr("id");
        hoverContent[id] = true;
    }, function () {
        var id = $(this).attr("id");
        hoverContent[id] = false;
        var $elm = $("#Map area[data-content='" + id + "']");
        hideContent($elm);
    });

    $(".no-touch area").hover(function () {
        var content = $(this).data("content");
        hoverContent[content] = true;
        if ($("#" + content).is(":visible")) return;
        $("#" + content)
            .stop()
            .show()
            .css("background", "url(/customers/bere/bennett2011/skin/images/" + content + "_animate_up.gif) no-repeat bottom right")
            .find("p")
                .stop()
                .delay(250)
                .show();
    }, function () {
        var content = $(this).data("content");
        hoverContent[content] = false;
        hideContent($(this));
    });

    function hideContent($elm) {
        setTimeout(function () {
            var content = $elm.data("content");
            console.log("hide " + content, hoverContent[content]);
            if (hoverContent[content]) return;

            $("#" + content + " p")
                .stop()
                .hide()
                    .parent(".content")
                    .stop()
                    .delay(250)
                    .attr("style", "background: url(/customers/bere/bennett2011/skin/images/" + content + "_animate_down.gif) no-repeat bottom right;")
                    .delay(250)
                    .fadeOut();
        }, 200);
    }

});
