$(document).ready(function() {

	$('div#grid-view').show();
	$('div#list-view').hide();
	$('div.no-comments-yet').hide();
	$('div.comments-hidden').hide();
	$('div#grid').addClass('current');
	$('div#list').removeClass('current');
	$('input.search-box').attr('value', 'search here...');

	// Search box behavior
	$('input.search-box').focus(function(){
		if ($(this).attr("value") == "search here...") $(this).attr("value", "");
                $(this).addClass("selected");
                });
	$('input.search-box').blur(function(){
		if ($(this).attr("value") == "") $(this).attr("value", "search here...");
                $(this).removeClass("selected");
                });

	// View Settings
	$('div#list').click(function() {
		$('div#grid').removeClass('current');
		$('div#list').addClass('current');
			$('div#grid-view').fadeOut('fast');
			$('div#list-view').fadeIn('slow');
	});

	$('div#grid').click(function() {
		$('div#grid').addClass('current');
		$('div#list').removeClass('current');
		$('div#list-view').fadeOut('fast');
		$('div#grid-view').fadeIn('slow');
	});

	$('div.leave-comment').click(function() {
		$('div.no-comments-yet').slideDown('slow', function() {
		$('div.leave-comment').slideUp('fast');
		});
	});

	$('div.view-comments').click(function() {
		$('div.view-comments').slideUp('fast', function() {
		$('div.comments-hidden').slideDown('slow');
		});
	});


	var helpdivhtml = '<div id="helpScrollDiv" style="position:fixed;top:0;left:0;"></div>';
	$('body').prepend(helpdivhtml);

	var helpdivhtmlnavhelper = '<div id="helpScrollDivNavHelper" style="position:fixed;bottom:0;left:0;"></div>';
	$('body').prepend(helpdivhtmlnavhelper);


	$(document).keydown(function(event) {
				var speed = 400;
				// helpdiv - see current top position in the window of the browser
				var helpdiv = $('#helpScrollDiv').offset().top;

				if (event.keyCode == 38) {
					$('html,body').animate({scrollTop: helpdiv-450}, speed);
					event.preventDefault();
				} else if (event.keyCode == 40) {
					// if the top position of the window is above case slider
					// then make scroll to the top edge of the case slider
					if(helpdiv <= offsetpx-2) {
						var offsetpx = $('#caseSlider').offset().top;
						$('html,body').animate({scrollTop: offsetpx}, speed);
					} else {
						$('html,body').animate({scrollTop: helpdiv+450}, speed);
					}
					event.preventDefault();
				}

	});

});


