﻿$(document).ready(function () {

    // headers
    $('.content .sfContentBlock h2').siblings().hide();

    $('.content h2').click(function () {

        var h2 = $(this);
        if (h2.hasClass('open')) {
            h2.removeClass('open');
            h2.siblings().hide();
        }
        else {
            h2.addClass('open');
            h2.siblings().show();
        }

    });

    var hash = window.location.hash.substring(1);
    if (hash.length) {
        var h2 = $('.content a[name="' + hash + '"]').siblings('h2');
        if (h2)
            h2.click();
    }

    // exit
    var url;
    var cTime;

    $("#exit-dialog").dialog({
        modal: true,
        autoOpen: false,
        closeOnEscape: true,
        resizable: false,
        draggable: false,
        close: function (event, ui) {
            if (cTime != null) window.clearTimeout(cTime);
        },
        buttons: {
            Ok: function () {
                window.open(url);
                $(this).dialog("close");
            },
            Cancel: function () {
                $(this).dialog("close");
            }
        }
    });


    $("a[href^='http']").not("a[href*='coastlinefcu.org']").not("a[href*='epscu.com']").not("a[href*='coastlinehomemortgage.com']").not("a[href*='wheremembersbuy.com']").not("a[href*='memberconnectweb.com']").not("a[href*='credituniontube.org']").not("#flip a").click(function () {

        url = $(this).attr('href');
        cTime = window.setTimeout(function () {
            window.location = url;
            $("#exit-dialog").dialog('close');
        }, 10000);

        $("#exit-dialog").dialog('open');
        return false;
    });

});	

