﻿
var modalInitDone = false;

function showModalDialog()
{								
	var thickBoxContent = $(".jq-identifier-class-quick-search").parents("div.us-panel,div.us-input-panel:first");					
	var modalBehavior = $find("modalBox");
	var thickboxId = $(thickBoxContent).attr("id");
		
	$(thickBoxContent).removeClass("hidden");
	
	if (!modalInitDone)
	{
		modalInitDone = true;
		modalBehavior.set_PopupControlID(thickboxId);
		modalBehavior.initialize();				
	}	
	
	modalBehavior.show();			
}

function hideModalDialog()
{
	var modalBehavior = $find("modalBox");
	modalBehavior.hide();		
}

function ShowHideBenefits(clicker)
{	
	var theTD = $(clicker).parents("td:first");
	var hiddenItems = $(theTD).find("li:hidden");

	if ($(hiddenItems).length > 0)
	{
		$(hiddenItems).slideToggle(20);
		clicker.innerHTML = "less";
	}
	else
	{
		$(theTD).find(".hidden-benefits").slideToggle(20);
		clicker.innerHTML = "more";		
	}
}

function ShowHideCharges(clicker) {
    var theTD = $(clicker).parents("td:first");
    var hiddenItems = $(theTD).find("li:hidden");
    
    if ($(hiddenItems).length > 0) {
        $(hiddenItems).slideToggle(20);
        clicker.innerHTML = "less";
    }
    else {
        $(theTD).find(".hidden-charges").slideToggle(20);
        clicker.innerHTML = "more";
    }
}

function toggleControl(controlToToggle)
{
	var control = $get(controlToToggle);

	if (control.style.display == "none")
		control.style.display = "block";
	else
		control.style.display = "none";

	return true;
}

$(function() {
	$("div[class*='reviewsummary']").each(function()	{
		$(this).find("div[class='showalllink']").find("a").click(function() {
			var divExtraText = $(this).parents("div[class*='reviewsummary']").find("div[class*='togglesection']");

			if ($(divExtraText).is(":visible"))
			{
				divExtraText.slideUp("fast", null);
				$(this).text("Show");
			}
			else
			{
				$("div[class*='reviewsummary']").find("div[class*='togglesection']:visible").slideUp();
				divExtraText.slideDown("fast", null);
				$("div[class*='reviewsummary']").find("div[class='showalllink']").find("a").text("Show");
				$(this).text("Hide");
			}
			
			$(this).blur();

			return false;
		});
	});
})

//CCD compliance on directory pages + call to new credit cards js for best buy tables.
$(document).ready(function() {
    $("table.us-resultstable tr:gt(0)").each(function() {
        var $row = $(this);
        if ($row.find('td').length == 5) {
            var apr = $row.find("td:nth-child(4)").text().replace("APR", "").replace("Representative variable", "");
            $row.after("<tr><td colspan=5 style='border-left:1px solid lightgrey;border-bottom:2px solid lightgrey;font-size:1.0em;font-weight:400;'>Representative example: When you spend £1,200 at a rate of " + apr + " (variable) per annum, your Representative APR is " + apr + " APR (variable). </td></tr>");
        }
    });

    $('#us-wrapper').append("<script src='http://www.uswitch.com/credit-cards/javascripts/top_deals.js' type='text/javascript'></script>");
})


