/// <reference path="jquery-1.3.1-vsdoc.js" />
/**
* hoverLight r2.1 // 3/20/2009 // tested with jQuery 1.3.1+
* Custom Athletic.net jQuery Plugin
* 
* @author    Joshua Bowdoin <josh.bowdoin@athletic.net>
*/
$.fn.hoverLight = function(options) {
    var defaults = {
        HLCells: 'tr td:nth-child(2n)',
        HLpopupUser: "<div id='HLpopup'><ul><li id='HL_Yellow' class='HL_Yellow HLBHSelect color'></li><li id='HL_Green' class='HL_Green HLBHSelect color'></li><li id='HL_Blue' class='HL_Blue HLBHSelect color'></li><li id='HL_Pink' class='HL_Pink HLBHSelect color'></li><li id='HL_Dusty' class='HL_Dusty HLBHSelect color'></li><li id='HL_Strong' class='HL_Strong HLBHSelect'>Bold</li><li id='HL_ClearAll' class='HLBHSelect' title='Clear all highlighting on this report.'>X</li></ul></div>",
        HLTable: '.HLData'
    };
    var options = $.extend(defaults, options);
    var HLCells = $('table' + options.HLTable + ' ' + options.HLCells)
    var HLpopup = $(options.HLpopupUser);
    HLpopup.appendTo("body");
    $('#HL_ClearAll').click(function() {
        $('tr.HLs td').removeClass('Y G B P D S');
        $('tr.HLs').removeClass('HLs HL_Yellow HL_Green HL_Blue HL_Pink HL_Dusty HL_Strong');
    });
    $('.HLBHSelect').not('#HL_ClearAll').click(function() {
        var FindContents = $(this).parent().parent().parent().text().substring(5);
        var cellNum = $(this).parent().parent().parent().get()[0].cellIndex + 1;
        if ($(this).hasClass('HLSelected')) {
            $('table.HLData tr td:nth-child(' + cellNum + '):contains(' + FindContents + ')')
                    .removeClass($(this).attr('id').substring(3, 4))
                    .siblings().removeClass($(this).attr('id').substring(3, 4))
                    .parent().removeClass($(this).attr('id') + ' HLs');
        }
        else {
            $('table.HLData tr td:nth-child(' + cellNum + '):contains(' + FindContents + ')')
                    .addClass($(this).attr('id').substring(3, 4))
                    .parent().addClass($(this).attr('id') + ' HLs');
        }
        $(this).toggleClass('HLSelected');
    });
    function showHLPopup() {
        $(this).prepend(HLpopup);
        if ($(this).hasClass('Y')) {
            $('#HLpopup li#HL_Yellow').addClass('HLSelected');
        };
        if ($(this).hasClass('G')) {
            $('#HLpopup li#HL_Green').addClass('HLSelected');
        };
        if ($(this).hasClass('B')) {
            $('#HLpopup li#HL_Blue').addClass('HLSelected');
        };
        if ($(this).hasClass('P')) {
            $('#HLpopup li#HL_Pink').addClass('HLSelected');
        };
        if ($(this).hasClass('D')) {
            $('#HLpopup li#HL_Dusty').addClass('HLSelected');
        };
        if ($(this).hasClass('S')) {
            $('#HLpopup li#HL_Strong').addClass('HLSelected');
        };
        HLpopup.show();
    }
    function hideHLPopup() {
        HLpopup.hide();
        $('#HLpopup li').removeClass('HLSelected');
    }
    var hIntentConfig = {
        sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)    
        interval: 350, // number = milliseconds for onMouseOver polling interval
        over: showHLPopup, // function = onMouseOver callback (REQUIRED)    
        timeout: 100, // number = milliseconds delay before onMouseOut
        out: hideHLPopup
    };
    HLCells.hoverIntent(hIntentConfig);
};
///**
//* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
//* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
//* 
//* @param  f  onMouseOver function || An object with configuration options
//* @param  g  onMouseOut function  || Nothing (use configuration options object)
//* @author    Brian Cherne <brian@cherne.net>
//**/
(function($) { $.fn.hoverIntent = function(f, g) { var cfg = { sensitivity: 7, interval: 100, timeout: 0 }; cfg = $.extend(cfg, g ? { over: f, out: g} : f); var cX, cY, pX, pY; var track = function(ev) { cX = ev.pageX; cY = ev.pageY; }; var compare = function(ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); if ((Math.abs(pX - cX) + Math.abs(pY - cY)) < cfg.sensitivity) { $(ob).unbind("mousemove", track); ob.hoverIntent_s = 1; return cfg.over.apply(ob, [ev]); } else { pX = cX; pY = cY; ob.hoverIntent_t = setTimeout(function() { compare(ev, ob); }, cfg.interval); } }; var delay = function(ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); ob.hoverIntent_s = 0; return cfg.out.apply(ob, [ev]); }; var handleHover = function(e) { var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget; while (p && p != this) { try { p = p.parentNode; } catch (e) { p = this; } } if (p == this) { return false; } var ev = jQuery.extend({}, e); var ob = this; if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); } if (e.type == "mouseover") { pX = ev.pageX; pY = ev.pageY; $(ob).bind("mousemove", track); if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout(function() { compare(ev, ob); }, cfg.interval); } } else { $(ob).unbind("mousemove", track); if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout(function() { delay(ev, ob); }, cfg.timeout); } } }; return this.mouseover(handleHover).mouseout(handleHover); }; })(jQuery);