jQuery.preloadImages = function()
{
  var p_img = new Object;
  for(var i = 0; i<arguments.length; i++)
  {
    p_img[i] = jQuery("<img>").attr("src", arguments[i]);
  }
}

function openCalc(url, name){
    popupWin = window.open(url, name, 'scrollbars,dependent,width=510,height=300,left=500,top=325');
}

$.preloadImages(
    '/images/home2008/moreinfo_grad_bottom.gif',
    '/images/home2008/nav_grad_bottom.gif',
    '/images/home2008/close_box.gif'
    );

$(document).ready(function(){

    var navEntries = $("#primaryNav li.p_entry");

    $('#primaryNav ul.primaryNavMenu').supersubs({
            minWidth:    12,   // minimum width of sub-menus in em units
            maxWidth:    31,   // 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
        }).superfish({
        animation   : {opacity:'show',height:'show'},
        autoArrows  : false,
        speed       : 'fast',
        delay       : 750
    });

    // for some reason the first sub-menu doesn't look right in IE6
    if ($.browser.msie && parseInt($.browser.version) <= 6)
    {
        $(navEntries[0]).find("ul:first").css("width", "21em");
        $(navEntries[0]).add(navEntries[1]).find("ul").bgIframe({opacity: false});
    }

    $('a.m_offer,a.m_more').cluetip(
        {
            cluetipClass: 'caponehp',
            closePosition: 'top',
            local:  true,
            cursor: 'pointer',
            sticky: true,
            activation: 'click',
            showTitle: false,
            dropShadow: false,
            closeText: '<img src="/images/home2008/close_box.gif" />'

        }
    );

    $("div.list,#cluetip").hover(
      function () {
        $(this).addClass("over");
      },
      function () {
        $(this).removeClass("over");
      }
    );

    if($.browser.safari)
    {
        var entries = $("#primaryNav li.p_entry");
        $(entries[1]).find("li").width(310);
        $(entries[3]).find("li").width(310);
    }

    $("#eos_regionalLogin").submit(function() {
    if($("#txtUserID").val() === "")
    {
        alert("Please enter a Username");
        return false;
    }
    if($("#txtPassword").val() === "")
    {
        alert("Please enter a Password");
        return false;
    }

        triggerTag("NDB_Footprint_OLB_Tag");
    });

    // "hack" for the "For Business" primary nav item regionalization
    navEntries.children("a[href^='/smallbusiness']").add(navEntries.children("a[href^='/bank/business']")).click(function()
    {
        // add a cookie so we know that "For Business" was clicked
        $.cookie("forbusiness", "true", {path: '/', domain: '.capitalone.com'});
    });
});
