	var myServer = 'http://www.sehlbach.de/';
	
	
$.fn.ajaxify = function(my_url,old_text) { 
    $.ajax( { 
		url: my_url, 
		cache: true, 
		success: function(message) { 
		$("#main").fadeOut(200, function() {
			$(this).empty();
			
			if (my_url.match(/\/C24\/sub\/kontakt/)) {
				my_url = my_url.replace(/\/ajax\//,"/statisch/");
				top.location = myServer + my_url;
				
				// alert('here goes the map!');				
				// initialize(message);
				// addMarker(52.49287,13.39719,'red','Olav Sehlbach<br />Fürbringerstraße 14','foo');
				// addMarker(52.49464,13.40078,'yellow','M41<br />Tempelherrenstraße','foo');
				// addMarker(52.49097,13.39559,'blue','U7<br />Gneisenaustraße','foo');
				
			}
			
			message = message.replace(/\/ajax\//,"/statisch/");

			$(this).fadeIn(200, function() {}).replaceWith(message);
									
			//$("a#bild").fancybox({
			//	'titleShow'		: false,
			//	'transitionIn'	: 'elastic',
			//	'transitionOut'	: 'elastic'
			//});
			
			// deactivate all other actives
			if (old_text) {
				var $that2 = $(this);
				$('#nav_categories ul li a.active, ul#mainHeaderSubNavi li a.active').each(function () {
					if ($(this).html() !== old_text) {
						$(this).removeClass('active').addClass('inactive');
					}
				});
			}
			
			
			var list_img = [{'href': $('a#bild').attr('href'), 'title': $('a#bild img').attr('alt')}];
			$('a.bild').each(function() {
				list_img.push({'href': $(this).attr('href'), 'title': $(this).attr('alt')});
			});
			$(this).bildclick(list_img);
			
			
			// 
			$('#mainContent a, #mainSubContent a').each(function () {}).bind("click", function(fx) {

				$('#mainContent a[rel=external], #mainSubContent a[rel=external]').attr('target','_blank'); 
				
				var is = my_url.match(/\/ajax\//);
				if (is[0]) {
					$(this).ajaxify(my_url);
				}
				// fx.preventDefault();
				
			});	
			

				
				
		});
		}
	});
}

$.fn.bildclick = function(list_img) { 
	$("a#bild").click(function() {
		
		var is, my_type, my_autoscale;
		
		if (is = $(this).attr('href').match(/\.swf.*/)) {
			my_type = 'iframe';
		}
		else {
			my_type = 'image';
		}
		// alert(my_type);
	
		$.fancybox(
		list_img,
		{
				// 'titleShow'     : false
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',
				'easingIn'      : 'easeOutBack',
				'easingOut'     : 'easeInBack',
				'padding'	: 0,
				'type'		: my_type,
				//'titlePosition'	: 'over'
				'changeFade'	: 0,
				'cyclic'		: true,
				'orig'			: $(".bild.orig")
		});
		
		// fx.preventDefault();
		return false;
	});
}

$(document).ready(function() {
	


	//$("a#bild").fancybox({
	//			'titleShow'		: false,
	//			'transitionIn'	: 'elastic',
	//			'transitionOut'	: 'elastic'
	//});
	
	// hide all submenus
	$("ul#nav_categories li ul").hide();
	// open active one
	$('ul#nav_categories li a.active').next('ul').show();
	
	// hide first entry
	$('ul#nav_categories > li a').each(function () {
		$(this).next('ul').children(':first').hide();
	})
	
	// $('ul#pimary_nav li a').click(function() {

	$('ul#nav_categories > li a').click(function() {
		
		var myURL = $(this).attr('href');
		var that = this;
		
		// close all open tabs
		$('ul#nav_categories > li a').each(function() {
			if (! ($(this).next('ul').is(":hidden")) &&
				$(this).html() != $(that).html() &&
				// ! $(that).hasClass('active') &&
				! $(that).hasClass('submenu')) {
					
				$(this).next('ul').slideToggle({ duration: 650, easing: "easeOutCirc", complete: function() {}});
				
							$(this).removeClass('active');
							$(this).addClass('inactive');
			}
		});
		
		$(this).next('ul').slideToggle({ duration: 650, easing: "easeOutCirc", complete: function() {}});
		
					if ($(this).hasClass('inactive')) {
							$(this).removeClass('inactive');
							$(this).addClass('active');
					}
					else {
							$(this).removeClass('active');
							$(this).addClass('inactive');
					}
					
		if ($(this).hasClass('active') && ! $(this).hasClass('submenu')) {
			
			$(this).next('ul').children(':first').children().removeClass('inactive').addClass('active');
							
			// alert('hier würde jetzt der Inhalt aus dem 1. Subeintrag geladen...');
			var go_to = $(this).next('ul').children(':first').children().attr('href');
			if (go_to) {
				// top.location = go_to;
				go_to = go_to.replace(/http:\/\/.*sehlbach\.de\//,"");
				go_to = go_to.replace(/statisch/,"ajax");
				
				$(this).ajaxify(go_to,'');
				
			}
		}

		if (myURL != '') {
				// top.location = myServer + myURL;
			}
			else {
				return (false);
			}

	});
	
	$('#nav_categories ul li a, #mainHeaderSubNavi li a, #mainContent a.paginate').each(function () {}).bind("click", function(fx) {
		var my_url = $(this).attr('href');
		if (my_url) {
			
			var old_text= $(this).html();
			
			my_url = my_url.replace(/http:\/\/.*sehlbach\.de\//,"");
			my_url = my_url.replace(/statisch/,"ajax");
			
			$(this).ajaxify(my_url,old_text);
			
		}
		
		fx.preventDefault();
		// return false;
	});

	
	var list_img = [{'href': $('a#bild').attr('href'), 'title': $('a#bild img').attr('alt')}];
	
	$('a.bild').each(function() {
		list_img.push({'href': $(this).attr('href'), 'title': $(this).attr('alt')});
	});
	
	// fancybox
	$(this).bildclick(list_img);
			
	// new window 
	$('a[rel=external]').attr('target','_blank'); 

	// fix a:active outline bug in IE6+7
	// http://haslayout.net/css-tuts/Removing-Dotted-Border-on-Clicked-Links
	if($.browser.msie) {
		$('a').click(function() {
			$(this).blur();
		});
	}

});

