/*--------------- LOGIN VARS & FUNKTIONEN ---------------*/

login_is_open = false;

function toggle_login_window() {
	if (login_is_open) {
		hide_login_window();
	} else {
		show_login_window();
		
	}
}

function show_login_window() {
		$("#header_controls_login_window").fadeIn("fast");
		$("#header_controls_login_button").toggleClass("login_button_clicked");
		login_is_open = true;
}

function hide_login_window() {
		$("#header_controls_login_button").removeClass("login_button_clicked");
		$("#header_controls_login_window").fadeOut("fast");
		login_is_open = false;
}

/*--------------- FORMULARE - FUNKTIONEN ---------------*/

function apply_input_logic(input, default_val) {
	// onFocus: Input wird geleert, Inaktiv-Klasse entfernt
	// onBlur:  Wurde kein Text eingetragen, dann Inaktiv-Klasse wieder einsetzen, Default-Value wiederherstellen*/
	if (default_val == null) default_val = "";
	$(input).focus(function() {
		if ($(input).val()==default_val) 
			$(input).val("");
		$(input).removeClass('waiting');
	});
	$(input).blur(function() {
		if ($(input).val()=="") {
			$(input).addClass('waiting');
			$(input).val(default_val);
		}
	});
}

/*--------------- ZEIT FORMATIEREN - FUNKTIONEN ---------------*/

function format_time(time) {
	var date = new Date();
	var posting_date = new Date( time * 1000);
	

	var posting_hour  	= (posting_date.getHours() < 10) ? '0' + posting_date.getHours() : posting_date.getHours();
	var posting_minute  = (posting_date.getMinutes() < 10) ? '0' + posting_date.getMinutes() : posting_date.getMinutes();
	
	var posting_day 	= (posting_date.getDate() < 10) ? '0' + posting_date.getDate() : posting_date.getDate();
	var posting_month 	= (posting_date.getMonth() < 10) ? '0' + posting_date.getMonth() : posting_date.getMonth();
	
	german_posting_date = posting_day + '.' + posting_month + '.' + posting_date.getFullYear() + ' ' + posting_hour +':'+ posting_minute;
			
	var milliseconds1 = time * 1000;
	var milliseconds2 = date.getTime();
	var difference = milliseconds2 - milliseconds1;
	var daysDifference = Math.floor(difference/1000/60/60/24);
	
	difference = difference - daysDifference*1000*60*60*24
	
	var hoursDifference = Math.floor(difference/1000/60/60);
	
	difference = difference - hoursDifference*1000*60*60
	
	var minutesDifference = Math.floor(difference/1000/60);
	
	difference = difference - minutesDifference*1000*60
	
	var secondsDifference = Math.floor(milliseconds2 / 1000) - time;
	// This next line below looks for entries over a day old
	//alert(secondsDifference);
	
	if (daysDifference > 1) 
		return ' ' + german_posting_date + ' ';
	else if (secondsDifference < 30)
		return 'Gerade eben'; 
	else if (secondsDifference < 60)
		return 'Vor ' + secondsDifference + ' Sekunden'; 
	else if (hoursDifference < 1) 
		return 'Vor ' + minutesDifference + ' Minuten';
	else if (daysDifference < 1) 
		return 'Heute, ' + posting_hour + ':' + posting_minute;
	else  
		return ' ' + german_posting_date + ' ';
}

/*--------------- MSGBOX - FUNKTIONEN ---------------*/

function init_msgbox_container_logic() {
	if ($('#msgbox_container').length != 0) {
		$(".infobox").each(function(index) {
			init_single_msgbox($(this));
		});
		setTimeout("$('#msgbox_container').slideDown();",500);
		if ($('#msgbox_container').hasClass('message_flash'))
			setTimeout("$('#msgbox_container').slideUp()", 8000);
	}
}

function init_single_msgbox(msgbox) {
	$(msgbox).children(".msg_close_button").click(function() {
		$(msgbox).slideUp();
	});
}

/*--------------- DIVERSES - FUNKTIONEN ---------------*/

function assign_ajax_content(container_identifier,ajax_controller_uri)	{
	$.ajax({ url: ajax_controller_uri, success: function(data){
        	$(container_identifier).html(data);
      }});
}


