// menu alive
// (c) copyright 2010 mauro gallo - web creations Caorle (VE) 
// all rights reserved
// vers. 1.0.2
var dHeight, mHeight, scrollTop, wHeight;
var moving = false;
 
$(document).ready(function () {
							dHeight = $(document).height(); // altezza documento
							// altezza menu
							mHeight = parseInt($("#clock").outerHeight()) + parseInt($("#nav").outerHeight()) + parseInt($("#footMenu").outerHeight());
							$(window).scroll(menuAlive);
							$(window).resize(menuAlive);
							menuAlive();
							});

function menuAlive() {
	scrollTop = $(document).scrollTop(); // posizione scrollbar
	wHeight = $(window).height(); // altezza finestra browser
	if (!moving && wHeight > mHeight && dHeight >= (wHeight + scrollTop)) {
		moving = true;
		slidingAfterScroll();
	}
}

function slidingAfterScroll() {
	var scrolling = $(document).scrollTop();
	var windowResizing = $(window).height();
	setTimeout(function () {
						  if (scrolling == scrollTop && windowResizing == wHeight) {
							  $(window).unbind("scroll", menuAlive);
							  $(window).unbind("resize", menuAlive);
							  $("#menu").animate({top : (scrollTop - 80)}, 500, function () {
																						  moving = false;
																						  $(window).scroll(menuAlive);
																						  $(window).resize(menuAlive);
																						  });
						  }
						  else 
							  slidingAfterScroll();
						 }, 100);
}
