$(document).ready(function() {
	
	var isOpen = false;
	var isActive = "";

	
	///////////////////////////////////////////////////////
	// STANDARD EINTRAG FUNCTIONS                        //
	///////////////////////////////////////////////////////
	
	$(".eintrag").mouseover(function(){
						$(this).addClass("highlight");

	});
	
	$(".eintrag").mouseout(function(){
						$(this).removeClass("highlight");

	});
	
	$('.sideEintrag').click(function(event){
		//event.stopPropagation();
	})		
	
	$('.eintrag').click(function(event){
		
			//test
		
			
			var thisSide = $(this).children(".sideEintrag");
			var thisEintrag = $("#topnav");
			
			
								
			if (thisSide.is(':visible')==false){
					
					if(event.target.nodeName==('A')){
					return;
					}
					
					
					thisSide.position({
								"my": "left top",
								"at": "right bottom",
								"of": thisEintrag,
								"collision" : "none"	
							
					});
				
					
					if(isActive!=""){
					
					isActive.removeClass("activate");
					isActive.children(".sideEintrag").hide("blind", { direction: "horizontal" });
				}
					
					
					isActive=$(this);
					isOpen = true;
					$(this).addClass("activate");
					
					
					
					
					// browserweiche
					
					if (parseInt(jQuery.browser.version)==7  && $.browser.msie) {
						
						// for IE Only
					
						$("#mainbox").stop().animate({"margin-left": "-528px"}, 500, function() {

								thisSide.show("fast");
								thisSide.position({
										"my": "left top",
										"at": "right bottom",
										"of": thisEintrag,
										"collision" : "none"	

								});
						});
					} else{
					
					// for good browsers
					$("#mainbox").stop().animate({"margin-left": "0px"}, 500, function() {
						
							thisSide.show("fast");
							thisSide.position({
									"my": "left top",
									"at": "right bottom",
									"of": thisEintrag,
									"collision" : "none"	
								
							});
					});
					
				}
					
						
					
			} else {
				if(event.target.nodeName==('A')){
				return;
				}
				if(event.target.nodeName==('IMG')){
				return;
				}
		
				isOpen = false;
				isActive="";
				$(this).removeClass("activate");
				
				
				if (parseInt(jQuery.browser.version)==7  && $.browser.msie) {
				$("#mainbox").stop().animate({"margin-left": "-264px"}, 1000, function(){});
				} else {
					$("#mainbox").stop().animate({"margin-left": "264px"}, 1000, function(){});
				}
				
				
				
				
				thisSide.hide("blind", { direction: "horizontal" });
				
				
				
			}			
							
	});





	///////////////////////////////////////////////////////
	// LEISTUNGEN EINTRAG FUNCTIONS                      //
	///////////////////////////////////////////////////////


	$(".leistungenLink").mouseover(function(){
						$(this).addClass("highlightLink");

	});
	
	$(".leistungenLink").mouseout(function(){
						$(this).removeClass("highlightLink");

	});


	$('.leistungenLink').click(function(event){
			
			var thisSide = $(this).children(".sideEintrag");
			var thisEintrag = $(this);
			
			
								
			if (thisSide.is(':visible')==false){
				
					
					thisSide.position({
								"my": "left top",
								"at": "right top",
								"of": $(".eintragBackground"),
								"collision" : "none"	
							
					});
				
					
					if(isActive!=""){
					
					isActive.removeClass("activateLink");
					isActive.children(".sideEintrag").hide("blind", { direction: "horizontal" });
				}
					
					
					isActive=$(this);
					isOpen = true;
					$(this).addClass("activateLink");
					
					
					if (parseInt(jQuery.browser.version)==7  && $.browser.msie) {
						
						// for IE Only
					$("#mainbox").stop().animate({"margin-left": "-528px"}, 500, function() {
						
							thisSide.show("fast");
							thisSide.position({
									"my": "left top",
									"at": "right top",
									"of": $(".eintragBackground"),
									"collision" : "none"	
								
							});
							
							
					}); 
					
					} else{
						
						$("#mainbox").stop().animate({"margin-left": "0px"}, 500, function() {

								thisSide.show("fast");
								thisSide.position({
										"my": "left top",
										"at": "right top",
										"of": $(".eintragBackground"),
										"collision" : "none"	

								});


						});
					}
						
					
			} else {
				
		
				isOpen = false;
				isActive="";
				thisEintrag.removeClass("activateLink");
				
				if (parseInt(jQuery.browser.version)==7  && $.browser.msie) {
					
					// for IE Only
				$("#mainbox").stop().animate({"margin-left": "-264px"}, 1000, function(){});
				
				} else{
					$("#mainbox").stop().animate({"margin-left": "264px"}, 1000, function(){});
				}
				
				
				thisSide.hide("blind", { direction: "horizontal" });
				
				
				
			}			
							
	});






	///////////////////////////////////////////////////////
	// NETZWERK EINTRAG FUNCTIONS                        //
	///////////////////////////////////////////////////////


	$(".eintragNetzwerk").mouseover(function(){
						$(this).addClass("highlight");

	});
	
	$(".eintragNetzwerk").mouseout(function(){
						$(this).removeClass("highlight");

	});


	
	///////////////////////////////////////////////////////
	// FABRIKANTEN EINTRAG FUNCTIONS                     //
	///////////////////////////////////////////////////////
	
	$(".eintragFabrikanten").mouseover(function(){
						$(this).addClass("highlight");

	});
	
	$(".eintragFabrikanten").mouseout(function(){
						$(this).removeClass("highlight");

	});
	
		
	
	$('.eintragFabrikanten').click(function(event){
		
			//test
		
			
			var thisSide = $(this).children(".sideEintrag");
			var thisEintrag = $("#topnav");
			
			
								
			if (thisSide.is(':visible')==false){
				
					
					thisSide.position({
								"my": "left top",
								"at": "right bottom",
								"of": thisEintrag,
								"collision" : "none"	
							
					});
				
					
					if(isActive!=""){
					
					isActive.removeClass("activate");
					isActive.children(".sideEintrag").hide("blind", { direction: "horizontal" });
				}
					
					
					isActive=$(this);
					isOpen = true;
					$(this).addClass("activate");
					
					
					
					
					// browserweiche
					
					if (parseInt(jQuery.browser.version)==7  && $.browser.msie) {
						
						// for IE Only
					
						$("#mainbox").stop().animate({"margin-left": "-528px"}, 500, function() {

								thisSide.show("fast");
								thisSide.position({
										"my": "left top",
										"at": "right bottom",
										"of": thisEintrag,
										"collision" : "none"	

								});
						});
					} else{
					
					// for good browsers
					$("#mainbox").stop().animate({"margin-left": "0px"}, 500, function() {
						
							thisSide.show("fast");
							thisSide.position({
									"my": "left top",
									"at": "right bottom",
									"of": thisEintrag,
									"collision" : "none"	
								
							});
					});
					
				}
					
						
					
			} else {
				if(event.target.nodeName==('A')){
				return;
				}
				
		
				isOpen = false;
				isActive="";
				$(this).removeClass("activate");
				
				
				if (parseInt(jQuery.browser.version)==7  && $.browser.msie) {
				$("#mainbox").stop().animate({"margin-left": "-264px"}, 1000, function(){});
				} else {
					$("#mainbox").stop().animate({"margin-left": "264px"}, 1000, function(){});
				}
				
				
				
				
				thisSide.hide("blind", { direction: "horizontal" });
				
				
				
			}			
							
	});

	



				

// ENDE DOCUMENT READY FUNCTION	
			
});




///////////////////////////////////////////////////////
// BACKGROUND FUNCTIONS                              //
///////////////////////////////////////////////////////


function getWindowHeight() {
	var windowHeight = 	$('#container').height();
	
	return windowHeight;
	};



function bgChange(newSrc){
	
	return; //neuwaerts version - no more backgrounds
	
	var agent=navigator.userAgent.toLowerCase();
	var is_iphone = (agent.indexOf('iphone')!=-1);
	var is_ipad = (agent.indexOf('ipad')!=-1);
	if (is_ipad) {
	
	// ipad version
	return;
	
	} 
	
	if (is_iphone){
	
	// iphone version	
		return;
	}
	
	else{
	
	// desktop version
	if($("#body-background1").is(':visible')==true && $('#theBackground1').attr('src') != newSrc){
		
		$('#theBackground2').attr('src', ''+newSrc).load(function(){});
		
		$('#body-background1').animate({ opacity: 'hide' }, 'normal');
		$('#body-background2').animate({ opacity: 'show' }, 'normal');
		
		$("#body-background2").ezBgResize();
	}
	
	else if($("#body-background2").is(':visible')==true && $('#theBackground2').attr('src') != newSrc){
							
		$('#theBackground1').attr('src', ''+newSrc).load(function(){});
		
		$('#body-background2').animate({ opacity: 'hide' }, 'normal');
		$('#body-background1').animate({ opacity: 'show' }, 'normal');
		
		$("#body-background1").ezBgResize();
	}
	}


}
	
	
	
	
	
	
// window load


$(window).load(function() {
		
	var agent=navigator.userAgent.toLowerCase();
	var is_iphone = (agent.indexOf('iphone')!=-1);
	var is_ipad = (agent.indexOf('ipad')!=-1);
	if (is_iphone) { 
		
		$("#body-background2").hide();
		$("#body-background1").hide();
		$("body").css('background', '#bbb5ac');
		
		
		
		
		} 
		
		
		else if(is_ipad){
			
			
			$("#body-background1").ezBgResize();
			$("#body-background2").hide();
			$("#body-background1").css("position","fixed");
			$("#body-background1").css("top","0px");
			$("#body-background1").css("left","0px");
			$("#body-background1").css("z-index","1");
			$("#body-background1").css("overflow","hidden");
			
		}
		
		else{
			
$("#body-background1").ezBgResize();
$("#body-background2").ezBgResize();
//$("#body-background2").hide();


$(window).bind("resize", function(){
    $("#body-background1").ezBgResize();
	$("#body-background2").ezBgResize();

});

}

});



function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
