
/* generate a random number */
function rand($max_val) {
	var $rand_no = Math.random();
	$rand_no = $rand_no * $max_val;
	$rand_no = Math.ceil($rand_no);
	return $rand_no;
}

/* calculate how far the window has been scrolled */
function f_scrollTop() {
	var n_win = window.pageYOffset ? window.pageYOffset : 0;
	var n_docel = document.documentElement ? document.documentElement.scrollTop : 0;
	var n_body = document.body ? document.body.scrollTop : 0;
	var result = f_filterResults(n_win, n_docel, n_body);
	return result;
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel))) {
		n_result = n_docel;
	}
	var result = n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
	return result;
}

/* respond to change in window width */
function windowResized() {
	var $loginLeft = $("#login_register").position().left;
	var $navbarRight = $("#last_tab").position().left + $("#last_tab").width();

	//alert($loginLeft + " <= " + $navbarRight + " - " + $("#nav_tabs").width())
	if ($loginLeft <= 675) {
		$("div#login_register").css("top", 75 );
	} else {
		$("div#login_register").css("top", 105 );
	}
}

/* add the selected tab as the top item in the page menu */
function add_tab_selection_to_page_menu () {
	var $element_to_copy_over;
	$html_of_active_tab = $("ul#nav li.here").html();
	if ($html_of_active_tab) {;
		if ( $("ul#nav_sub .here").length > 0 ) {
			$element_to_copy_over = "<li>" + $html_of_active_tab + "</li>";
		} else {
			$element_to_copy_over = "<li class=\"here\">" + $html_of_active_tab + "</li>";
		}
		$("ul#nav_sub").prepend($element_to_copy_over);
	}
	$("ul#nav_sub a:contains('Help save these precious places')").css("color","#0026ff");
}
