/******************************************************
* Z-Bot jQuery-UI Animations
******************************************************/

/******************************************************
* Infobar Animation
******************************************************/
jQuery(document).ready(function() {

	/* Set initial Window and Footer Height */
	var window_height = $(window).height();
	var footer_height = $('#footer').height() + $('#mumbo-jumbo').height();

	/* If window is resized, update Window Height */
	$(window).bind('resize', function(){
		var window_height = $(window).height();
	});

	$('#info-bar .slide-container').after('<span class="slide-toggle">Slide It</span>');

	/* Basic Button Toggle */
/*	$('#info-bar .slide-toggle').toggle( retractInfoBar, expandInfoBar ); */

	$('#info-bar .slide-toggle').addClass('expanded');
	$('#info-bar .slide-toggle').click(function() {
		if ( $(this).is('.expanded') ) {
			retractInfoBar();
		}
		else {
			expandInfoBar();
		}
	});

	/* Auto Expand/Contract at Bottom of Scroll */
	/* Only triggers if Window Height is less than height of Sidebar + Footer */
	if (window_height <= ($('#sidebar').height() + footer_height)) {
			$(window).scroll(function() {
				if ($(document).height() <= ((window_height + $(window).scrollTop()) + footer_height)) {
					retractInfoBar();
				} else {
					expandInfoBar();
				}
			});
	}

	/* Expand / Retract Functions */
	function retractInfoBar(){
		$('#info-bar .slide-container').slideUp(200);
		$('#info-bar .slide-toggle').addClass('retracted').removeClass('expanded');
	};

	function expandInfoBar(){
		$('#info-bar .slide-container').slideDown(200);
/*
		var scrollback = $(document).height() - $('#info-bar').height();
		alert('Scrollback is ' + scrollback);
		$('html, body').animate({scrollTop: scrollback}, 200);
*/
		$('#info-bar .slide-toggle').addClass('expanded').removeClass('retracted');
	};

});

