$(document).ready(function() {DoDocReady(); });

function DoDocReady() {
/****************************************************************/
/* Fixed Term Related Isa Table: /savings/fixed-term-savings/ */
    $("table.ftrelatedsortable").tablesorter({
 //sortList: [[0,0]],
    // pass the headers argument and assing a object
    headers: {
        // assign the secound column (we start counting zero)
        4: {
            // disable it by setting the property sorter to false
            sorter: false
        },
        // assign the third column (we start counting zero)
        5: {
            // disable it by setting the property sorter to false
            sorter: false
        }
    }

});


$("#ft-related-sorter").change(function() {
    // set sorting column and direction, this will sort on the first and third column the column index starts at zero
    var sorting = [[document.getElementById("ft-related-sorter").value, document.getElementById("ft-related-sorter-direction").value]];
    // sort on the first column
    $("table.ftrelatedsortable").trigger("sorton",[sorting]);

      //remove the empty item from the direction sorter
       if($("#ft-related-sorter-direction option:selected").text() == "") $("#ft-related-sorter-direction option:selected").remove();

       //remove any empty options
        $(this).children("option").each(function(){
            if ($(this).html() == "") $(this).remove();
       });
});

$("#ft-related-sorter-direction").change(function() {
    // set sorting column and direction, this will sort on the first and third column the column index starts at zero
    var sorting = [[document.getElementById("ft-related-sorter").value, document.getElementById("ft-related-sorter-direction").value]];
    // sort on the first column
    $("table.ftrelatedsortable").trigger("sorton",[sorting]);

    //remove the empty item from the direction sorter
    if($("#ft-related-sorter option:selected").text() == "") $("#ft-related-sorter option:selected").remove();

    //remove any empty options
    $(this).children("option").each(function(){
        if ($(this).html() == "") $(this).remove();
    });
});

 /****************************************************************/
/* Fixed Term Table: /savings/fixed-term-savings/ */

$("table.ftsortable").tablesorter({
 //sortList: [[0,0]],
    // pass the headers argument and assing a object
    headers: {
        // assign the secound column (we start counting zero)
        4: {
            // disable it by setting the property sorter to false
            sorter: false
        },
        // assign the third column (we start counting zero)
        5: {
            // disable it by setting the property sorter to false
            sorter: false
        }
    }
});



$("#ft-sorter").change(function() {
    // set sorting column and direction, this will sort on the first and third column the column index starts at zero
    var sorting = [[document.getElementById("ft-sorter").value, document.getElementById("ft-sorter-direction").value]];
    // sort on the first column
    $("table.ftsortable").trigger("sorton",[sorting]);

   //remove the empty item from the direction sorter
    if($("#ft-sorter-direction option:selected").text() == "") $("#ft-sorter-direction option:selected").remove();

    //remove any empty options
    $(this).children("option").each(function(){
        if ($(this).html() == "") $(this).remove();
    });
});

$("#ft-sorter-direction").change(function() {
   // set sorting column and direction, this will sort on the first and third column the column index starts at zero
   var sorting = [[document.getElementById("ft-sorter").value, document.getElementById("ft-sorter-direction").value]];
   // sort on the first column
   $("table.ftsortable").trigger("sorton",[sorting]);

   //remove the empty item from the direction sorter
    if($("#ft-sorter option:selected").text() == "") $("#ft-sorter option:selected").remove();

    //remove any empty options
    $(this).children("option").each(function(){
        if ($(this).html() == "") $(this).remove();
    });
});



/****************************************************************/
/* Easy Access Table: /savings/easy-access-savings/ */

$("table.tablesortereasyaccess").tablesorter({
    // pass the headers argument and assing a object
    headers:
    {
        // assign the secound column (we start counting zero)
        3: {sorter: false},
        4: {sorter: false}
    }
});



$("#ea-sorter").change(function() {
    // set sorting column and direction, this will sort on the first and third column the column index starts at zero
    var sorting = [[document.getElementById("ea-sorter").value, document.getElementById("ea-sorter-direction").value]];

    $("table.tablesortereasyaccess").trigger("sorton",[sorting]);

    //remove the empty item from the direction sorter
    if($("#ea-sorter-direction option:selected").text() == "") $("#ea-sorter-direction option:selected").remove();

    //remove any empty options
    $(this).children("option").each(function(){
        if ($(this).html() == "") $(this).remove();
    });
});

$("#ea-sorter-direction").change(function() {
    // set sorting column and direction, this will sort on the first and third column the column index starts at zero
    var sorting = [[document.getElementById("ea-sorter").value, document.getElementById("ea-sorter-direction").value]];

    $("table.tablesortereasyaccess").trigger("sorton",[sorting]);

    //remove the empty item from the direction sorter
    if($("#ea-sorter option:selected").text() == "") $("#ea-sorter option:selected").remove();

    //remove any empty options
    $(this).children("option").each(function(){
        if ($(this).html() == "") $(this).remove();
    });
});

/****************************************************************/
/* Easy Access Related Variable Rate Cash Isa's Table: /savings/easy-access-savings/ */

$("table.variablecashisassortable").tablesorter({
        // pass the headers argument and assing a object
        headers:
        {
            // assign the secound column (we start counting zero)
            4: {sorter: false},
            5: {sorter: false}
        }
});



$("#ea-related-sorter").change(function() {
    // set sorting column and direction, this will sort on the first and third column the column index starts at zero
    var sorting = [[document.getElementById("ea-related-sorter").value, document.getElementById("ea-related-sorter-direction").value]];

    $("table.variablecashisassortable").trigger("sorton",[sorting]);

    //remove the empty item from the direction sorter
    if($("#ea-related-sorter-direction option:selected").text() == "") $("#ea-related-sorter-direction option:selected").remove();

    //remove any empty options
    $(this).children("option").each(function(){
        if ($(this).html() == "") $(this).remove();
    });
});

$("#ea-related-sorter-direction").change(function() {
    // set sorting column and direction, this will sort on the first and third column the column index starts at zero
    var sorting = [[document.getElementById("ea-related-sorter").value, document.getElementById("ea-related-sorter-direction").value]];

    $("table.variablecashisassortable").trigger("sorton",[sorting]);

    //remove the empty item from the direction sorter
    if($("#ea-related-sorter option:selected").text() == "") $("#ea-related-sorter option:selected").remove();

    //remove any empty options
    $(this).children("option").each(function(){
        if ($(this).html() == "") $(this).remove();
    });
});


/****************************************************************/
/* ISA Variable Rate Table: /savings/isa-savings/ */

$("table.isavariableratesortable").tablesorter({
        // pass the headers argument and assing a object
        headers:
        {
            // assign the secound column (we start counting zero)
            3: {sorter: false},
            4: {sorter: false}
        }
});




$("#isa-variable-sorter").change(function() {
   // set sorting column and direction, this will sort on the first and third column the column index starts at zero
      var sorting = [[document.getElementById("isa-variable-sorter").value, document.getElementById("isa-variable-sorter-direction").value]];

       $("table.isavariableratesortable").trigger("sorton",[sorting]);

       //remove the empty item from the direction sorter
       if($("#isa-variable-sorter-direction option:selected").text() == "") $("#isa-variable-sorter-direction option:selected").remove();

       //remove any empty options
        $(this).children("option").each(function(){
            if ($(this).html() == "") $(this).remove();
        });
});

$("#isa-variable-sorter-direction").change(function() {
   // set sorting column and direction, this will sort on the first and third column the column index starts at zero
      var sorting = [[document.getElementById("isa-variable-sorter").value, document.getElementById("isa-variable-sorter-direction").value]];

      $("table.isavariableratesortable").trigger("sorton",[sorting]);

       //remove the empty item from the sorter
       if($("#isa-variable-sorter option:selected").text() == "") $("#isa-variable-sorter option:selected").remove();

       //remove any empty options
       $(this).children("option").each(function(){
            if ($(this).html() == "") $(this).remove();
        });
});
/****************************************************************/
/* ISA Variable Rate Table: /savings/isa-savings/ */

$("table.isafixedratesortable").tablesorter({
        // pass the headers argument and assing a object
        headers:
        {
            // assign the secound column (we start counting zero)
            4: {sorter: false},
            5: {sorter: false}
        }
});



$("#isa-fixed-sorter").change(function() {
    // set sorting column and direction, this will sort on the first and third column the column index starts at zero
    var sorting = [[document.getElementById("isa-fixed-sorter").value, document.getElementById("isa-fixed-sorter-direction").value]];

    $("table.isafixedratesortable").trigger("sorton",[sorting]);
    //return false to stop default link action

    //remove the empty item from the sorter
    if($("#isa-fixed-sorter-direction option:selected").text() == "") $("#isa-fixed-sorter-direction option:selected").remove();

    //remove any empty options
    $(this).children("option").each(function(){
        if ($(this).html() == "") $(this).remove();
    });

    return false;
});

$("#isa-fixed-sorter-direction").change(function() {
    // set sorting column and direction, this will sort on the first and third column the column index starts at zero
    var sorting = [[document.getElementById("isa-fixed-sorter").value, document.getElementById("isa-fixed-sorter-direction").value]];

    $("table.isafixedratesortable").trigger("sorton",[sorting]);

    //remove the empty item from the sorter
    if($("#isa-fixed-sorter option:selected").text() == "") $("#isa-fixed-sorter option:selected").remove();

    //remove any empty options
     $(this).children("option").each(function(){
        if ($(this).html() == "") $(this).remove();
     });

    // return false to stop default link action
    return false;
});
/****************************************************************/

 $("table.tablesorterindexlinked").tablesorter({
  // sortList: [[0,0]],
    // pass the headers argument and assing a object
    headers: {
        // assign the secound column (we start counting zero)
        1: {sorter: false},
        4: {sorter: false},
        5: {sorter: false}
    }
});

    // update the dropdowns if the table headers are clicked
    UpdateSortDropdown1("table.ftsortable th","#ft-sorter","#ft-sorter-direction");
    UpdateSortDropdown1("table.ftrelatedsortable th","#ft-related-sorter","#ft-related-sorter-direction");
    UpdateSortDropdown2("table.tablesortereasyaccess th","#ea-sorter","#ea-sorter-direction");
    UpdateSortDropdown1("table.variablecashisassortable th","#ea-related-sorter","#ea-related-sorter-direction");
    UpdateSortDropdown2("table.isavariableratesortable th","#isa-variable-sorter","#isa-variable-sorter-direction");
    UpdateSortDropdown1("table.isafixedratesortable th","#isa-fixed-sorter","#isa-fixed-sorter-direction");



    //$("#accordion").accordion({header:'div.accordionHeader', autoHeight: false, collapsible: true, active: false});
    // om: show and hide to be independent, so don't use the accordion
    $("#accordion .accordionHeader").addClass("ui-state-default").click(function() {
        if($(this).next().is(":visible")) {
            $(this).removeClass("ui-state-active").addClass("ui-state-default").next().slideUp();
        } else {
            $(this).removeClass("ui-state-default").addClass("ui-state-active").next().slideDown();
        }
    }).next().hide();

    $(".jQueryTooltipList img").tooltip({
        track: true,
        delay: 0,
        showURL: false,
        opacity: 1,
        extraClass: "pretty fancy",
        top: -15,
        left: 5
    });

    $("#myTable").tablesorter({
        // pass the headers argument and assing a object
        headers: {
            // assign the secound column (we start counting zero)
            2: {
                // disable it by setting the property sorter to false
                sorter: false
            },
            // assign the third column (we start counting zero)
            3: {
                // disable it by setting the property sorter to false
                sorter: false
            }
        }
    });

    // to allow the Ts and Cs tab to be selected from a link elsewhere on the page
    var $tabs = $('.tabs').tabs(); // first tab selected
    $('a.aTsCs').click(function() { // bind click event to link
        $tabs.tabs('select', 2);
        $('html, body').animate({scrollTop:0}, 'fast'); // switch to third tab
        return false;
    });
    // to allow the Summary tab to be selected from a link elsewhere on the page
    var $tabs = $('.tabs').tabs(); // first tab selected
    $('a.aSums').click(function() { // bind click event to link
        $tabs.tabs('select', 1);
        $('html, body').animate({scrollTop:0}, 'fast'); // switch to second tab
        return false;
    });
	//loadFlash();
}

// Fix for IE6 - gives input elements pointer cursor on hover
$(function() {
        $('.action input').hover(function(){
               $(this).addClass('hover');
        }, function() {
               $(this).removeClass('hover');
        });
});

  $(function() {
          $("input#ctl00_searchButton").hover(
            function () {
                   $(this).addClass("hover");
            },
            function () {
                   $(this).removeClass("hover");
            }
          );
  });

  $(function() {
          $("input#ctl00_ctl00_searchButton").hover(
            function () {
                   $(this).addClass("hover");
            },
            function () {
                   $(this).removeClass("hover");
            }
          );
  });

//update the dropdown
function UpdateSortDropdown1(a,b,c)
{
    var doOrder = false;

    $(a).click(function(event) {

        switch($(this).find('p').html().trim())
        {
        case "Account and apply":
              $(b).val(0);
              doOrder = true;
              break;
        case "Rates":
            $(b).val(1);
            doOrder = true;
            break;
         case "Term":
            $(b).val(2);
            doOrder = true;
            break;
         case "Save from":
            $(b).val(3);
            doOrder = true;
            break;
        default:

            if ($(this).find('p').html().trim().indexOf("Balance after 12 months")>-1) {$(b).val(6);  doOrder = true;}
            else {doOrder = false;}
        }

        if(doOrder == true)
        {
           if($(this).attr("class").indexOf("headerSortDown") > -1){$(c).val(1);}
           else if($(this).attr("class").indexOf("headerSortUp") > -1){$(c).val(0);}
           else if($(this).attr("class").indexOf("header") > -1){$(c).val(0);}
        }
});

}

//update the dropdown
function UpdateSortDropdown2(a,b,c)
{
    var doOrder = false;

    $(a).click(function(event) {

    switch($(this).find('p').html().trim())
    {
    case "Account and apply":
        $(b).val(0);
        doOrder = true;
        break;
    case "Rates":
        $(b).val(1);
         doOrder = true;
        break;
     case "Save from":
        $(b).val(2);
         doOrder = true;
        break;
     default:
        if ($(this).find('p').html().trim().indexOf("Balance after 12 months")>-1) {$(b).val(5); doOrder = true;}
        else { doOrder = false; }
    }

    if(doOrder == true)
    {
       if($(this).attr("class").indexOf("headerSortDown") > -1){ $(c).val(1);}
       else if($(this).attr("class").indexOf("headerSortUp") > -1){$(c).val(0);}
       else if($(this).attr("class").indexOf("header") > -1){$(c).val(0);}
    }
});

}


function hide_expanded()
{
	$("#expandedFlash").hide();
}

function show_expanded(){
	$('#expandedFlash').show();
	$('#expandedFlash').html('<object type="application/x-shockwave-flash" width="960" height="456" data="/swf/isa-carpet-full.swf" id="movie"><param name="movie" value="/swf/isa-carpet-full.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /></object>');
}
