Cufon.replace('h2, .onecol h1, .threecol h1, .twocol h1, h3, h4, h5, h6, p.button a, li.submit, .teaser p.more a, p.phone-number, h1.call-us', {fontFamily: 'vag-light', hover: true });

$(document).ready(function() {
  	$("#main a[href$=pdf]").add().addClass("pdf");
	$("a[href=#]").attr("href","#this");
	$('ul#nav li:last-child, #sub-nav ul.sub-nested li:last-child, ul#toplinks li:last-child').addClass("last");
	$('#home-intro p:first-child').addClass("first");
	$("#extra div#side-products-nav li a, #footer #first a, #footer #links a, #footer #useful a, #footer #last #companydetails a").prepend("&raquo; ");
  	$('dl.faq > dd').hide(); 
  	$(".address_hide").hide();
  	$('dl.faq > dt').click(function() {
    $(this).next('dd').slideToggle('fast')
    .siblings('dd:visible').slideUp('fast');

  });
  	$('a[href*=.pdf],a[href*="://"]:not(a[href^="http://foresters.cms.netstep.co.uk/"]):not(a[href^="http://forestersfriendlysociety.co.uk/"]):not(a[href^="http://www.forestersfriendlysociety.co.uk/"])').click( function() {
		if($(this).attr("href").indexOf(".pdf") > -1) { // track page/pdf using google analytics
			//pageTracker._trackPageview($(this).attr("href"));
			_gaq.push(['_trackPageview',$(this).attr("href")]);
		}
                if (!$(this).hasClass("tandcpdf")) window.open( $(this).attr('href') );
                return false;
				if (!$(this).hasClass("kfd-confirmation")) window.open( $(this).attr('href') );
                return false;
        });
	$('div.rounded, #extra .teaser, div.box, #main').corner({
	  tl: { radius: 6 },
	  tr: { radius: 6 },
	  bl: { radius: 6 },
	  br: { radius: 6 }
	});
	$('.prodhome-box h2').corner({
	  tl: { radius: 4 },
	  tr: { radius: 4 },
	  bl: { radius: 0 },
	  br: { radius: 0 }
	});
	$('ul#nav').superfish();
	// menu highlight
	$('ul#nav li ul li.current').parent('ul').parent('li').addClass('current');

	$("h1 ~ ul li").each ( function() { // loop through each ul that is a direct sibling after the h1 tag
		if ($("a[href*=#this]", this).length > 0) {
			$(this).wrapInner("<div class='expandBlock'></div>");
			$("a[href^=#this]", this).clone().prependTo($(this));
			$(".expandBlock a[href^=#this]", this).remove();
		}
	});
	$("div.expandBlock ul li").css("position","static");
	$("div.expandBlock").each( function() {
		if ($(this).prev("a[href*=#this]").length > 0) {
			$(this).toggle();
		}
	});
	$("a[href*=#this]").mousedown( function() {
		$(this).next("div").animate( {
			opacity: "toggle",
			height:	"toggle"
			} , 1000
		);
	});	

	$("span.tandcpdf a").addClass("tandcpdf");
	$("a .tandcpdf").closest("a").addClass("tandcpdf");
	$("a.tandcpdf").mousedown( function() {
		if (confirm("Please click 'OK' to confirm that you have read and understood the Key Features, How you share in the profits of Foresters and Key Facts documents")) {
			window.open($(this).attr('href'));
			return true;
		} else {
			e.stopPropagation();
			e.preventDefault();
			return false;			
		}
	});
	
	$("span.kfd-confirmation a").addClass("kfd-confirmation");
	$("a .kfd-confirmation").closest("a").addClass("kfd-confirmation");
	$("a.kfd-confirmation").mousedown( function(e) {
		if (confirm("Please click OK to confirm you have read and understood the Key Features Document")) {
			window.open($(this).attr('href'));
			return true;
		} else {
			e.stopPropagation();
			e.preventDefault();
			return false;			
		}
	});
});

function postcodeLookup() {
	var postcode = $("#postcode").val();
	var houseno = $("#houseno").val();
	if (postcode.length == 0) {
		alert("Please enter your postcode");
	} else {
		$(".addressError").hide();
		var url = "/postcode/postcode_lookup.php";
		returnVal = $.get(	url,
				{
					postcode	: postcode,
					houseno		: houseno
				}
				, function(data) {
					if ($(data).find("record").length > 0) {
						populateHTMLElements(data);
					} else if (data == 'error') {
						$(".addressError").show();
					} else {
						$("#addressListHolder").html(data);
					}
				}
				,"html"
		);
	}
}
function selectAddress() {
	var addressID = $("#addressList").val();

	var url = "/postcode/postcode_lookup.php";
	returnVal = $.get(	url,
			{
				addressID	: addressID
			}
			, function(data) {
				populateHTMLElements(data);
			}
			,"xml"
	);
}
function populateHTMLElements(xml) {
	$("#addressListHolder").hide();
	$(".address_hide").show();
	$("#company").val($(xml).find("organisation").text());
	$("#line1").val($(xml).find("line1").text());
	$("#line2").val($(xml).find("line2").text());
	$("#line3").val($(xml).find("line3").text());
	$("#town").val($(xml).find("town").text());
	$("#county").val($(xml).find("county").text());
	$("#country").val($(xml).find("country").text());
}

function showContent() {
	$("#extra-content").fadeIn();	
}

function showConfirm(strMessage) {
	if (confirm(strMessage)) {
		return true;
	} else {
		return false;
	}
}
