// build the accordian menu
function initMenu() {
  $('#menu ul').hide();
  $('#menu ul.selected').show();
}


$(document).ready(function() {
    // side menu init
    initMenu();

    // IE6 PNG fixer
    $(document).pngFix();

    // Form validation
    //$("#formID").validationEngine()

    //contact us
    $("#textBoxes").hide();
    $("#ctl00_ctl00_ContentPlaceHolder1_MainPanelContent_existingCustomer").change(function() {
    if ($("#ctl00_ctl00_ContentPlaceHolder1_MainPanelContent_existingCustomer option:selected").val() == "Yes") {
        $("#textBoxes").show();
        } else {
        $("#textBoxes").hide();
       }
    });

    // Glossary section 
    $('.sectionInfo').hide();
    $('.closeSection').hide();
    $('.openSection').click(function() {
        $(this).hide().next().show();
        $(this).next().next().slideDown();
        return false;
    });
    $('.closeSection').click(function() {
        $(this).hide().prev().show();
        $(this).next().slideUp();
        return false;
    });

    // Instantiate cufon
    Cufon.replace('#assetHeaderLower a');
    Cufon.replace('#assetRHS a');
    Cufon.replace('#assetHeaderMain a');
    Cufon.replace('#assetHeaderSub a');

    $("#assetHeaderLower a").css("color", "#FFFFFF");
    $("#assetHeaderLower a").css("font-size", "15pt");
    $("#assetHeaderLower a").css("word-spacing", "-2px");
    $("#assetHeaderLower a").css("letter-spacing", "-1px");
    $("#assetHeaderLower a").css("top", "71px");

    $("#assetRHS a").css("color", "#FFFFFF");
    $("#assetRHS a").css("font-size", "14pt");
    $("#assetRHS a").css("word-spacing", "-3px");
    $("#assetRHS a").css("letter-spacing", "-1px");
    $("#assetRHS a").css("top", "85px");

    // changes to the h1 tag
    $("#assetHeaderMain a").css("color", "#FFFFFF");
    $("#assetHeaderMain a").css("font-size", "11pt");
    $("#assetHeaderMain a").css("word-spacing", "-1px");
    $("#assetHeaderMain a").css("letter-spacing", "-1px");
    $("#assetHeaderMain a").css("font-stretch", "semi-expanded");
    $("#assetHeaderMain a").css("line-height", "90%");
    $("#assetHeaderMain a").css("top", "96px");

    $("#assetHeaderSub a").css("color", "#FFFFFF");
    $("#assetHeaderSub a").css("font-size", "17.5pt");
    $("#assetHeaderSub a").css("word-spacing", "-3px");
    $("#assetHeaderSub a").css("letter-spacing", "-1px");
    $("#assetHeaderSub a").css("top", "135px");
	       

    // header panel slider
    $(".close").hide();
    $(".open").click(function() {
        if ($.browser.msie && $.browser.version.substr(0, 1) == 6) {
            $("#panel").animate({ 'top': '-128px' }, '500');
        } else {
            $("#panel").animate({ 'top': '-122px' }, '500');
        }
        $(".open").hide();
        $(".close").show();
        return false;
    });
    $(".close").click(function() {
        
        if ($.browser.msie && $.browser.version.substr(0, 1) == 6) {
            $("#panel").animate({ 'top': '-263px' }, '500');
        } else { 
            $("#panel").animate({ 'top': '-258px' }, '500');
        }
        $(".close").hide();
        $(".open").show();
        return false;
    });


    // image swap
    $(function() {
        $('.rollover').hover(function() {

            var currentImg = $(this).attr('src');
            $(this).attr('src', $(this).attr('hover'));
            $(this).attr('hover', currentImg);
        }, function() {
            var currentImg = $(this).attr('src');
            $(this).attr('src', $(this).attr('hover'));
            $(this).attr('hover', currentImg);
        });
    });

    // populate the postcode textbox
    $('#ctl00_ctl00_ContentPlaceHolder1_RightHandCol_HomeGitPanelUc_TextBox1').autofill({
        value: 'Enter postcode',
        defaultTextColor: '#0055a4',
        activeTextColor: '#0055a4'
    });

    $('#ctl00_ctl00_ContentPlaceHolder1_RightHandBanners_CarGitPanelUc_TextBox1').autofill({
        value: 'Enter postcode',
        defaultTextColor: '#0055a4',
        activeTextColor: '#0055a4'
    });

    $('#ctl00_ctl00_ContentPlaceHolder1_RightHandCol_CarGitPanelUc_TextBox1').autofill({
        value: 'Enter postcode',
        defaultTextColor: '#0055a4',
        activeTextColor: '#0055a4'
    });

    

    
});


var popup;

// Identity Protection opener
function openthefttest() {

    popup = window.open("http://tools.cpp.co.uk/swintonsurvey/index.php", "thefttest", "height=660,width=805,scrollbars=yes,resizable=yes");

    if (popup != null) {
        popup.focus();
    }
}


// Identity Protection opener
function openidentitypanel() {

    popup = window.open("https://www2.respondingtolife.com/assist/policyapp/application.cpp?id=648BB9714CBD565A3038056F51620279&type=2&term=1", "SwintonIdolWindow", "height=660,width=805,scrollbars=yes,resizable=yes");

    if (popup != null) {
        popup.focus();
    }
}

// idolquote opener
function openidolpanel() {

    popup = window.open("https://www.theidol.com/affiliate.cfm?affiliate=swinton&affiliateNumber=104&product=6&allow=1", "SwintonIdolWindow", "height=660,width=805,scrollbars=yes,resizable=yes");

    if (popup != null) {
        popup.focus();
    }
}

// lifesearch opener
function openlifesearchpanel(ev) {

    popup = window.open("http://www.lifesearch.co.uk/affiliateaspx/intro.aspx?IntId=4576&Vfy=E-", "lifesearchquote", "height=660,width=805,scrollbars=yes");

    if (popup != null) {
        popup.focus();
    }
}

// Live PA
function openPApanel() {

    popup = window.open("https://quote.swinton.co.uk/pa/applicationlauncher.aspx?appsource=pa", "paquote", "height=660,width=805,scrollbars=no");

    if (popup != null) {
        popup.focus();
    }
}


//Live ADB
function openADBpanel() {

    popup = window.open("https://quote.swinton.co.uk/adb/applicationlauncher.aspx?appsource=adb", "adbquote", "height=660,width=805,scrollbars=no");

    if (popup != null) {
        popup.focus();
    }
}


function openHealthSurepanel() {
    //var sUrl = 'http://www.healthsure.co.uk/corporatevoluntary/index.php';
    //var sQuery = 'web_code=swinton';

    var sUrl = 'https://www.simplyhealth.uk.com/index.php?option=com_bluefrontier&custid=281&prodid=17&view=products&Itemid=67';
    var sQuery = 'web_code=swinton';

    var sAffValue = getAff();
    switch (sAffValue) {
        case 'email_aug_live_swinton_home':
        case 'email_aug_live_bullseye_home':
        case 'email_aug_live_bullseye_pmc':
        case 'email_aug_live_its4me_pmc':
        case 'email_aug_live_swinton_pmc':
            sQuery += '&aff=' + sAffValue;
            break;
    }

    window.open(sUrl + '?' + sQuery,
        "myWindow", "status = 1, height = 600, width = 980, resizable = 0, scrollbars=1");
    return false;
}
