/*
  CATALOGTREE 4.0
  Copyright (C) 2007 Pyrrhon Software

  Lutz Ißler
  Talstr. 27
  04103 Leipzig
  GERMANY

  Web:    www.pyrrhon.com
  Email:  lutz@pyrrhon.com

  Design by catalogtree, Arnhem, THE NETHERLANDS

  Permission granted to use this file and associated files
  only on the specified website.
*/



var colors = new Array("cyan", "magenta", "yellow");

function on(id) {
	for (var i=0; i<index[id].length; i++) {
		var el = document.getElementById("index_"+index[id][i]);
		if (el) {
			el.setAttribute("class", colors[i%3]);
		}
	}
}

function off(id) {
	for (var i=0; i<index[id].length; i++) {
		var el = document.getElementById("index_"+index[id][i]);
		if (el) {
			el.removeAttribute("class");
		}
	}
}

$(function() {
	var chunkHeights = new Array();
	var totalHeight = 0;
	$("#index > .section").each(function() {
		var h = $(this).height();
		totalHeight += h;
		chunkHeights.push(h);
	});
	var colHeight = totalHeight/Math.floor($(window).width()/(120+11));
	var bestSplits = [];
	var height = 0;
	for (var i=0; i<chunkHeights.length; i++) {
		height += chunkHeights[i];
		if (height>colHeight) {
			bestSplits.push(i);
			height = 0;
		}
	}
	var lastSplit = 0;
	for (var i=0; i<bestSplits.length; i++) {
		$("#index > .section:lt("+(bestSplits[i]-lastSplit)+")").wrapAll('<div class="col"></div>');
		lastSplit = bestSplits[i];
	}
	$("#index > .section").wrapAll('<div class="col"></div>');

	$(window).resize(function() {
		var numColumns = Math.floor(($(window).width()-10)/393);
		$("#content").each(function() {
			var columns = $(".overfull", this);
			if (columns.count!=numColumns) {
				var projects = $(".project", this);
				var projectsPerColumn = Math.ceil(projects.length/numColumns);
				for (var i=1; i<=numColumns; i++) {
					$(projects).filter((i>1 ? ":gt("+((i-1)*projectsPerColumn-1)+")" : "")+":lt("+(i*projectsPerColumn)+")").appendTo(this).wrapAll('<div class="overfull"></div>');
				}
				columns.remove();
			}
		})
	}).resize();

	$("a[href^='http://']").click(function (e) {
		e.preventDefault();
		this.blur();
		window.open(this.href);
	});
});

