// All my jQuery in one little (or big) package.

$(document).ready(function(){

// SITE INITIALIZATION

$.scrollTo('0px',{duration:1});		// For some reason, this works on making sure the page is reloaded to the top.


// ARTICLE ALIGNMENT

var marginBot = $(window).height() - 260;
$('#article').css('height',marginBot);
$('#aligner').css('vertical-align','middle');


// TOOLTIPS

$(".more_bar li a").hover(function() {$(this).next("span").show();},function() {$(this).next("span").hide();});			// This is minimized code for the more_bar tooltips.
$(".more_bar_reversed li a").hover(function() {$(this).next("span").show();},function() {$(this).next("span").hide();});	// Same goes here, but for the reversed bar.


// TOOLBAR

var amIScrolling = false;
var windowHeight = $(window).height();
	
$("ul.more_bar_reversed").hide();		// Hiding the bottom bar until it's needed.	
	
$("li.other_thoughts").click(function () { 	// onClick event to scroll down to the bottom of the page.
	var amIScrolling = true;
	var fixedHeight = $(window).height() + 5;
   	// $("ul.more_bar").hide();	
	$.scrollTo(fixedHeight, {
		duration: 800, 
		axis:'y',
		onAfter:function() {$("ul.more_bar_reversed").css("top","-50px");$("ul.more_bar_reversed").show().animate({top:"0"}, 1000).css('position','fixed').css('top','0');}
		});
	});
	
$("li.main_thought").click(function () {	// onClick even to scroll back up to the top of the page.
	var amIScrolling = true;
	$("ul.more_bar_reversed").hide();
	$.scrollTo('0px', {
		 duration: 800,
		 axis:"y"
//		 onAfter:function() {
//		 	$('ul.more_bar_reversed').css('top','-50px').show().stop().animate({'top':'0'}, 1000);
//			}
		 });
	 });	

// TOOLBAR SCROLLING FUNCTION	 
	 
$(window).scroll(function () {
	if (amIScrolling == false){
		var scrollWhere = $(window).scrollTop();
		if (scrollWhere <= 1){$('ul.more_bar').css("bottom","-50px").show().animate({'bottom':"0"}, 1000);}
		else if (scrollWhere >= 20){$('ul.more_bar').hide();}
	}
});	 

$(window).scroll(function () {
	if (amIScrolling == false){
		var scrollWhere = $(window).scrollTop();
		console.log(scrollWhere);
		console.log(windowHeight);
		if (scrollWhere < windowHeight){$('ul.more_bar_reversed').hide();}
//		else if (scrollWhere = windowHeight - 5){$('ul.more_bar_reversed').css('top','-50px').show().stop().animate({'top':'0'}, 1000).css('position','fixed').css('top','0');}
		else if (scrollWhere > windowHeight + 10){$('ul.more_bar_reversed').show().stop().css('position','fixed').css('top','0');}
//		else if (scrollWhere > windowHeight){$('ul.more_bar_reversed').show().stop().css('position','fixed').css('top','0');}
	}
});	

	 
// IMG HOVERS

$("img").hover(
	function () {$(this).next("span").show();},
	function () {$(this).next("span").hide();}
	);
	
});
