$(document).ready(function () {

    //hover #programs li change
    $('#programs li').hover(function () {
        $(this).addClass("hover");
    }, function () {
        $(this).removeClass("hover");
    })

    //match h1 to #programs li
    var h1 = $('h1').html();
    $('#programs, #navigation').find("a:contains('" + h1 + "')").filter(function (index) { return $(this).text() == h1; }).each(function () {
        if ($(this).text() != "Find an Agent") {
            if ($(this).text() == "Policyholder Services") {
                $('#policy-agent').addClass("here");
            }
            else {
                $(this).parent().addClass("here");
            }
        }
        else {
            $('#find-agent').addClass("here");
        }
        $('.here').parent().parent().addClass("here");
    })

    //oil & gas .here ampersand workaround
    var str = location.pathname;
    if (str.match("on-shore-oil-and-gas-extraction")) {
        $('#oil').addClass('here');
    }

    //add home class
    $('.home-main').parent().addClass('home');

    //home flash
    if ($('.home-main')) {
        var flashvars = {};
        var params = {};
        params.wmode = "transparent";
        var attributes = {};
        swfobject.embedSWF("img/flash/home.swf", "bigpic", "528", "260", "9.0.0", "img/flash/expressInstall.swf", flashvars, params, attributes);
    }

    //circle of excellence workaround
    if (str.match("circle-of-excellence")) {
        $('#coe').addClass('here');
        $('#coe').parent().parent().addClass("here")
    }

    //industry links remove .here
    if (str.match("industry-links")) {
        $('#programs li, #oil').removeClass('here');
    }

    //navigation dropdowns
    $('#navigation li').hoverIntent(function () {
        $(this).addClass("hover");
        $('ul', this).fadeIn('fast');
    }, function () {
        $('ul', this).animate({ opacity: 1.0 }, 200);
        $('ul', this).fadeOut('fast', function () {
            $(this).removeClass("hover");
        })
    })

    //external links
    $('a[rel="external"]').attr('target', '_blank');

    //'texas only' pdf link
    $('#texas').click(function () {
        window.open("../pdfs/Bituminous-eBilling.pdf");
    });

    //printer friendly version
    $('#print').click(function () {
        $('#print, #header, #navigation, #programs, #feature, #contentFooter, #footer').css({ 'display': 'none' });
        $('#regular').css({ 'display': 'block' });
        $('.highlights td, .highlights tr, .highlights th').css({ 'background': 'none', 'color': '#000000' });
        $('.highlights td, .highlights tr').css({ 'font-weight': 'normal' });
        $('body').css({ 'background-color': '#ffffff' });
        $('#main').css({ 'border': 'none' });
        $('.footnote').css({ 'color': '#000000' });
        $('#WardGroupLink a').css({ 'background': 'none', 'color': '#000000' });
    });

});


//jq hover intent plugin
(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);
