$(function () {
    // jQuery is required for the selectors
    Cufon.replace('.gotham', { fontFamily: 'Gotham Rounded Medium' });
    Cufon.replace('h1', { fontFamily: 'Helvetica Neue' });
    Cufon.replace('#headcontent h1', { fontFamily: 'Helvetica Neue' });
    Cufon.replace('#headcontent h2', { fontFamily: 'Helvetica Neue' });
    Cufon.replace('.hnlight', { fontFamily: 'Helvetica Neue' });
    Cufon.replace('.hnheavy', { fontFamily: 'Helvetica Neue' });
    Cufon.replace('.boxheader', { fontFamily: 'Helvetica Neue' });
    Cufon.replace('.darkbluebtn', { fontFamily: 'Helvetica Neue' });
    Cufon.replace('.purplebtn', { fontFamily: 'Helvetica Neue' });
    Cufon.replace('.greenbtn', { fontFamily: 'Helvetica Neue' });
    Cufon.replace('.chasegreenbtn', { fontFamily: 'Helvetica Neue' });
    Cufon.replace('.corpbtnup', { fontFamily: 'Helvetica Neue' });
    Cufon.replace('.quotebuttonsmall, .quotebuttonlarge', { fontFamily: 'Helvetica Neue' });

    // Start home banner animation + partner checks

    if ($('#partner').val() == 'main') {
        setTimeout("showImage('#headcontent.home', 2, 4)", 5000);
        $('.main_keyfacts').show();
        $('.askafa_keyfacts').hide();
        $('.asafa_keyfacts').hide();
        $('#menu_askafa').hide();        
        $('#MenuBarMain').show();
    }

    if ($('#partner').val() == 'askafa') {
        $('.main_keyfacts').hide();
        $('.askafa_keyfacts').show();
        $('.asafa_keyfacts').show();
        $('#MenuBarMain').hide();
        $('#menu_askafa').show();
    }

    // Start IFA banner animation
    //setTimeout("showImage('#headcontent.intermediaries', 2, 2)", 5000);

    // Confirm Read Dialog
    $(".confirmread").click(function () {
        return confirm('Click OK if you AGREE you have read Shepherds Key facts, Key features and How Shepherds Manage Your Money if applicable, otherwise click cancel.');
    });

    // Temp error message for HEPP and MPPI
    $(".temporarily-unavailable").click(function () {
        alert("The quote option for this product is temporarily unavailable. Please phone head office on 0161 428 1212 to obtain a quote.");
        return false;
    });

    // Confirm IFA Income Dialog
    $(".confirm-income-protection-ifa").click(function () {
        return confirm('You can only apply for this product if you are investment authorised. If you do not have permission to write investment business please see our Simple Income Protection Plan.');
    });

});

function fadeOut(selector) {
    $(selector).animate(
				{ 'opacity': 0 },
				{ duration: 1000 });
}
function fadeIn(selector) {
    $(selector).animate(
				{ 'opacity': 1 },
				{ duration: 1000 });
}

function showImage(selector, imgNo, totalImages) {
    if (imgNo > totalImages) imgNo = 1;
    var pos = (imgNo - 1) * -344;
    fadeOut(selector);
    $(selector).animate(
				{ backgroundPosition: "0 " + pos + "px" },
				{ duration: 10 });
    fadeIn(selector);

    setTimeout("showImage('" + selector + "' ," + (imgNo + 1) + ", " + totalImages + ")", 5000);
}

