﻿
// mikes super duper professional spam protection
function spamProtectionId(id) {
	var mail = $(id);
	var link = mail.text().replace(" [at] ", "&#64;");
	mail.html("<a href=\"mailto:" + link + "\">" + link + "</a>");
}

$(function() {

	var scrollAction = true;

	// call spam protection
	spamProtectionId("#mail");
	
	// qr-code & stnr
	$("#moreinfo").html("<img src=\"setup/qr-card.png\" /><br /><span style=\"font-size:smaller\">StNr: 63423/21618</span>");

	// navigation concept 1.0 (obsolete - replace it soon!)
	$('.page').hide();

	var arr = $.makeArray($(".page"));
	for(var i=0; i<arr.length; i++) {
		$(arr[i]).attr("id","jq" + $(arr[i]).attr("id"));
	}

	var firstHash = window.location.hash;
	firstHash = firstHash.substring(1);

	if(firstHash == '') {
		$(arr[0]).show();
	}
	else {
		$('#jq' + firstHash).show();
	}
	
	$('#header a').click(function() {

		$('#header a').removeClass("active-bottom active-top");
		if ($(this).attr("id") == "linkstart") {
			$(this).addClass("active-top");
		}
		else {
			$(this).addClass("active-bottom");
		}

		$(".page").slideUp();
		var href = $(this).attr('href'); // statt id :)
		$('#jq' + href.substring(1)).slideDown(function(){ 
			scrollAction = true 
		});
	});
	
	// trigger lonely contact link
	$('#clicktocontact').click(function(event) {
		event.preventDefault();
		$('#linkcontact').click();
	});

	// afterwards implemented fixed side navigation - it's bad :(
	var altNavigation = $("#altnav");
	
	$('#linkaltstart').click(function(event) {
		event.preventDefault();
		altNavigation.hide();
		scrollAction = false;		
		$('#linkstart').click();
	});

	$('#linkaltreferences').click(function(event) {
		event.preventDefault();
		altNavigation.fadeOut();
		scrollAction = false;		
		$('#linkreferences').click();
	});

	$('#linkaltcontact').click(function(event) {
		event.preventDefault();
		altNavigation.fadeOut();
		scrollAction = false;		
		$('#linkcontact').click();
	});	
	//*/
	
	// show/hide fixed side navigation dependent on scroll position
	$(window).scroll(function () {
		var pos = $(window).scrollTop();
		if (scrollAction) {
			if (pos > 150) {
				altNavigation.fadeIn();
			}
			else {
				altNavigation.fadeOut();
			}
		}
		//if(pos <= 0) { // > see slideDown....
		//	scrollAction = true;
		//}
	});
	
	// get qr infos 
	$("#moreinfo img").click(function() {
		$("#qrinfo").slideDown();
	});	
		
});


