var useHilites = true;

var hilites = {
	bibliothek: {path: '/angebote/bibliothek/',
	             width: 211,  height: 166,  top: 424,  left: 483,
	             poly: [483,513, 506,486, 545,460, 564,459, 558,442, 601,424,
	                    614,452, 607,447, 635,479, 639,460, 653,464, 654,489,
	                    677,482, 688,510, 694,560, 640,586, 540,589, 484,562]},
	begegnung: {path: '/angebote/begegnung/',
	            width: 436, height: 307, top: 558, left: 258,
	            poly: [261,595, 483,559, 543,586, 640,585, 685,562, 691,835,
	                   644,857, 545,862, 484,837, 263,838]},
	training: {path: '/angebote/training/',
	           width: 408, height: 244, top: 353, left: 73,
	           poly: [77,351, 119,379, 160,387, 256,381, 309,371, 477,368,
	                  479,556, 410,562, 240,594, 165,594, 87,577, 80,562]},
	ideen: {path: '/angebote/ideen/',
	        width: 261, height: 301, top: 532, left: 690,
	        poly: [691,562, 878,562, 935,547, 950,533, 949,697, 916,742,
	               857,763, 819,770, 821,824, 734,829, 732,772, 693,772]},

	person: {path: '/zur-person/',
	         width: 171, height: 116, top: 203, left: 501,
	         poly: [501,317, 541,204, 619,205, 671,315]}
};

$(document).ready(function(){
	$('#head').html('<img src="/img/logo.gif" alt="" width="245" height="72" />');
	setup();
});

$(window).resize(function(){
	$('div.shadowed').removeShadow();
	$('#jsstuff').html('');
	setup();
});

function setup() {

	dimnsns = windowDimensions();

	// Content positioning
	overhead = 35;
	effconth = $('#content').height() + overhead;
	margtop = parseInt($('#content').css('margin-top'));
	usable = dimnsns.height - margtop;
	if (effconth <= usable) {
		widthreduce = 0;
		$('#content').css('top', (usable - effconth) + 'px');
	} else {
		widthreduce = 15;
	}
	if ($.browser.msie) {
		widthreduce = 0;
	}

	// BG image scaling
	$('#bg').attr({
		width: dimnsns.width - widthreduce,
		height: dimnsns.height
	});
 	$('#bg').css('visibility', 'visible');

	wratio = (dimnsns.width - widthreduce) / 1672;
	hratio = dimnsns.height / 938;

	if (useHilites) {
		map = '<map name="navmap">';
		imgs = '';
		for (var name in hilites) {
			hilite = hilites[name];
			if (window.location.pathname.replace(/\//g, '') == hilite.path.replace(/\//g, '')) {
				continue;
			}
			map += '<area shape="poly" coords="';
			imgs += '<a href="' + hilite.path + '">' +
					'<img src="/img/over_' + name + '.gif" class="hover" ' +
					'id="over_' + name + '" alt="" usemap="#navigation" ' + 
					'width="' + Math.round(hilite.width * wratio) + '" ' +
					'height="' + Math.round(hilite.height * hratio) + '" ' +
					'style="top: ' + Math.round(hilite.top * hratio) + 'px; ' + 
					'left: ' + Math.round(hilite.left * wratio) + 'px" ' + 
					'onmouseover="show(\'over_' + name + '\')" onmouseout="hide(\'over_' + name + '\')" />' +
					'</a>';
			for (i = 0, ii = hilite.poly.length; i < ii; i += 2) {
				map += Math.round(hilite.poly[i] * wratio) + ',' +
					   Math.round(hilite.poly[i + 1] * hratio);
				if (i < ii - 2) {
					map += ',';
				}
			}
			map += '" href="' + hilite.path + '" onmouseover="show(\'over_' + name + '\')" onmouseout="hide(\'over_' + name + '\')" />';
		}
		map += '<\057map>';
		$('#jsstuff').html(map + imgs);
	}

	// Drop shadows
	$('div.shadowed').dropShadow({left: 1, top: 1, blur: 1, opacity: 0.25});
}

function show(elmntid) {
	document.getElementById(elmntid).style.display = 'inline';
}

function hide(elmntid) {
	document.getElementById(elmntid).style.display = 'none';
}

/**
 * Returns inner dimensions (content size) of window
 * @return Object with properties 'width' and 'height' or null,
           if dimensions can't be retrieved
 * @author CB
 */
function windowDimensions() {
	if (self.innerHeight) {
		return {width: self.innerWidth, height: self.innerHeight};
	}
	if (document.documentElement && document.documentElement.clientHeight) {
		return {width: document.documentElement.clientWidth, height: document.documentElement.clientHeight};
	}
	if (document.body) {
		return {width: document.body.clientWidth, height: document.body.clientHeight};
	}
	return null;
}

