$(function() {
	function fieldBlur(id, str) {
		id = 'input#' + id;

		$(id).addClass('formblur').val(str);

		$(id).focus(function() {
			$(this).removeClass();
			if ($(this).val() == str) {
				$(this).val('');
			}
		});

		$(id).blur(function() {
			$(this).removeClass().addClass('formblur');
			if ($(this).val() == '') {
				$(this).val(str);
			}
		});
	}

	fieldBlur('gsearch', 'Search Google...');
	fieldBlur('comment', 'Post a comment...');
	
	$().ckeditor && $('textarea#editor').ckeditor({
		'customConfig': '../js/ckconfig.php'
	});
	
	$().AnyTime_picker && $('input.datetime').AnyTime_picker({
		'format': '%m/%d/%Y %l:%i %p'
		//'hideInput': true,
		//'placement': 'inline'
	});
	
	var $sidebar = $('#fixside');

	if ($sidebar.length) {
		var $window = $(window);
		var offset = $sidebar.offset();
		var topPadding = 15;

		$window.scroll(function() {
			if ($window.scrollTop() > offset.top) {
				$sidebar.stop().animate({
					marginTop: $window.scrollTop() - offset.top + topPadding
				});
			} else {
				$sidebar.stop().animate({
					marginTop: 5
				});
			}
    		});
	}
});

