$(function() {
	$( "#PageMenu" ).resizable({
		minWidth: 230,
		containment: "body"
	});
});
		
function cellObject(eid) {
  var pos = $(eid).position();
  this.width = $(eid).width();
  this.height = $(eid).height();
  this.left = pos.left-1;
  this.top = pos.top;
  this.right = pos.left + this.width+2; // padding + border = 6
  this.bottom = pos.top + this.height + 6;
  this.posx = pos.left + ((this.width + 6) / 2);
  this.posy = pos.top + ((this.height +6) / 2);
} 
var drawLines = function() {
  var divs = $('table.content, table.miniContent');
  for (var i = 0; i < (divs.length - 1); i++) { // draw lines for all elements except last one
    var from = new cellObject(divs[i]);
    var upper = new cellObject(divs[i+1]);
    var rspan = $($(divs[i]).parent('td')).attr('rowspan');
    var lower = new cellObject(divs[i+rspan]);

	if (jQuery.trim(divs[i+1].innerHTML).length != 0)
	{
		// draw line to upper child
		if (from.posx < upper.posx && from.posy > upper.posy) {
		$("#PageContent").drawPolyline([from.right, upper.left], [from.posy,upper.posy], {color:'#000000', alpha: .5, stroke:1});
		}
	}

	if (jQuery.trim(divs[i+rspan].innerHTML).length != 0)
	{	
		// draw line to lower child
		if (from.posx < lower.posx && from.posy < lower.posy) {
		$("#PageContent").drawPolyline([from.right, lower.left], [from.posy,lower.posy], {color:'#000000', alpha: .5, stroke:1});
		}
	}
  }
};
$(document).ready(function(){
	drawLines();
	
	if ($("#relationlink").tooltip)
		$("#relationlink").tooltip({cssClass:"tooltip-grey"});
	
});


function gp(person){
var frm = document.getElementById("frm")
frm.action = person.href;
frm.submit();
}
$(document).ready(function() {
	$('.tabsBsmall').children("a").click(function () {
		var v = $(this).children("span").html();
		if (v=="*") v="_";
		if (v.charCodeAt(0)==197) v="Å";
		if (v.charCodeAt(0)==196) v="Ä";
		if (v.charCodeAt(0)==214) v="Ö";
		$("#filter").val(v);
		$("#frm").submit();
		return false;
	});
	$("#person").click(function() {
		$("#list").val("person");
		$("#frm").submit();
		return false;
	});
	$("#places").click(function() {
		$("#list").val("places");
		$("#frm").submit();
		return false;
	});
	$("#search").click(function() {
		$("#list").val("search");
		$("#frm").submit();
		return false;
	});
});
var toggleNode = function (oba) {
	$(oba).nextAll("div:first").toggle();
};
var showPlace = function (placeId, place) {
		var div = $(place).nextAll("div:first");
		if (div.html().length == 0)
		{
			div.html("Laddar...");
			div.load("/place.php?p=" + placeId);
		}
		div.toggle();
};

function epost()
{
	var e = '6d61696c746f3a6d617274696e5f6272616e64744074656c69612e636f6d';
	var f = '<a href="';
	for (x=0;x<e.length;x=x+2)
	f = f + '&#x' +  e.substr(x,2) + ';';
	f = f + '">';
	for (x=14;x<e.length;x=x+2)
	f = f + '&#x' +  e.substr(x,2) + ';';
	f = f + '</a>'
	if (document.getElementById("epost"))
	document.getElementById("epost").innerHTML = document.getElementById("epost").innerHTML + f;
}

$(document).ready(function() {
    epost();
});
