/*
	## Teichgraeber JS
*/

window.addEvent('domready', function() {

	// # get some vars
	header_length = $('header').getStyle('width');
	orig_window_width = null;
	
	// # locate the navi elements
	teichgraeber_locate(true);
	window.addEvent('resize',function(e){
		teichgraeber_locate(false);
	});

});

/*
	this locates the navi elements to their corret position. the set LEFT style is only a relative value.
*/
function teichgraeber_locate(init) {

	var display = $(document.body).getSize();

	$$('.navi_element').each(function(item, index){
		
		var props = $(item).getStyles('top', 'left'); 		
		var new_top = props.top;
		var left = props.left.toInt();
		
		if(init) {
			// first run, get the original LEFT value	
			var new_left = (((display.x - header_length.toInt()) / 2) + left).ceil();
		} else {
			// onresize, calculate the position from current position
			var original_left = left - ((orig_window_width - header_length.toInt()) / 2).ceil();
			var new_left = ((display.x - header_length.toInt()) / 2) + original_left;
		}
		
		$(item).setStyles({
			top: new_top,
			left: new_left.ceil(),
			display: 'block',
			visibility: 'visible'
		});
		
	});
	
	orig_window_width = display.x;
	
}

