﻿$(document).ready(function(){
	
	if ( $("#land").val() == "bitte auswählen") {		
		$("#kapitel").load("typo3temp/"+$('#cache_file').val()+" #blank option");
		//$(".limited_width form ul .col_2 select").attr("disabled", "disabled");
		$("#kapitel").attr("disabled", "disabled");
	}
	
	if ( $("#kapitel").val() == "bitte auswählen") {		
		$("#bericht").attr("disabled", "disabled");
		$("#bericht").load("typo3temp/"+$('#cache_file').val()+" #blank option");
		revertNavigation();
		$(".limited_width form ul .col_3").unbind('mouseover');
	} else {
		moveNavigation();
	}
	
	$(".limited_width form ul .col_1 select").change(function() {changeKapitel(this);});
	
	$("#kapitel").change(function(){
			x=document.getElementById("land");
			$("#bericht").load("typo3temp/"+$('#cache_file').val()+" #"+this.options[this.selectedIndex].title+" option",'',function() { $("#bericht").attr("selectedIndex",0);});
			//window.dropdown_menu_hack(document.getElementById("bericht")) }
			$(".limited_width form ul .col_3 select").removeAttr("disabled");
			$(".limited_width form ul .col_3").css("background-position", "0 -111px");
		if ($('#kapitel').val()!='bitte auswählen') {		
			moveNavigation();
		}
	});
	
	// Statistik wurde generiert - Seite wird neu geladen - alle drei Zahlen müssen aktiv sein
	if ($("#kapitel").attr("disabled")!= true) {		
		$(".limited_width form ul .col_2").css("background-position", "0 -54px");
	}
	if ($("#bericht").attr("disabled") != true) {		
		$(".limited_width form ul .col_3").css("background-position", "0 -111px");
	}
	
});

function moveNavigation() {
	$(".limited_width form ul .col_3").unbind('mouseover');
	$('.limited_width form ul .col_1').animate({'width':'100px'}, {'easing':'swing'});
		$('#land').hide();
		var land=$('#land').val();
		if(land == null) return false;
		
		if (land.length>13) { land=land.substr(0,10)+'...'; }
		$('#plain_land').html(land);
		$('#plain_land').show();
		$('.limited_width form ul .col_1').bind('mouseover',function() { revertNavigation(); })
	$('.limited_width form ul .col_2').animate({'width':'100px'}, {'easing':'swing'});
		$('#kapitel').hide();
		kapitel=$('#kapitel').val();
		if (kapitel.length>13) { kapitel=kapitel.substr(0,10)+'...'; }
		$('#plain_kapitel').html(kapitel);
		$('#plain_kapitel').show();
		$('.limited_width form ul .col_2').bind('mouseover',function() { revertNavigation(); })
	$('.limited_width form ul .col_3').animate({'width':'430px'}, {'easing':'swing'});
	$('.limited_width form ul .col_3 select').css({'width':'400px'});
	$('.limited_width form ul .col_3 option').css({'width':'400px'});
}

function revertNavigation() {
	$(".limited_width form ul .col_3").bind('mouseover',function() { moveNavigation(); });
	$('.limited_width form ul .col_1').unbind('mouseover');
	$('.limited_width form ul .col_2').unbind('mouseover');
	$('.limited_width form ul .col_3 select').css({'width':'182px'});
	$('.limited_width form ul .col_3 option').css({'width':'182px'});
	$('.limited_width form ul .col_3').animate({'width':'210px'}, {'easing':'swing'});
	$('.limited_width form ul .col_1').animate({'width':'210px'}, {'easing':'swing'});
		$('#plain_land').hide();
		$('#land').show();
		
	$('.limited_width form ul .col_2').animate({'width':'210px'}, {'easing':'swing'});
		$('#plain_kapitel').hide();
		$('#kapitel').show();
	
	
		
}

function changeKapitel(from) {
	$(".limited_width form ul .col_3 select").attr("disabled", "disabled");
	
	$("#kapitel").load("typo3temp/"+$('#cache_file').val()+" #"+getIDName(from.options[from.selectedIndex].text)+" option",'',function() { $("#kapitel").attr("selectedIndex",0); });
	$(".limited_width form ul .col_2 select").removeAttr("disabled");
	
	
	$("#bericht").load("typo3temp/"+$('#cache_file').val()+" #blank option");
	$(".limited_width form ul .col_2").css("background-position", "0 -54px");
}

function getIDName(string) {
	search=new Array('Ä','Ö','Ü','ä','ö','ü','ß'," ",',');
	replace=new Array('ae','oe','ue','ae','oe','ue','ss','_','333');
	for (var i=0; i<search.length; i++) {
		var string=string.replace(search[i],replace[i]);
		//string=string2;
	}
	string=string.toLowerCase();
	return string;
}

