$(document).ready(function(){

	var themeroot = "/wp-content/themes/treecarving/";
	$("#gallery h2").after('<p class="random"><a href="#random">Click!</a></p>');

	$("body").append('<img src="'+themeroot+'gfx/green-loady.gif" id="l" alt="Loading" />');
	function randomGalleries() {
		$(".random").html('');
		$("#l").appendTo(".random");
		$.get("/",{
			ajax: 1,
			homegal: 1
		},function(galleries){
			$(".gallery-wrap")
				.fadeOut("normal",function(){
					$(this)
						.empty()
						.html(galleries)
						.fadeIn("normal");
					$("#l").appendTo("body");
					$(".random").html('<a href="#random">Click!</a>');
					$(".random a").click(randomGalleries);
				});
		});
		return false;
	}
	$(".random a").click(randomGalleries);

	// initialise quotes cycler
	$('#quotes-box')
		.load("/wp-content/themes/treecarving/testimonials.php",function(){
			$("#quotes-box").cycle({
				sync: 0,
				timeout: 10000
			});
		});
	
	// remove text widows in titles
	var h2Text = '';
	$('h2 a,h1 a,h3 a').each(function() {
		h2Text  = $(this).text().replace(/ (\S+)$/,'&nbsp;$1');
		$(this).html(h2Text);
	});

});
