$(document).ready(function(){

	// hide #back-top first
	$("#backToTop").hide();

	// fade in #back-top
	$(function () {
		$(window).scroll(function () {
			if ($(this).scrollTop() > 100) {
				$('#backToTop').fadeIn();
			} else {
				$('#backToTop').fadeOut();
			}
		});

		// scroll body to 0px on click
		$('#backToTop').click(function () {
			$('body,html').animate({
				scrollTop: 0
			}, 800);
			return false;
		});
	});

	var top = $('#meta').offset().top - parseFloat($('#meta').css('marginTop').replace(/auto/, 0));
	$(window).scroll(function (event) {
    // what the y position of the scroll is
    var y = $(this).scrollTop();

    // whether that's below the form
    if (y >= top) {
      // if so, ad the fixed class
      $('#meta').addClass('fixed');
    } else {
      // otherwise remove it
      $('#meta').removeClass('fixed');
    }
  });

	$("a[rel='blankwindow']").click( function() {
		window.open( $(this).attr('href') );
		return false;
	});

});
