$(function(){

// make the boxes sit together
	$('#content').masonry({ columnWidth:255 });
	$('.fontface h4').addClass('jqd'); // change size/line height to compensate for masonry + font-face flicker
	setTimeout(function() { $('#content').masonry({ columnWidth:255 }); }, 2000); // then call masonry again to compensate for @font-face resize
	
// defuscate all email links	
	$('.obfuscated').defuscate();
	
// admin bar hiding
	$('#adminbar.hideable').css({ opacity:0 }); //.css({ opacity:0, 'display':'block' });
	$('#adminbar.hideable').hover(
		function(){ $(this).stop().animate({opacity:1}, 300); },
		function(){ $(this).stop().animate({opacity:0}, 300); }
		);

/// menu fading
	$('.menu li')
		.removeClass('csshover') // this class is hooked into for the css rollover
		.find('a')
		.removeClass('csshover') // for RSS icon
		.prepend('<span class="jhover" />') // this span should have the same bg as the :hover state in the css
		.each(function() {
			var $span = $('> span.jhover', this).css('opacity', 0);//.css('top',30);
			$(this).hover(
				function () { $span.stop().animate({opacity:1}, 100); }, // on hover
			 	function () { $span.stop().animate({opacity:0}, 500); } // off hover
			
				// function () { $span.stop().animate({opacity:1,top:'0'}, 200); },//.fadeTo(200, 1); },
			 	// function () { $span.stop().animate({opacity:0,top:'-30'}, 200).top('30'); }//.fadeTo(400, 0); }
				);
		});

/// hide footerbg if the page is too short
	var $pageheight = $(document).height();
	if($pageheight < 950) { $('#footerbg').addClass('hide'); }
	
	
// box1 (in list) rollover
	$('.linked').hover(
		function () { $(this).find('.boxbg').stop().animate({opacity:1}, 300); }, // on hover
	 	function () { $(this).find('.boxbg').stop().animate({opacity:0.4}, 400); } // off hover
	);

	
	
	
// contact form behaviour:
	
	$('input').addClass("blurfield");
	$('input, textarea').focus(function() {
		$(this).removeClass("blurfield").addClass("focusField");
		if (this.value == $(this).attr('title')) { this.value = ''; } else { this.select(); } // compare the value with the 'title' attr
	});
	$('input, textarea').blur(function() {
		$(this).removeClass("focusField").addClass("blurfield");
		if ($.trim(this.value) == '') { this.value = $(this).attr('title'); } // return to default (but HOW?)
	});

	$('#contactform').submit(function() {
		// alert($('input#subject').val() + ' called.');
		
		$('#contactform input[type=text], #contactform textarea').each(function(index) {
			if($(this).val() == $(this).attr('title')) { $(this).val(""); }
			// console.log($(this).val() + " - " + $(this).attr('title'));
		});
		
		// return false;
	});
	
	// slide away 'success' message
	
	$('p.success').delay(2000).slideUp(800, function() {
		$('#content').masonry({ columnWidth:340, animate:true });
	});
	
	
	$('.missing:first').focus();
	$('.invalid:first').focus();
	
	// $('.missing:first, .invalid:first').focus(function() { $(this).value = $(this).value; })
	
	
});
