/*
  Systemantics 2.0
  Copyright (C) 2010 by Systemantics, Bureau for Informatics

  Systemantics GmbH
  Am Lavenstein 3
  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.

  Changes to these files are PROHIBITED due to license restrictions.
*/



$(function() {
	$(".menu ul li:first-child").click(function() {
		location.href = $(this).parent("ul").find("li:eq(1) a").attr("href");
	});

	if ($.browser.msie && $.browser.version.substr(0, 1)=="7") {
		var lastMenu = false;
		$(".menu").hover(
			function() {
				lastMenu = $(this);
				$(this).addClass("hover");
			},
			function() {
			}
		);
		$('<div id="menuback"></div>')
			.mouseenter(
				function() {
					if (lastMenu) {
						lastMenu.removeClass("hover");
					}
				}
			)
			.appendTo("body");
	}

	$(".project, .example").css("height", "32px");
	$(".project h2 a, .project h2, .example h2").click(function() {
		this.blur();
		var p = $(this).parents(".project, .example");
		var img = $("img", p);
		if (p.hasClass("expanded")) {
			// Collapse
			if (img.length>0) {
				$("body").css("background-image", "none");
			}
			p.removeClass("expanded");
			p.animate({height: 32}, 250);
		} else {
			// Expand
			if (img.length>0) {
				$("body").css("background-image", "none");
			}
			$(".expanded")
				.removeClass("expanded")
				.animate({height: 32}, 500);
			p.addClass("expanded");
			p.animate({height: $(".details", p).height()+32}, 500, function() {
				if (img.length>0) {
					$("body").css({
						backgroundImage: "url("+$("img", p).attr("src")+")",
						backgroundPosition: "171px "+p.offset().top+"px"
					});
				}
			});
			if (p.is(".project")) {
				location.hash = p.attr("id").substr(1);
				pageTracker._trackEvent("Projects", "View", p.attr("id").substr(1));
			}
		}
		return false;
	});
	var p = $("#p"+location.hash.substr(1));
	var year = $("#p"+location.hash.substr(1)).parents(".year");
	if ($(".year").index(year)>0) {
		p
			.css("height", "auto")
			.addClass("expanded");
		$(window).scrollTop(year.offset().top-24);
		$("body").css({
			backgroundImage: "url("+$("img", p).attr("src")+")",
			backgroundPosition: "171px "+p.offset().top+"px"
		});
	}

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

	$(".cols").columnize({
		columns: 2,
		column: "col text",
		balance: true
	});

	$(".details p, .details dt, .details dd").wrapInner("<span></span>");
});
