$(function(){
	var $menu = $('#navigation a[href="'+location.pathname+'"]').last();
	if (!$menu.length) {
		$menu = $('#navigation a[href="/'+location.pathname.split('/')[1]+'/"]').last();
	}

	if ($menu.length) {
		$menu.addClass('active');
		
		var $pMenu = $menu.parents('li:eq(1)');
		if ($pMenu.length) {
			$pMenu.children('a').addClass('active');
			$('#header').after(
				$('<div id="navigation-sub-container"></div>').append($pMenu.children('ul').clone().attr('id','navigation-sub')).append('<div style="clear: both;"></div>')
			).after($('<div class="page-border"></div>'));
		} else if ($menu.parent('li').children('ul').length) {
			$('#header').after(
				$('<div id="navigation-sub-container"></div>').append($menu.parent('li').children('ul').clone().attr('id','navigation-sub')).append('<div style="clear: both;"></div>')
			).after($('<div class="page-border"></div>'));
		}
	}
	
	$('ul#navigation ul').prev().mouseenter(function(){
		$(this).parent().toggleClass('active', true); 
	}).parent('li').mouseleave(function(){
		$(this).toggleClass('active', false);
	});
	
	$('img.pikto.full').load(function() {
		$(this).wrap(function(){
			return '<span class="' + $(this).attr('class') + '" style="background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />';
		});
		$(this).css("opacity","0");
	});


	$('form td input.textbox, form td input.checkbox, form td select, form td textarea').each(function(){
		$(this).focus(function(){
			$(this).toggleClass('focus', true).parent('td').parent('tr').toggleClass('highlight', true);
		}).blur(function(){
			$(this).toggleClass('focus', false).parent('td').parent('tr').toggleClass('highlight', false);
		});
	});
	$('form').submit(function(){
		$(this).find('input[type="submit"]:not(input.nojs)').attr('disabled','disabled').val('Bitte warten...');
	});
	$('.notempty').blur(function(){
		$(this).toggleClass('error', $(this).val().length == 0);
	});
	$('input.mobileno').keyup(function(){
		var $this = $(this);
		var $value = $this.val();
		var value = $value.replace(/[^0-9]/g, '');
		if (value.substr(0,1) == '0') {
			value = value.substr(1);
		}
		$this.val(value);
		if ($value != value) {
			$this.css('background-color', '#e11');
			window.setTimeout(function(){
				$this.css('background-color', '');
			}, 200);
		}
	});
	
	$('.tipp .container').each(function(){
		var container = $(this);
		container.parent().prev().focus(function(){
			container.show();
		}).blur(function(){
			container.fadeOut();
		});
	});
	
	$('div.tabs').each(function(){
		$container = $(this);
		$container.children('a.tab').each(function(){
			$tab = $(this);
			$content = $tab.next('div.tab');
			$tab.data({container:$container,content:$content});
			$tab.click(function(e){
				$this = $(this);
				e.preventDefault();
				$this.data('container').children('a.tab').toggleClass('active',false);
				$this.toggleClass('active',true);
				$this.data('container').children('div.tab').hide();
				$this.data('content').fadeIn();
			});
			if (!$tab.hasClass('active')) {
				$content.hide();
			}
			$container.append($content);
		});
	});
	
	$('body.ie6').append($('<scr'+'ipt/>').attr({type:'text/javascript',src:'http://browser-update.org/update.js'}))
});

$.postJSON = function(url, data, callback) {
    jQuery.post( url, data, callback, "json") ;
};