// javascript DHMTL - funktionen
// author: alexander stier, cuti & stier gbr
// datum: 08.02.2008

		function validateKontakt(form){
				if (form.name.value == "") { alert("Bitte geben Sie Ihren Namen an !"); form.name.focus(); return false; }
				if (form.mail.value == "") { alert("Bitte geben Sie Ihre E-Mail-Adresse an !"); form.mail.focus(); return false; }
				if (form.mail.value.indexOf('@', 0) == -1 ||	form.mail.value.indexOf('.', 0) == -1) { alert("Bitte geben Sie ein gültige E-Mail-Adresse an !"); form.mail.focus(); return false; }
				return true;
		}
				
		var show_1 = "#block1";
		var show_2 = "#block2";
		var hide_1 = "#block3";
		var hide_2 = "#block4";
		var showsub = "";
		var layoutStyle = "";
		var activeMain = "home_00";
		var activeSub = "";
		var buttonClick;
	
		var changeActive = function(){
				if(document.getElementById(activeMain)) {
					if (activeMain.indexOf("home") > -1) {
						document.getElementById(activeMain).className = "homeButtonBlau";
					} else {
						document.getElementById(activeMain).className = "mainButtonBlau";
					}
				}
				if(document.getElementById(activeSub)) { document.getElementById(activeSub).className = "subButtonBlau"; }
	
				if (hide_1 == "#block1") { 
					show_1 = "#block3"; 
				} else { 
					show_1 = "#block1"; 
				}
				$(hide_1).animate( { left: ( document.body.offsetWidth ) + 20 }, { queue:true, duration:500 } );
				$(hide_1).fadeOut(0);
				
				if (hide_2 == "#block2") { 
					show_2 = "#block4";
				} else { 
					show_2 = "#block2";
				}
				$(hide_2).animate( { left: ( document.body.offsetWidth ) + 20 }, { queue:true, duration:500 } );
				$(hide_2).fadeOut(0);

				$(show_1).css("left", -920 );
				$(show_2).css("left", document.body.offsetWidth+16 );
				$("#menu").animate( { top: 570 }, { queue:true, duration:500 } );
		};
		
		var changeSub = function(id){
			active = activeSub.split("_");
			// alert("changeSub: "+id);
			if(id){
				activate = id.split("_");
				if (active[0] != activate[0]) {
					if (showsub == "#submenu1" || showsub == "") { 
						$("#submenu1").animate( { left: ( document.body.offsetWidth ) + 20 }, { duration:500 }  );
						$("#submenu2").css("left", -920 );
						$("#submenu2").load("/ajax/"+activate[0]+"_submenu.php",'',function(){
							$("button").click(buttonClick);
							if(document.getElementById(id)) { document.getElementById(id).className = "subButtonGelb"; }					
							$("#submenu2").animate( { left: ( document.body.offsetWidth/2 ) - 308 }, { queue:true, duration:1000 }  );
							showsub = "#submenu2";
						});
					} else if (showsub == "#submenu2") {
						$("#submenu2").animate( { left: ( document.body.offsetWidth ) + 20 }, { duration:500 }  );
						$("#submenu1").css("left", -920 );
						$("#submenu1").load("/ajax/"+activate[0]+"_submenu.php",'',function(){
							$("button").click(buttonClick);
							if(document.getElementById(id)) { document.getElementById(id).className = "subButtonGelb"; }					
							$("#submenu1").animate( { left: ( document.body.offsetWidth/2 ) - 308 }, { queue:true, duration:1000 }  );
							showsub = "#submenu1";
						});					
					}
				} else {
					if(document.getElementById(id)) { document.getElementById(id).className = "subButtonGelb"; }					
				}
				activeSub = id;
			} else {
				if(showsub){
					$(showsub).animate( { left: ( document.body.offsetWidth ) + 20 }, { queue:true, duration:500 }  );
					showsub = false;
				}
				activeSub = id;
			}
		};

		function resize(){
			$("#menu").css("left", (document.body.offsetWidth/2) - 350);
			$("#submenu1").css("right", (document.body.offsetWidth/2) - 308 );
			switch(layoutStyle) {
				case "single":	
												$(show_1).animate( { left: ( document.body.offsetWidth/2 ) - 402 } );
												break;
												
				case "double":	
												$(show_1).animate( { left: ( document.body.offsetWidth/2 ) - 468 } );
												$(show_2).animate( { left: ( document.body.offsetWidth/2 ) + 20 } );
												break;
			}
		}

		buttonClick = function(node) {

				if ($(this).attr('name')) {
					hash = $(this).attr('name');
				} else {
					hash = node;
				}
				
				hash = hash.replace(/^.*#/, '');
				// alert("buttonClick: "+hash);
				// moves to a new page. 
				// pageload is called at once. 
				$.history.load(hash);				
				return false;

		};


		// PageLoad function
		// This function is called when:
		// 1. after calling $.historyInit();
		// 2. after calling $.historyLoad();
		// 3. after pushing "Go Back" button of a browser
		function pageload(hash) {
			// hash doesn't contain the first # character.
			if(hash) {
				// restore ajax loaded state
				switch(hash) {
					case "portrait_00":			
																	if (activeMain != "portrait_00" || activeSub != "portrait_01") {
																		changeActive();
																		activeMain = "portrait_00";
																		document.title = 'cuti & stier gbr | Portrait'; 
																		$(show_1).show();
																		$(show_1).css("width",870);
																		$(show_1).load("/ajax/portrait_digital-business-agentur.php",'',function(){
																				$(show_1).animate( { left: ( document.body.offsetWidth/2 ) - 400 }, { queue:true, duration:1000 } );
																				changeSub("portrait_01");
																			});
						
																		layoutStyle = "single";
																		hide_1 = show_1;
																		hide_2 = show_2;
																	}
																	break;

					case "portrait_01":			
																	if (activeSub != "portrait_01") {
																		changeActive();
																		activeMain = "portrait_00";
																		document.title = 'cuti & stier gbr | Portrait'; 
																		$(show_1).show();
																		$(show_1).css("width",870);
																		$(show_1).load("/ajax/portrait_digital-business-agentur.php",'',function(){
																				$(show_1).animate( { left: ( document.body.offsetWidth/2 ) - 400 }, { queue:true, duration:1000 } );
																				changeSub("portrait_01");
																			});
						
																		layoutStyle = "single";
																		hide_1 = show_1;
																		hide_2 = show_2;
																	}
																	break;

					case "portrait_02":			if (activeSub != "portrait_02") {
																		changeActive();
																		activeMain = "portrait_00";
																		document.title = 'cuti & stier gbr | cuti & stier'; 
																		$(show_1).show();
																		$(show_1).css("width",450);
																		$(show_1).load("/ajax/portrait_mcuti.php",'',function() {
																				$(show_1).animate( { left: ( document.body.offsetWidth/2 ) - 468 }, { queue:true, duration:1000 } );
																			});
																		$(show_2).show();
																		$(show_2).css("width",450);
																		$(show_2).load("/ajax/portrait_astier.php",'',function() {
																				$(show_2).animate( { left: ( document.body.offsetWidth/2 ) + 20 }, { queue:true, duration:1000 } );	
																				changeSub("portrait_02");
																			});															

																		layoutStyle = "double";
																		hide_1 = show_1;
																		hide_2 = show_2;
																	}
																	break;
													
					case "portfolio_00":		if (activeMain != "portfolio_00" || activeSub != "portfolio_01") {
																		changeActive();
																		activeMain = "portfolio_00";
																		document.title = 'cuti & stier gbr | Portfolio › Web-Programmierung'; 
																		$(show_1).show();
																		$(show_1).css("width",870);
																		$(show_1).load("/ajax/portfolio_web-programmierung.php",'',function() {
																				$(show_1).animate( { left: ( document.body.offsetWidth/2 ) - 400 }, { queue:true, duration:1000 } );	
																				changeSub("portfolio_01");
																			});
						
																		layoutStyle = "single";
																		hide_1 = show_1;
																		hide_2 = show_2;
																	}
																	break;


					case "portfolio_01":		if (activeSub != "portfolio_01") {
																		changeActive();
																		activeMain = "portfolio_00";
																		document.title = 'cuti & stier gbr | Portfolio › Web-Programmierung'; 
																		$(show_1).show();
																		$(show_1).css("width",870);
																		$(show_1).load("/ajax/portfolio_web-programmierung.php",'',function() {
																				$(show_1).animate( { left: ( document.body.offsetWidth/2 ) - 400 }, { queue:true, duration:1000 } );
																				changeSub("portfolio_01");
																			});
						
																		layoutStyle = "single";
																		hide_1 = show_1;
																		hide_2 = show_2;
																	}
																	break;

					case "portfolio_02":		if (activeSub != "portfolio_02") {
																		changeActive();
																		activeMain = "portfolio_00";
																		document.title = 'cuti & stier gbr | Portfolio › Intranet-Applikations-Entwicklung'; 
																		$(show_1).show();
																		$(show_1).css("width",870);
																		$(show_1).load("/ajax/portfolio_intranet-applikations-entwicklung.php",'',function() {
																				$(show_1).animate( { left: ( document.body.offsetWidth/2 ) - 400 }, { queue:true, duration:1000 } );	
																				changeSub("portfolio_02");
																			});
						
																		layoutStyle = "single";
																		hide_1 = show_1;
																		hide_2 = show_2;
																	}
																	break;

					case "portfolio_03":		if (activeSub != "portfolio_03") {
																		changeActive();
																		activeMain = "portfolio_00";
																		document.title = 'cuti & stier gbr | Portfolio › CMS-Typo3'; 
																		$(show_1).show();
																		$(show_1).css("width",870);
																		$(show_1).load("/ajax/portfolio_cms-typo3.php",'',function() {
																				$(show_1).animate( { left: ( document.body.offsetWidth/2 ) - 400 }, { queue:true, duration:1000 } );	
																				changeSub("portfolio_03");
																			});
						
																		layoutStyle = "single";
																		hide_1 = show_1;
																		hide_2 = show_2;
																	}
																	break;

					case "portfolio_04":		if (activeSub != "portfolio_04") {
																		changeActive();
																		activeMain = "portfolio_00";
																		document.title = 'cuti & stier gbr | Portfolio › Service-Hosting-Kommunikation'; 
																		$(show_1).show();
																		$(show_1).css("width",870);
																		$(show_1).load("/ajax/portfolio_service-hosting-kommunikation.php",'',function() {
																				$(show_1).animate( { left: ( document.body.offsetWidth/2 ) - 400 }, { queue:true, duration:1000 } );	
																				changeSub("portfolio_04");
																			});
						
																		layoutStyle = "single";
																		hide_1 = show_1;
																		hide_2 = show_2;
																	}
																	break;

					case "referenzen_00":		if (activeMain != "referenzen_00") {
																		changeActive();
																		activeMain = "referenzen_00";
																		document.title = 'cuti & stier gbr | Referenzen'; 
																		$(show_1).show();
																		$(show_1).css("width",870);
																		$(show_1).load("/ajax/referenzen.php",'',function() {
																				$(show_1).animate( { left: ( document.body.offsetWidth/2 ) - 400 }, { queue:true, duration:1000 } );	
																				changeSub("");
																				activeSub = "";
																				tb_init('#scene a.thickbox, #scene area.thickbox, #scene input.thickbox');
																			});
						
																		layoutStyle = "single";
																		hide_1 = show_1;
																		hide_2 = show_2;
																	}
																	break;
													
					case "kontakt_00":			if (activeMain != "kontakt_00") {
																		changeActive();
																		activeMain = "kontakt_00";
																		document.title = 'cuti & stier gbr | Kontakt'; 
																		$(show_1).show();
																		$(show_1).css("width",870);
																		$(show_1).load("/ajax/kontakt.php",'',function() {
																				$(show_1).animate( { left: ( document.body.offsetWidth/2 ) - 400 }, { queue:true, duration:1000 } );	
																				changeSub();
																				activeSub = "";
																				if(document.getElementById(activeSub)) { document.getElementById(activeSub).className = "subButtonGelb"; }
																			});
						
																		layoutStyle = "single";
																		hide_1 = show_1;
																		hide_2 = show_2;
																	}
																	break;
					case "kontakt_01":			if (activeMain != "kontakt_01") {
																		changeActive();
																		activeMain = "kontakt_00";
																		document.title = 'cuti & stier gbr | Kontakt'; 
																		$(show_1).show();
																		$(show_1).css("width",870);
																		$(show_1).load("/ajax/senden.php",'',function() {
																				$(show_1).animate( { left: ( document.body.offsetWidth/2 ) - 400 }, { queue:true, duration:1000 } );	
																				changeSub();
																				activeSub = "";
																				if(document.getElementById(activeSub)) { document.getElementById(activeSub).className = "subButtonGelb"; }
																			});
						
																		layoutStyle = "single";
																		hide_1 = show_1;
																		hide_2 = show_2;
																	}
																	break;
				
					case "home_00":					if (activeMain != "home_00") {
																		changeActive();
																		activeMain = "home_00";
																		document.title = 'cuti & stier gbr | digital-business-agentur'; 
																		$("#menu").animate( { top: 500 }, { queue:true, duration:500 } );
																		changeSub();
																		activeSub = "";
																		if(document.getElementById(activeSub)) { document.getElementById(activeSub).className = "subButtonGelb"; }
																		hide_1 = show_1;
																		hide_2 = show_2;
																	}
																	break;
																					
				}

			} else {

				// start page
				if (activeMain != "home_00") {
					changeActive();
					activeMain = "home_00";
					document.title = 'cuti & stier gbr | digital-business-agentur'; 
					$("#menu").animate( { top: 500 }, { queue:true, duration:500 } );
					changeSub();
					activeSub = "";
					if(document.getElementById(activeSub)) { document.getElementById(activeSub).className = "subButtonGelb"; }
					hide_1 = show_1;
					hide_2 = show_2;
				}
			}

			if(document.getElementById(activeMain)) {
				if (activeMain.indexOf("home") > -1) {
					document.getElementById(activeMain).className = "homeButtonGelb";
				} else {
					document.getElementById(activeMain).className = "mainButtonGelb";
				}
			}

		}

		$(document).ready(function(){	
			$.history.init(pageload);
			// Button Listener
			$("button").click(buttonClick);
			// Browser-Resize function
			resize();		
		});


