var current = "index.html";

show = function(page){

	if(current != page){
		
		current = page;
		
		if(page == "referenzen.html") showReferenzen(page);
        	
		else if(page == "impressum.html")  showImpressum(page);
			
		else if(page == "index.html") showIndex(page);
			
		else if(page == "kontakt.html") showKontakt(page);
			
		else showErrorPage("404.html");
		
	}
	else{

		$("#content").animate({
			opacity: "0"
		},'fast');


		$("#content").animate({
			opacity: "1"
		},'fast');

	}		
}

showReferenzen = function(file){

	$("#content").animate({
		marginLeft: "+=940"	
	},"slow");
	
	$("#content").queue(
		function(){
			$(this).css("margin-left","0");
			$(this).dequeue();			
			$(this).css("opacity","0");					
			$(this).dequeue();			
			$(this).load('contents/'+file,
				function(){
					Cufon.refresh();
					$(this).dequeue();	
					$(this).css("opacity","1");	
					$(this).dequeue();			
					$.getScript("js/box.js");						
					$(this).dequeue();				
				}
			);
			

	});	
}


showImpressum = function(file){
	
	$("#content").animate({
		marginLeft: "+=940"	
	},"slow");
	
	$("#content").queue(function(){
		$(this).css("opacity","0");	
		$(this).dequeue();		
		$(this).load('contents/'+file,
			function(){
				
			Cufon.refresh();
			$(this).dequeue();		
			$(this).css("margin-left","-940px");
			$(this).dequeue();		
			$(this).css("opacity","1");		
			$(this).dequeue();		
			$(this).animate({
				marginLeft: "+=940"
			},"slow");		
			$(this).dequeue();		
		
		});
			
	});	
}


showKontakt = function(file){
	
	$("#content").animate({
		marginLeft: "-=940"	
	},"slow");
	
	
	$("#content").queue(
		function(){
			$(this).css("opacity","0");
			$(this).dequeue();
			$(this).load('contents/'+file,			
				function(){
					Cufon.refresh();
					$(this).dequeue();			
					$(this).css("opacity","1");	
					$(this).dequeue();
					$(this).animate({
						marginLeft: "+=940"
					},"slow");		
					$(this).dequeue();				
			});
	})	
}


showIndex = function(file){
	
	$("#content").animate({
		marginLeft: "-=940"	
	},"slow");
	
	
	$("#content").queue(
		function(){
			$(this).css("opacity","0");
			$(this).dequeue();
			$(this).load('contents/'+file,
				function(){
					
					Cufon.refresh();
					$(this).dequeue();			
					$(this).css("opacity","1");	
					$(this).dequeue();
					$(this).animate({
						marginLeft: "+=940"
					},"slow");		
					$(this).dequeue();		
						$.getScript("js/startseite.js");						
					$(this).dequeue();
			});
			
	})	
	setStartseitenButtons();
}

showErrorPage = function(file){
	
	$("#content").animate({
		marginLeft: "-=940"	
	},"slow");
	
	
	$("#content").queue(
		function(){
			$(this).css("opacity","0");
			$(this).dequeue();
			$(this).load('contents/'+file,
				function(){
					Cufon.refresh();
					$(this).dequeue();			
					$(this).css("opacity","1");	
					$(this).dequeue();
					$(this).animate({
						marginLeft: "+=940"
					},"slow");		
					$(this).dequeue();		
						$.getScript("js/startseite.js");						
					$(this).dequeue();
			});
			
	})	
}




replaceMainLinks = function(){
	
	//Add a onclick function to all links that reference to "referenzen.php"	
	$("a[href='referenzen.php']").attr('onclick','').click(function(){show("referenzen.html")});		
	//Remove the refenzen
	$("a[href='referenzen.php']").attr('href','#');

	//Similar to first
	$("a[href='impressum.php']").attr('onclick','').click(function(){show("impressum.html")});		
	$("a[href='impressum.php']").attr('href','#');

	//Similar to first
	$("a[href='kontakt.php']").attr('onclick','').click(function(){show("kontakt.html")});		
	$("a[href='kontakt.php']").attr('href','#');

	//Similar to first
	$("a[href='index.php']").attr('onclick','').click(function(){show("index.html")});	
	$("a[href='index.php']").attr('href','#');	

}









setStartseitenButtons = function(){
	
	
	
	//Add a click function to the element with id reference
	$("#reference").click(
		function(){
			show('referenzen.html');
		}
	);	
	
	
	//Add an hover effect to the element with id reference and reference_button
	$("#reference").hover(
		function(){
			$("#reference_button").animate({			
					opacity: "0.5"
			},"slow")
			
			$("#reference_button").animate({			
						opacity: "1"				
			},"slow")				
		}
	);
	
	
	
	
	
	
	
	
	
	$("#kontakt").click(
		function(){
			show('kontakt.html');
		}
	);	
	
	$("#kontakt").hover(
		function(){
			$("#kontakt_button").animate({			
					opacity: "0.5"
			},"slow")
			
			$("#kontakt_button").animate({			
						opacity: "1"				
			},"slow")				
		}
	);
}
