function nl2br (str, is_xhtml) {
	var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '' : '<br>';
	return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
}

$(function(){
	var url = "http://www.biblegateway.com/votd/get?format=json&version=31&callback=?";

	$.getJSON( url, function( data ){
		$("#verse").html(data['votd'].text);
		
		var reference = data['votd'].display_ref + " " + data['votd'].version_id;
		var permalink = "<a href='"+data['votd'].permalink +"' target='blank'>"+ reference+"</a>";
				
		$("#reference").html(permalink);
	});
	
	// get the latest blog entry
	
	var url = "http://www.citylifehull.co.uk/pastors_blog/?feed=json&jsonp=?";
	
	$.getJSON( url, function( data ){
		$("#blog").html("<h2>"+data[0].title+"</h2><p>"+data[0].content+"<br><span class='date'>"+data[0].date+"</span></p>");
	});
	
	
	// hide the hidden areas
	$(".hidden").hide();
	
	// when a hidden link is clicked get it's 'rel' attribute and show the element with the id
	$(".hidden_link").click(function(){
		var id = "#"+$(this).attr('rel');		
		$(id).slideToggle("slow");	
		$(this).hide(); // hide the link
	});
	
	// when a shown link is clicked get it's 'rel' attribute and hide the element with the id
	$(".shown_link").click(function(){
		var id = $(this).attr('rel');
		var paragraph = "#"+id;	// the id of the paragraph to hide	
		$(paragraph).slideToggle("slow");	
		
		// show the "show more" link again
		var element = $(".hidden_link").attr("rel",id);
		$(element).show();	
	});
});
