var hideDelay = 10;
var hGap = 0;
$(document).ready(function()
	{ // when html is loaded
	$('div.popmenu').popMenu();
	setTall();
	});

(function($)
	{
	$.fn.popMenu = function()
		{
		return this.each(function()
			{
			var self = $(this);
			self.data('hiding', false); // init timeout id
			var id = self.attr('id');
			var menuEl = $('a.'+id); // menu link class = dropdown id
			// position under menu link; using offsetHeight because height() seems to give the link's non block height
			pos = menuEl.offset();
			height = menuEl.attr('offsetHeight');
			if (typeof(height) == "undefined")
				return;
			self.css({'left': (pos.left+hGap)+'px', 'top': (pos.top + height)+'px'});
			// apply hover (mouseover, mouseout) to both menu link and dropdown.
			$.each([self, menuEl], function()
				{
				$(this).hover(
					function()
						{
						if (self.data('hiding'))
							{
							clearTimeout(self.data('hiding'));
							self.data('hiding', false);
							}
						$('div#'+id).show();
						menuEl.addClass('current');
						},
					function()
						{ // delay hide so if the pointer passes between the menu and dropdown the hide can be cancelled
						self.data('hiding', setTimeout(function()
							{
							menuEl.removeClass('current');
							$('div#'+id).hide();
							}, hideDelay));
						});
				});
			});
		}
	})(jQuery);

function setTall()
	{
	var otherOuterHeight = $('#header').outerHeight(true) + $('#menu').outerHeight(true) + $('#footer').outerHeight(true);

	var content = $('#content');
	var contentOuterHeight = content.outerHeight(true);
	var contentPadEtc = contentOuterHeight - content.height();

	var leftbar = $('#leftcol');
	var leftbarOuterHeight = leftbar.outerHeight(true);
	var leftbarPadEtc = leftbarOuterHeight - leftbar.height();

	var rightbar = $('#rightcol');
	var rightbarOuterHeight = rightbar.outerHeight(true);
	var rightbarPadEtc = rightbarOuterHeight - rightbar.height();

	var maxHeight = Math.max(contentOuterHeight, Math.max(leftbarOuterHeight, Math.max(rightbarOuterHeight, $(window).height()-otherOuterHeight)));
	content.height(maxHeight - contentPadEtc);
	}

function showWin()
  {
  var w = window.open('','popup','width=600,height=500,resizable,scrollbars,status,left=80,top=80');
  w.document.clear();
  w.focus();
  return true;
  }
function showSearch()
	{
	window.name='origin';
	var w = window.open('','search','width=250,height=550,resizable,scrollbars,status,top=0,left=0');
	w.document.clear();
	w.focus();
	return true;
	}

function mailIt()
	{
	var email = "info@thredbo.org";
	var a = email.split("@");
  document.write("<a href=" + "mail" + "to:" + a[0] + "@" + a[1] + ">(click here)</a>")
	}

