/*
  Bureau Lofvers
  Copyright (C) 2008 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.
*/

function menuClose() {
	$("#menu").height("13px");
}

var unitWidth = 30;

window.onload = function () {
	// Layout texts
	COLUMN_LAYOUT.setCols(3);
	COLUMN_LAYOUT.setFixedCols(true);
	var el = $(".content").each(function () {
		COLUMN_LAYOUT.layoutElement(this, "column")
	});
	$(".content").css("visibility", "visible");

	// Layout boxes
	var boxes = $(".shadow1");
	var rectangles = new Array(boxes.length);
	for (var i=0; i<boxes.length; i++) {
		rectangles[i] = new Object();
		var box = $(boxes.get(i));
		rectangles[i].id = box;
		rectangles[i].width = Math.ceil(box.width()/unitWidth);
		rectangles[i].height = Math.ceil(box.height()/unitWidth);
	}
	var placement = RECTANGULAR_PACKING.placement(rectangles, 32);
	for (var i in placement) {
		placement[i].id.css("left", placement[i].x*unitWidth+8);
		placement[i].id.css("top", placement[i].y*unitWidth+8);
		placement[i].id.css("visibility", "visible");
	}
};

function storeMenuPosition() {
	var menu = $("#menu");
	var offset = menu.offset();
	document.cookie = "menu="+offset.top+","+offset.left+","+(menu.hasClass("closed") ? 1 : 0)+"; path=/";
}

$(function () {
	var menu = $("#menu");
	menu.jqDrag().dblclick(function () {
		menu.toggleClass("closed");
		storeMenuPosition();
	}).mouseup(storeMenuPosition);
	// Restore the menu"s position
	cookies = document.cookie.split(/;/);
	for (var i=0; i<cookies.length; i++) {
		var cookie = $.trim(cookies[i]).split(/=/);
		if (cookie.length==2 && cookie[0]=="menu") {
			var pos = cookie[1].split(/,/);
			if (pos.length==3) {
				menu.css("left", pos[1]+"px")
					.css("top", pos[0]+"px");
				if (pos[2]=="1") {
					menu.addClass("closed");
				}
			}
		}
	}
	menu.show();
});
