var NavigationInterval;

function Launch(){		
	$('UL#Navigation').children().each(function(){		
		$(this).mouseover(function(){ $(this).addClass('Over'); Cufon.refresh('h3'); Navigation($(this).attr('id'), 'Show'); });	
		$(this).mouseout(function(){ Navigation($(this).attr('id'), 'Hide'); });	
	});
	
	$('UL#Register').children().each(function(){
		$(this).mouseover(function(){ $(this).addClass('Over'); Cufon.refresh('h3'); });	
		$(this).mouseout(function(){ $(this).removeClass('Over'); Cufon.refresh('h3'); });	
	});
	
	$('DIV.SubNavigation UL').children().each(function(){
		$(this).mouseover(function(){ $(this).addClass('Over'); });	
		$(this).mouseout(function(){ $(this).removeClass('Over'); });	
	});
	
	$('DIV.SubNavigation').each(function(){
		$(this).mouseover(function(){  Navigation($(this).attr('id'), 'Keep'); });	
		$(this).mouseout(function(){ Navigation($(this).attr('id'), 'Hide'); });	
	});
		
	$('FORM#SearchForm INPUT').focus(function(){
		$(this).addClass('Active');
		$('FORM#SearchForm').css('background-image', 'url(images/search-active.png)');
		$('DIV#SearchButton').fadeIn();
		$('DIV#SearchFilter').fadeIn();
		
	});
	//$('FORM#SearchForm INPUT').blur(function(){
	$('DIV#SearchHolder').mouseleave(function(){
		$(this).removeClass('Active');
		$('FORM#SearchForm').css('background-image', 'url(images/search.png)');
		$('DIV#SearchButton').fadeOut();
		$('DIV#SearchFilter').fadeOut();
	});
	
	
	$('UL#Breadcrumb LI').children().last().css({ fontSize: '11px', fontWeight: 'bold', textDecoration: 'none' });
	
	$('FORM#LoginForm').css({top:($('UL#Register').position().top + 30) + 'px', left:($('UL#Register').position().left + $('UL#Register').outerWidth() - $('FORM#LoginForm').outerWidth() + 12) + 'px'});
	
	$.ajax({
	  url: 'backend/view.php?URL=' + escape(document.location.href)
	});
}

function Resize(){
	$('FORM#LoginForm').css({
		top:($('UL#Register').position().top + 30) + 'px',
		left:($('UL#Register').position().left + $('UL#Register').outerWidth() - $('FORM#LoginForm').outerWidth() + 12) + 'px'
	});
}

function Navigation(ID, Action){
	if(ID.indexOf('SubNavigation-') != -1) ID = ID.substr(ID.indexOf('-')+1, ID.length);
	
	clearTimeout(NavigationInterval);
		
	Position = $('LI#' + ID).offset();
	
	switch(Action){
		case 'Show':
			$('DIV.SubNavigation').hide();
			$('DIV.SubNavigation').removeShadow();
			
			$('UL#Navigation LI').removeClass('Over');
		
			$('DIV#SubNavigation-' + ID).show();
			$('DIV#SubNavigation-' + ID).css('left', Position.left + 'px');
			$('DIV#SubNavigation-' + ID).css('top', Position.top+34 + 'px');
						
			$('DIV#SubNavigation-' + ID + ' .Information').css('min-height', ($('DIV#SubNavigation-' + ID + ' UL').height()-40) + 'px');
			
			$('LI#' + ID).addClass('Over');
			
			Cufon.refresh('h3'); 
		break;
		case 'Keep':
		break;
		case 'Hide':
			NavigationInterval = setTimeout(function(){ Navigation(ID, 'Close') }, 500);
		break;
		case 'Close':
			$('DIV#SubNavigation-' + ID).hide();
			$('DIV#SubNavigation-' + ID).removeShadow();
			
			$('LI#' + ID).removeClass('Over');
			
			Cufon.refresh('h3'); 
		break;
	}
}

function TopNavigation(){
	Status = String($('DIV#Button IMG.Arrow').attr('src'));
	
	$('#LoginForm').hide();
	
	if(Status.indexOf('-open') != -1) Status = 'Closed';
	else Status = 'Open';
	
	switch(Status){
		case 'Closed':
			$('DIV#TopHolder').fadeIn();
			if ($.browser.msie != true) {
				$('DIV#MapCover').animate({marginTop: 241}, 750);
				$('DIV#MapSearchBox').animate({marginTop: 241}, 750);
				$('DIV#MapCoverSelection').animate({marginTop: 241}, 750);
				$('DIV#MapSearchClose').animate({marginTop: 241}, 750);
			}			
			$('#Top').animate({height: 245}, 750);
			
			if ($.browser.msie == true && parseInt(jQuery.browser.version) == 7) {
				$('#Top').animate({height: 245}, 750, IE7);
			} else {
				$('#Top').animate({height: 245}, 750);
			}
			
			$('DIV#Button IMG.Arrow').attr('src', 'images/top-close.png');
		break;
		case 'Open':
			if ($.browser.msie != true) {
				$('DIV#MapCover').animate({marginTop: 0}, 750);
				$('DIV#MapSearchBox').animate({marginTop: 0}, 750);
				$('DIV#MapCoverSelection').animate({marginTop: 0}, 750);
				$('DIV#MapSearchClose').animate({marginTop: 0}, 750);
			}						
			$('#Top').animate({height: 4}, 750);
			if ($.browser.msie == true && parseInt(jQuery.browser.version) == 7) {
				$('DIV#TopHolder').fadeOut("slow", IE7);
			} else {
				$('DIV#TopHolder').fadeOut();
			}
			$('DIV#Button IMG.Arrow').attr('src', 'images/top-open.png');
			
		break;
	}
}

function IE7() {
	Navigation('ueber-uns', 'Show');
	Navigation('ueber-uns', 'Hide');
}

function Calendar(Offset){
	Month += Offset;
	if(Month == 0) {
		Year --;
		Month = 12;
	} else if(Month == 13){
		Year++;
		Month = 1;
	}
		
	$('.Loader').fadeIn(300, CalendarCall);
	$('.Loader').css({top:($('.Days').outerHeight()*-1) + 'px', height:$('.Days').outerHeight() + 'px'});
	$('.Loader IMG').css({marginTop:($('.Days').outerHeight()-66)/2 + 'px'});
}

function CalendarCall(){
	$('SPAN.Month').html(Months[Month-1] + ' ' + Year);
	
	$.ajax({
	  url: 'backend/action.php?Action=Calendar&Year=' + Year + '&Month=' + Month + '&View=' + View,
	  dataType: 'html',
	  success: CalendarData
	});
}

function CalendarData(Data){
	$('.Days').html(Data);
	$('.Loader').fadeOut(300);
}

function Login(){
	$('FORM#LoginForm').toggle();
}

function Reply(ID){
	if($('#Reply-' + ID).is(':hidden') && ID != 'New'){
		$('#Reply-' + ID).show();
	} else {
		$('#ReplyForm-' + ID).submit();
	}
}

function ShowHelp(Extern){
	if (Extern == undefined && $('#Help').size() == 0) document.location.href = BasePath + Lang + '/hilfe/index.html';
	else { 
		$('#Help').fadeIn();
		
		PlaceHelp();
	}
}

function PlaceHelp(){
	$('#HelpContent').css('margin-left', ($(document).width()/2)-($('#HelpContent').width()/2) + 'px');
}

function HideHelp(){
	$('#Help').fadeOut();	
}



function ShowDownloadMessage(){
	$('#DownloadMessage').fadeIn();
	PlaceDownloadMessage();
}

function PlaceDownloadMessage(){
	$('#DownloadMessageContent').css('margin-left', ($(document).width()/2)-($('#DownloadMessageContent').width()/2) + 'px');
	$('#DownloadMessage').css('height', ($('DIV#Content').height() - 2) + 'px');
}

function HideDownloadMessage(){
	$('#DownloadMessage').fadeOut();	
}




function SubmitFormOnEnter(Field, Event){
	var KeyCode;
	if (window.event) KeyCode = window.event.keyCode;
	else if (Event) KeyCode = Event.which;
	else return true;

	if (KeyCode == 13) {
		
	 $(Field).parents('FORM').submit();
   
	 return false;
  } else return true;
}

function SetSearchFilter(checked, field){
	if (checked === true) {
		document.getElementById(field).value = 1;
	} else {
		document.getElementById(field).value = 0;
	}	
}

function ScrollToTop() {
	$('html, body').animate({scrollTop:0}, 'fast');
}

function Get(o) {
	return document.getElementById(o);
}
