function load_ajax_content(url)
{
	$.ajax({ 
		"url": url + '?ajax=true', 
		"success": open_ajax_box
	});
}
function open_ajax_box(content)
{
	// kaputten etracker teil abschbeiden
	var tmp = content.split('<!-- Copyright (c) 2000-2011');
	if(tmp.length > 1)
		content = tmp[0];


	$('#ajax_box_outer').css({ 'display' : 'block' });
	$('#intro_wrap').css({ 'visibility' : 'hidden'});

	$('#ajax_box_content').css({ 'height' : 'auto' });
	$("#ajax_box_content").attr('innerHTML', content);

// <div id="inner-content"> führt im IE zu problemen !
document.getElementById('ajax_box_content').firstChild.id = 'none';

	var diff = $(document.body).attr('offsetHeight') - $('#ajax_box_inner').attr('offsetHeight');
	
	// ajax box ist nicht so hoch wie der body
	if(diff > 0)
	{
		$('#ajax_box_outer').css({ 'margin-bottom' : '0' });
		$('#ajax_box_inner').css({ 'margin-top' : Math.round(diff / 2) + 'px' });
	}
	// ajax box ist höher als der body
	else
	{
		$('#ajax_box_outer').css({ 'margin-bottom' : diff - 20 + 'px' });
		$('#ajax_box_inner').css({ 'margin-top' : '10px' });
	}
}

function close_ajax_box()
{
	$('#ajax_box_outer').css({ 'display' : 'none'});
	$('#intro_wrap').css({ 'visibility' : 'visible'});
}


$(document).ready(function(){

	/*
	*	wenns keine ajax box gibt, eine erzeugen
	*/
	if(!document.getElementById('ajax_box_outer'))
	{
		var ajax_box_outer = document.createElement('div');
		ajax_box_outer.id = 'ajax_box_outer';
		document.body.appendChild(ajax_box_outer);
		$("#ajax_box_outer").click(function(event){ if(event.target == document.getElementById('ajax_box_outer')) close_ajax_box(); });		

		var ajax_box_inner = document.createElement('div');
		ajax_box_inner.id = 'ajax_box_inner';
		ajax_box_outer.appendChild(ajax_box_inner);
		
		var close_ajax_box_btn = document.createElement('div');
		close_ajax_box_btn.id = 'close_ajax_box_btn';
		close_ajax_box_btn.innerHTML = ' X ';
		close_ajax_box_btn.style.cursor = 'pointer';
		ajax_box_inner.appendChild(close_ajax_box_btn);
		$("#close_ajax_box_btn").click(function(){ close_ajax_box(); });
		
		var ajax_box_content = document.createElement('div');
		ajax_box_content.id = 'ajax_box_content';
		ajax_box_inner.appendChild(ajax_box_content);
		
	}
	
	/*
	*	alle links mit target="_top" auf AJAX stellen
	*/
	var links = document.getElementsByTagName('a');	
	for(var i=0; i < links.length; i++)
	{
		if(links[i].target == '_top')
		{
			links[i].href = 'javascript: load_ajax_content("' + links[i].href + '");';
			links[i].target = '';
		}
	}

});

