/*
 * jQuery autoResize (textarea auto-resizer)
 * @copyright James Padolsey http://james.padolsey.com
 * @version 1.04
 */

(function(a){a.fn.autoResize=function(j){var b=a.extend({onResize:function(){},animate:true,animateDuration:150,animateCallback:function(){},extraSpace:20,limit:1000},j);this.filter('textarea').each(function(){var c=a(this).css({resize:'none','overflow-y':'hidden'}),k=c.height(),f=(function(){var l=['height','width','lineHeight','textDecoration','letterSpacing'],h={};a.each(l,function(d,e){h[e]=c.css(e)});return c.clone().removeAttr('id').removeAttr('name').css({position:'absolute',top:0,left:-9999}).css(h).attr('tabIndex','-1').insertBefore(c)})(),i=null,g=function(){f.height(0).val(a(this).val()).scrollTop(10000);var d=Math.max(f.scrollTop(),k)+b.extraSpace,e=a(this).add(f);if(i===d){return}i=d;if(d>=b.limit){a(this).css('overflow-y','');return}b.onResize.call(this);b.animate&&c.css('display')==='block'?e.stop().animate({height:d},b.animateDuration,b.animateCallback):e.height(d)};c.unbind('.dynSiz').bind('keyup.dynSiz',g).bind('keydown.dynSiz',g).bind('change.dynSiz',g)});return this}})(jQuery);

/* JavaScript for dbushell.com
 * @copyright David Bushell http://dbushell.com
 */

$(document).ready(function()
{
	// placeholder fallback (using code from Modernizr to detect)
	
	var f = document.createElement('input');
	var placeholder = !!('placeholder' in f);
	if (!placeholder) {
		var fields = $('.field', '#contactform');
		fields.each(function()
		{
			var txt = $(this).attr('placeholder');
			if (txt) {
				$(this).addClass('placeholder').val(txt).focus(function() {
					if ($(this).val() == txt) $(this).removeClass('placeholder').val('');
				}).blur(function() {
					if ($(this).val() == "") $(this).addClass('placeholder').val(txt);
				});
			}
		});
	}
	
	// reCaptcha for contact form and comments
	
	if (document.getElementById('contactform')) {
		var commentCaptcha = false;
		var commentCaptchaFocus = true;
		var commentCaptchaReady = false;
		recaptchaCallback = function() {
			commentCaptchaReady = true;
			if (commentCaptchaFocus) {
				Recaptcha.focus_response_field();
			}
		};
		showCaptcha = function() {
			commentCaptcha = true;
			Recaptcha.create(reCaptchaPublicKey,
				"contactform-recaptcha", {
				theme: "white",
		   	callback: recaptchaCallback
		   });
		};
		$('#contactform-submit', '#contactform').click(function() {
			if (!commentCaptcha) {
				showCaptcha();
			   return false;
			}
			$('.placeholder', '#contactform').each(function() {
				if ($(this).val() == $(this).attr('placeholder')) {
					$(this).val('');
				}
			});
			return commentCaptchaReady;
		});
		$('#contactform-enquiry', '#contactform').autoResize();
		$('#contactform-enquiry', '#contactform').keypress(function() {
			if (!commentCaptcha) {
				commentCaptchaFocus = false;
				showCaptcha(false);
			}/* else { // removed to allow for autoResize
				$(this).unbind();
			}*/
		});
		if (autoShowCaptcha) showCaptcha();
	}
	/*
	// "About Me" Timeline
	
	if (document.getElementById('timeline')) {
		var t = {
			$: $('#timeline', '#page'),
			e: ('#timeline-events', '#page'),
			s: null//, years: {}
		};
		$('a.year', t.$).each(function() {
			var y = { $: $(this) };
			y.e = $('#ev' + y.$.attr('id').substr(1), t.e);
			if (!t.s && y.$.hasClass('selected')) t.s = y;
			else y.e.hide();
			y.$.bind('click', function(e) {
				if (t.s) {
					t.s.e.fadeOut(250);
					t.s.$.removeClass('selected');
				}
				y.e.fadeIn(250);
				y.$.addClass('selected');
				t.s = y;
				return false;
			});
		});
		t.s.e.show();
	}*/

});




  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-9497100-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
