/**
 * 
 * @return
 */
function viewPortHeight() {
	// return opera's 'innerHeight' function, otherwise let jquery determine it...
	return window.innerHeight ? window.innerHeight : _jq_(window).height();
}

function positionContent() {
	var topCtHeight = _jq_("#topcontent").height();
	if (typeof(topCtHeight) == 'undefined') topCtHeight = 0;
	positionContent(topCtHeight);
}

/**
 * 
 * @param topCtHt - the height of the topcontent part in pixels
 * @return
 */
function positionContent(topCtHt) {
	var pageHeight = viewPortHeight();
	// set pagecontainer height to be as high as the viewport
	_jq_("#pagecontainer").height(pageHeight + "px");
	// determine the height of topcontainer as headerheight plus specified topContentHeight
	var topCt = _jq_("#topcontent");
	var topContainerHeight = _jq_("#header").height() + topCtHt;
	if (topCtHt != topCt.height()) {
		topCt.height(topCtHt + "px");
		if (topCtHt == 0) topCt.hide();
		else topCt.show();
		_jq_("#topcontainer").height(topContainerHeight + "px");
	}
	// determine height of contentcontainer as pagecontainer minus topcontainer and footercontainer
	var contentHeight = pageHeight - topContainerHeight - _jq_("#footercontainer").height();
	// determine height of bottomcontent as contentcontainer minus footerseparator
	var footerSeparatorHeight = _jq_("#footerseparator").height();
	var bottomContentHeight = contentHeight - footerSeparatorHeight;
	if (bottomContentHeight < 0) {
		// set contentcontainer to be just as high as the footerseparator
		contentHeight = footerSeparatorHeight;
		bottomContentHeight = 0;
		_jq_("body").css("overflow", "auto");
	} else {
		_jq_("body").css("overflow", "visible");
	}
	_jq_("#contentcontainer").height(contentHeight + "px");
	_jq_("#bottomcontent").height(bottomContentHeight + "px");
}

function setCurrentNavigation() {
	_jq_(".current").each(function() {
		var thisObj = _jq_(this);
		// get the content for the attached anchors (assume there's only one!)
		var content = _jq_("li.current > a:first >span:first").text();
		// clear this object
		thisObj.empty();
		// attach the content in a div
		thisObj.append("<span>"+content+"</span>");
	});
}

/**
 * 
 * @return
 */
function registerEventHandlers(readMsg, hideMsg) {
	// remove the focus-borders on links once where done with them
	_jq_("a").mouseup(function() {
		this.blur();
	});
	// toggle between read and hide for selected classed
	_jq_(".titleandbody > div > a.toggleread").toggle(function(e) {
		// using display:block let's spans with class body align corretly...
		_jq_(this).children(".body").css("display", "block");
		// we use html, because our messages may contain markup..
		_jq_(this).children(".readhide").html(hideMsg);
		return false;
	}, function(e) {
		_jq_(this).children(".body").hide();
		_jq_(this).children(".readhide").html(readMsg);
		return false;
	});
	// click the submit-button marked as default when enter is pressed in a form
	_jq_("form input, form select").keypress(function(e) {
		// no default button? -> let normal eventhandling occur
		if(_jq_(this).parents("form:first").find("button[type=submit].default, input[type=submit].default").length != 1) return true;
		
		if((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
			alert('enter key pressed!');
			_jq_(this).parents("form:first").find("button[type=submit].default, input[type=submit].default").click();
			return false;
		} else {
			return true;
		}
	});
}

/**
 * 
 * @param contentRef
 * @return
 */
function showMoreContent(contentRef) {
	// not done now:
	/*
	// get references to our content containers
	var contentB = _jq_("div#content_B div.innerbottomcontent");
	// get reference to the 'more content' div
	var content = _jq_(".long_" + contentRef).clone();
	content.show();
	// set the reference as the only child of contentB
	// first clear all elements in contentB
	contentB.empty();
	// then add it
	contentB.append(content);

	// hide contentA
	_jq_("#content_A").hide();
	// show contentB
	_jq_("#content_B").show();
	return false;
	*/
	// just return true to let normal eventhandling occur
	return true;
}

function hideMoreContent() {
	/* not done now:
	_jq_("div#content_B div.innerbottomcontent").empty();
	_jq_("#content_B").hide();
	_jq_("#content_A").show();
	return false;
	*/
	// just return true to let normal eventhandling occur
	return true;
}