﻿var cfg = ($.hoverintent = {
    sensitivity: 7,
    interval: 100
});

$.event.special.hoverintent = {
    setup: function() {
        $(this).bind("mouseover", jQuery.event.special.hoverintent.handler);
    },
    teardown: function() {
        $(this).unbind("mouseover", jQuery.event.special.hoverintent.handler);
    },
    handler: function(event) {
        event.type = "hoverintent";
        var self = this,
				args = arguments,
				target = $(event.target),
				cX, cY, pX, pY;

        function track(event) {
            cX = event.pageX;
            cY = event.pageY;
        };
        pX = event.pageX;
        pY = event.pageY;
        function clear() {
            target.unbind("mousemove", track).unbind("mouseout", arguments.callee);
            clearTimeout(timeout);
        }
        function handler() {

            if (cfg.sensitivity > (Math.abs(pX - cX) + Math.abs(pY - cY))) {
                clear();
                jQuery.event.handle.apply(self, args);
            } else {
                pX = cX; pY = cY;
                timeout = setTimeout(handler, cfg.interval);
            }
        }
        var timeout = setTimeout(handler, cfg.interval);
        target.mousemove(track).mouseout(clear);
        return true;
    }
};

$(function() {
$("#accordion").accordion({
    event: "hoverintent"
    });
});

// initialise plugins
$(document).ready(function() {
    if (window.location.href.indexOf("locknavigation=true") < 0) {
        $("#menu ul.menu").supersubs({
            minWidth: 12,   // minimum width of sub-menus in em units
            /*maxWidth: 15,*/   // maximum width of sub-menus in em units
            extraWidth: 1     // extra width can ensure lines don't sometimes turn over
            // due to slight rounding differences and font-family
        }).dropdown();  // call supersubs first, then superfish, so that subs are
        // not display:none when measuring. Call before initialising
        // containing tabs for same reason.
    }
});

