/*
  AVAC
  Copyright (C) 2008-2009 by Systemantics, Bureau for Informatics

  Lutz Issler
  Mauerstr. 10-12
  52064 Aachen
  GERMANY

  Web:    www.systemantics.net
  Email:  mail@systemantics.net

  Permission granted to use the files associated with this
  website only on your webserver.
*/



var z = 1;

$(function() {
	// Create an intro paragraph
	$("#content p:first").addClass("intro");
	$("#content > p:not(.intro)").wrapAll('<div class="text"></div>');

	// Format the columns in the contact section
	$(".column:first").addClass("first");

	// External links
	$("a.external, a[href^=http://]").click(function() {
		window.open(this.href);
		return false;
	});

	if ($(".content.page").length>0) {
		// Make columns
		var col2 = $('<div class="column"></div>')
			.prependTo(".content");
		var col1 = $('<div class="column first"></div>')
			.prependTo(".content")
			.append($(".content h2"))
			.append($(".text").children())
			.append($(".figures"));
		$(".text").remove();
		while (col1.height()>col2.height() && col1.children("p").length>1) {
			col2.prepend(col1.children("p:last"));
		}
		if ($(".figures").length==0 && col1.height()<col2.height()) {
			col1.append(col2.children("p:first"));
		}
		if (col2.children().length==0) {
			col2.append(col1.children("p:last"));
		}
	}

	// Move intro to the top
	$("#content").prepend($(".intro"));

	// Make figures functional
	$(".figure a").click(function() {
		this.blur();
		$('<div class="enlarged"><img src="'+this.href+'" alt="" /></div>')
			.css({
				left: $(this).parent().offset().left,
				top: $(this).parent().offset().top
			})
			.click(function() {
				$(this).remove();
			})
			.appendTo("body");
		return false;
	});
});
