$(document).ready(function(){
	$('.holder input, .holder textarea, .holder select').focus(function() {$(this).closest('.holder').addClass('focus');});
	$('.holder input, .holder textarea, .holder select').blur(function() {$(this).closest('.holder').removeClass('focus');});
	$('.holder .required').blur(function() {
		if ($(this).val().replace(/\s+/) == '') {
			$(this).closest('.holder').addClass('error');
			$(this).siblings('.required_text').fadeIn('fast');
		} else {
			$(this).closest('.holder').removeClass('error');
			$(this).siblings('.required_text').fadeOut('fast');
			if ($(this).attr('id').search(/email/) != -1) {
				if ($(this).val().search(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i) == -1) {
					$(this).closest('.holder').addClass('invalid');
					$(this).siblings('.invalid_text').fadeIn('fast');
				} else {
					$(this).closest('.holder').removeClass('invalid');
					$(this).siblings('.invalid_text').fadeOut('fast');
				}
			}
		}
	});
	up_next_closed = false;
	if ($('.article').length > 0) {
		$(window).scroll(function() {
			var point_of_interest = $('.article').offset().top + $('.article').height() - $(window).height();
			if (up_next_closed == false && $(this).scrollTop() > point_of_interest) {
				$('#up_next').fadeIn('slow');
			}
			if ($(this).scrollTop() < point_of_interest - 200) {
				$('#up_next').fadeOut('fast');
			}
		});
	}

	$('.accordion .title').click(function() {
		$('.accordion .section').removeClass('selected');
	 	$('.accordion .content').slideUp('normal');
		if($(this).next().is(':hidden') == true) {
			$(this).closest('.section').addClass('selected');
			$(this).next().slideDown('normal');
		 } 
	 });
	$('.accordion .content').hide();
	$('.accordion .selected .content').show();
});


(function( $ ){
	$.extend( {
		Twitter: function( username, numPosts, fnk ) {
			var info = {};
			
			// If no arguments are sent or only username is set
			if( username == 'undefined' || numPosts == 'undefined' ) {
				return;
			} else if( $.isFunction( numPosts ) ) {
				// If only username and callback function is set
				fnk = numPosts;
				numPosts = 5;
			}
			
			var url = "http://twitter.com/status/user_timeline/"
				+ username + ".json?count="+numPosts+"&callback=?";

			$.getJSON( url, function( data ){
				if( $.isFunction( fnk ) ) {
					fnk.call( this, data );
				}
			});
		}
	});
})( jQuery );
