$(document).ready(function() {
	
	// Prevent site from being loaded in an iframe ala Digg
	if(location.href!=top.location.href){
		top.location.href=location.href
	}
	
	
	// Add four spans to images for rounded-corner-goodness
	$(".roundedimage").prepend('<span class="una"></span><span class="duo"></span><span class="tres"></span><span class="quattuor"></span>');
	
	
	// Insert a witty comment into the browser-hate message for IE
	var browserHateCaptions = new Array(
		"After browsing this site why not go and watch a Betamax!",
		"Are you a historian? Why else would you use something this old to browse the net?!",
		"You broke the Internets!",
		"Boldy using a browser not even its creator recommends anymore!",
		"Heard of this thing called the Internet? It's changed a lot since your browser came out!",
		"Upgrade for the that fresh Web 3.0 feel"
	);
	$("#browser-hate-caption").text(browserHateCaptions[Math.round(Math.random()*browserHateCaptions.length)-1]);
	
	
	// Add comment reply details
	$('li.comment header p').append(' | <a href="#comment-form" class="comment-reply-to-add-link" title="Reply to this comment">reply</a>');
	$('li.comment header p a').click(function() {
		var commentID = $(this).parent().parent().parent().attr('id');
		var commenter = $(this).parent().parent().find('h4').text();
		$('#comment-form input[name="replyid"]').val(commentID);
		$('#comment-form-reply-text').fadeTo("fast",1).html('RE: '+commenter+' <a href="#remove" title="Remove this reply link" id="comment-form-reply-delete">x</a>');
		$("#comment-form-reply-delete").bind('click', function() {
			$('#comment-form input[name="replyid"]').val('');
			$('#comment-form-reply-text').text('Reply link removed');
			setTimeout('$("#comment-form-reply-text").fadeTo("slow",0);',500);
			return false;
		});
	});
	
	
	// Display default form values until click
	$('.comment-form input').example(
		function() { return $(this).attr('title'); },
		{ className: 'comment-form-default' }
	);
	$('#live-search-form').example(
		function() { return $(this).attr('title'); },
		{ className: 'live-search-default' }
	);
	
	
	// Automatically scroll to all inpage anchor links
	$.localScroll({
		duration: 450
	});
	
	
	// Add livesearch to header search box
	$("#live-search-form").livesearch({
		url: '/ajax/search/?s='
	});
	
	
	// Add menu dropdown animations
	$("#top nav li").hover(
	  function () {
	  	$(this).children("ul").fadeIn("fast");
	  },
	  function () {
	  	$(this).children("ul").fadeOut("fast");
	  }
	);

	
	// Scroll Twitter page previous tweets
	$("#archives-twitter-one-year-ago, #archives-twitter-two-years-ago").codaSlider({
		dynamicArrows: false,
		dynamicTabs: false,
		autoHeight: false,
		autoSlide: true,
		autoSlideInterval: 10000,
		slideEaseDuration: 2000,
		slideEaseFunction: 'easeInOutQuad'
	});


	// Click tracking
	$("a:not([href*=hybridlogic.co.uk])").not("[href*=#]").not("[href*=javascript]").mousedown(function() {
		var arg_href = $(this).attr("href");
		$.post("/ajax/tracker", {href:arg_href});
	});
	
	
	
});