function hinweis_aus() {
  //document.getElementById("hinweis").style.visibility = "hidden";
	$("#hinweis").animate({"top":-$("#hinweis").height()},300, "easeInBack");

}

function show_hinweis(hinweis, decode){
	if(decode)hinweis = $.url.decode(hinweis);
	$("#hinweis_text").html(hinweis);
	document.getElementById("hinweis").style.visibility = "visible";
	//$("#hinweis").css("z-index",100);
	var posY =  ($(window).height() / 2) - ($("#hinweis_text").height() / 2);
	$("#hinweis").css("top",-$("#hinweis").height());
	//$("#hinweis").css("z-index",100);
	$("#hinweis").animate({"top":posY},800, "easeOutBounce");
}



function checkMandatories(formular){
		var fehler=false;
		$(formular).find(".mandatory").each(function(i){

			if($(this).attr("type")=="checkbox"){

				if($(this).attr("checked")== false && $(this).attr("disabled")==false){
					fehler=true;
					try {
						$(this).next().animate( { backgroundColor:"white", color:"#006bb3" }, { queue:true, duration:250 } );
						$(this).next().animate( { backgroundColor:"#ff0000", color:"white" }, { queue:true, duration:250 } );
						$(this).next().animate( { backgroundColor:"white", color:"#006bb3" }, { queue:true, duration:250 } );
						$(this).next().animate( { backgroundColor:"#ff0000", color:"white" }, { queue:true, duration:300 } );
					} catch(e){}
					show_hinweis("<b>Fehler:</b><br>Bitte überprüfe die Pflichtfelder.");
				} else {
					try {	
						$(this).next().animate( { backgroundColor:"transparent", color:"black" }, { queue:true, duration:250 } );
					} catch(e){}
				}
			} else {
				if($(this).val()=="" && $(this).attr("disabled")==false){
					fehler=true;
					try {
						$(this).animate( { backgroundColor:"white", color:"black" }, { queue:true, duration:250 } );
						$(this).animate( { backgroundColor:"#ff0000", color:"#006bb3" }, { queue:true, duration:250 } );
						$(this).animate( { backgroundColor:"white", color:"#006bb3" }, { queue:true, duration:250 } );
						$(this).animate( { backgroundColor:"#ff0000", color:"white" }, { queue:true, duration:300 } );
					} catch(e){}
				} else {
					try {
						$(this).animate( { backgroundColor:"white", color:"black" }, { queue:true, duration:500 } );
					} catch(e){}
				}
			}
		});
		return fehler;
}




function activateNavi(){
	
	
	$(".subnavi").mouseenter(function(){
		$(this).css("left",$(this).prev().position().left-2);
		$(this).children(".subnavi_items").height("auto");
		$(this).children(".subnavi_items").stop().slideDown(300);
	});
	
	$(".subnavi").mouseleave(function(){
		$(".subnavi_item_pic").stop().slideUp(300);
		$(this).children(".subnavi_items").stop().slideUp(300);
	});		
	
	$("#navi_main > .item").mouseenter(function(){
		$(this).next(".subnavi").css("left",$(this).position().left-2);
		$(this).next(".subnavi").children(".subnavi_items").height("auto");
		$(this).next(".subnavi").children(".subnavi_items").stop().slideDown(300);
	});
	

	$("#navi_main > .item").mouseleave(function(){
		$(".subnavi_item_pic").stop().slideUp(300);
		$(this).next(".subnavi").children(".subnavi_items").stop().slideUp(300);
	});		
	
	$(".subnavi_items").hide();
	$(".subnavi_item_pic").hide();
	$(".subnavi").each(function(){
		$(this).css("left",$(this).prev().position().left-2);
	});
	
	activateNaviItems();
}

function openNaviItems(){
		$(this).css("left",$(this).prev().position().left-2);
		$(this).children(".subnavi_items").height("auto");
		$(this).children(".subnavi_items").stop().slideDown(300);
}

function closeNaviItems(){
		$(".subnavi_item_pic").stop().slideUp(300);
		$(this).children(".subnavi_items").stop().slideUp(300);
}

function activateNaviItems(){
	$(".subnavi_item").mouseenter(function(){
		$(this).find("a").toggleClass("highlight");
		$(this).children(".subnavi_item_pic").attr("style","display:none");
		$(this).children(".subnavi_item_pic").stop(true).slideDown(300);
	});
	
	$(".subnavi_item").mouseleave(function(){
		$(this).find("a").toggleClass("highlight");
		$(this).children(".subnavi_item_pic").stop().slideUp(300, function(){
			$(this).attr("style","display:none");
		});
	});		
}

function reloadBackground(){
	if($(".body-background > img").attr("src") != undefined){
		waitforBGImage();
	} else {
		showContent();
	}
}


function sendScreen(async){
		if(async != false)async = true;
		$screen_width = $(window).width();
		$screen_height = $(window).height();
		$(".body-backgrounds").width($screen_width);
		$(".body-backgrounds").height($screen_height);	
		$(".body-background").width($screen_width);
		$(".body-background").height($screen_height);	
		
		var session_id = $("#session").val();
		$.ajax({
			async: async,
			type:	'POST',
			url: 	"lib/js_functions.php", 
			data:	{ 'function': 'setScreenSize', $session_name: $session_id, 'screen_width':$screen_width, 'screen_height':$screen_height},
			success: function(data){
				window.clearTimeout($idTimeoutBackground);
				$idTimeoutBackground = null;
				
				if($screen_width != $(window).width() || $screen_height != $(window).height())waitForResized();				
				
				if($idTimeoutBackground == null)$idTimeoutBackground = window.setTimeout("reloadBackground()", 500);
			},
		});		
		
}


var $session_id;
var $content;
var $id_typ;
var $id_utyp;
var $id_uutyp;
var $screen_width;
var $screen_height;
var $idTimeoutBackground;
var bgImageSrcOrg = new Array();

var bgImage = new Array();
var backgrounds_loaded=0;

function waitForResized(){
	$(window).unbind("resize");
	//alert($screen_width+" "+$(window).width());
	//alert($screen_height+" "+$(window).height());
	if($screen_width == $(window).width() && $screen_height == $(window).height())return;
	$("#main_content").hide();
	window.clearTimeout($idTimeoutBackground);
	$idTimeoutBackground = null;	
	if($idTimeoutBackground == null)$idTimeoutBackground = window.setTimeout("sendScreen()", 500);
}

function waitforBGImage(){
	
		jetzt = new Date();
		backgrounds_loaded = 0;
		for(i=0; i < bgImageSrcOrg.length; i++){
			var img = new Image();
			img.onload = showContent;
			img.src=bgImageSrcOrg[i]+"?"+jetzt.getTime();
			bgImage[i] = img;
			
		};
}


$(document).ready(function() {
	$("#main_content").hide();
	$('#features').css("bottom",-80);
	$(".body-background > img").each(function(){
		if($(this).attr("src") != undefined)bgImageSrcOrg[$(this).parent().prevAll().length] = $(this).attr("src");
	});
	
	$session_id = $("#session_id").val();
	$content = $("#content").val();
	$id_typ = $("#id_typ").val();
	$id_utyp = $("#id_utyp").val();
	$id_uutyp = $("#id_uutyp").val();
	sendScreen(false);
	$(window).resize(waitForResized);
	activateNavi();
	$('.rollover').hoverswap({});
	
	$('#features').delay(2500).animate({"bottom":0},450);
	
	
	
//  kontaktformular________________________________________________

	$("#kontaktformular").submit(function(){
		
		var fehler=checkMandatories(this);
		if(!fehler){

		} else {
			show_hinweis("<b>Fehler:</b><br>Bitte überprüfe die Pflichtfelder.");
			return false;
		}
		
		//
		
	});
//  kontaktformular ende___________________________________________	
	
	if($("#hinweis_text").text() != "")show_hinweis($("#hinweis_text").html());
	
}); 



