$(function() {
	// Add sroll to #anchor links
	if ($('#homepage').get(0)) {
		$('a[href*=#]').click(function(evt) {
			var scrToElem = $(this).attr('href');
			var urlSplit = scrToElem.split('#');
			if ('more' != urlSplit[1].substring(0,4).toLowerCase()) {
				evt.preventDefault();
				$('html').scrollTo( scrToElem, 500);
				return false;
			}
		});
	}
	
	// Animate recent work on homepage
	if ($('#recent_work article').get(0)) {
		var $strong = $('#recent_work article a strong')
		$strong.css({'bottom': '-' + $strong.outerHeight() + 'px', 'opacity': '0.8'});
		$('#recent_work').delegate('article', 'mouseover mouseout', function(evt) {
			$(this).toggleClass('animate');
			$title = $(this).find('strong').eq(0)
			$title.stop().animate({
				'bottom': evt.type == 'mouseover' ? '0px' : '-' + $title.outerHeight() + 'px'
			});
		});
	}
	
	// Back to top links
	$('.top_link').hide();
	$('#recent_work, #recent_articles, #about_me').hover(function() {
		$(this).contents().find(".top_link").fadeIn(400);
	}, function() {
		$(this).contents().find(".top_link").fadeOut(200);
	});
	
	// Rotating logo
	if (! ($.browser.msie == true && $.version == 6)) {
		var $mainLogo = $('#main_logo');
		var $logoClone = $mainLogo.clone();
		var $headerCont = $mainLogo.parent().parent();
		$headerCont.append($logoClone);
		$mainLogo.remove();
		$('header').live('mouseenter mouseleave', function() {
			$(this).toggleClass('hover');
		});
	}
	
	// Cufon and font properties
	$('h2, h3').css({
		'font-size': '2.25em'
	});
	$('h4').css({
		'font-size': '1.5em'
	});
	$('h2 span, h3 span').css({
		'top': '-4px',
		'font-size': '0.75em'
	});
	
	Cufon.replace('h2, h3, h4', {
		'textShadow': '1px 1px #faf3e5'
	});
	Cufon.replace('#copyright', {
		'textShadow': '1px 1px #0b3c43'
	});
	
	// Large captial letter beginning each paragraph
	$('article > p, #about_me .section_content p:first, .intro p:first').each(function() {
		$para = $(this);
		$text = $para.text();
		$firstLetter = $text.substr(0,1);
		$text = $text.substr(1, $text.length);
		$para.text($text);
		$('<span class="cap">' + $firstLetter + '</span>').prependTo($para);
	});
	
	// Fix some CSS selectors that dont work in IE
	$('#contact_form input:text').addClass('text');
	$('#home_boxes li:last-child').addClass('last_col');
	$('#main_content .third_col:last-child').addClass('last_col');
	
	initialiseClock();
	if ($("#commentform").length > 0) {
		$("#commentform").validate();
	}


	
});
