function relativeTime(pastTime)
{
	// Generate a JavaScript relative time for the tweets

	var origStamp = Date.parse(pastTime);
	var curDate = new Date();
	var currentStamp = curDate.getTime();
	var difference = parseInt((currentStamp - origStamp)/1000);

	if(difference < 0) return false;

	if(difference <= 5)			return "gerade eben";
	if(difference <= 20)			return "vor ein paar Sekunden";
	if(difference <= 60)			return "Vor einer Minute";
	if(difference < 3600)		return "Vor "+parseInt(difference/60)+" Minuten";
	if(difference <= 1.5*3600) 	return "In der letzten Stunde";
	if(difference < 23.5*3600)	return "Vor "+Math.round(difference/3600)+" Stunden";
	if(difference < 1.5*24*3600)	return "Gestern";

	// If the tweet is older than a day, show an absolute date/time value;

	var dateArr = pastTime.split(' ');

	return dateArr[4].replace(/\:\d+$/,'')+' '+dateArr[2]+' '+dateArr[1]+
	(dateArr[3]!=curDate.getFullYear()?' '+dateArr[3]:'');
}

var deviceAgent = navigator.userAgent.toLowerCase();
var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
 
	
$(document).ready(function(){

	var target_offset = $("#links").offset();
	var target_top = target_offset.top;	
	$("#links a").click(function(){
		if($("#layerarbeit")){$("#layerarbeit").detach()}
		h=$(this).attr("href").split("#");
		ziel="#"+h[1];
		n=$(ziel).position();
		$("#links li").removeClass("blau_c")
		$(this).addClass("blau_c")
		$("html,body").animate({scrollTop:n.top}, { queue:false, duration:800, easing:"backEaseOut"});
		if (agentID) {
			$("#links").animate({top:n.top+80}, { queue:false, duration:0, easing:"linear"});
		}
	});

	$("#unten a").click(function(){
		n=$("#aussen").position();
		if($("#layerarbeit")){$("#layerarbeit").detach()}
		$("html,body").animate({scrollTop:n.top}, { queue:false, duration:800, easing:"backEaseOut"});
			
		if (agentID) {
			$("#links").css("top",($(window).scrollTop()+80)+"px");
		}
	
	});
	
	$(".rollo").click(function(){
		if($("#layerarbeit")){$('#layerarbeit').detach();}
		$("#aussen").after("<div id='layerarbeit' style='display:none'></div>");
		var wo=$(this).attr("wo");
		n=$("#links").position();		
		var arbeit=$("#"+wo+" .rollanker").position();	
		if(agentID){
		
		$("#layerarbeit").css("top",$(window).scrollTop()+"px")
		}
		else{
		$("#layerarbeit").css("top",(n.top-80)+"px")
		}
		
		$("#layerarbeit").load(this.href,function(){
			$("#close img").click(function(){
				$("#layerarbeit").detach()
			})
		
			$("#layerarbeit").animate({height:1000},{ queue:false, duration:800, easing:"expoEaseOut"})
		});
		return false;
	
	});
$(".team1 .team a").click(function(){window.open($(this).attr("href"),"_blank");return false;})
	$("#leistungen .team1").hover(function(){$(this).addClass("hellblau");$(this).removeClass("beige")},function(){$(this).addClass("beige");$(this).removeClass("hellblau")})
	$("#leistungen .team1").click(function(){$(".rollo",this).click()})
	$("#arbeit .a_eintrag").hover(function(){$(this).addClass("hellblau");$(this).removeClass("beige")},function(){$(this).addClass("beige");$(this).removeClass("hellblau")})
	$("#arbeit .a_eintrag").click(function(){$(".rollo",this).click()})
	$("#agentur .team1").hover(function(){$(this).addClass("hellblau");$(this).removeClass("beige")},function(){if(!$(this).hasClass("offen")){$(this).addClass("beige");$(this).removeClass("hellblau")}})
	$("#home .zeile").hover(function(){$(this).addClass("hellblau");$(this).removeClass("beige")},function(){if(!$(this).hasClass("offen")){$(this).addClass("beige");$(this).removeClass("hellblau")}})
		
	$("#agentur .team1").click(function(){
		if($("#layerarbeit")){$("#layerarbeit").detach()}
		var was=$(".teama", this).attr("was");
		var weid=$(".teama",this).attr("weid");
		if($(this).hasClass("offen")){
			$(this).animate({height:"58px"},{ queue:false, duration:800, easing:"backEaseOut"});
			$("#tp2_"+weid).detach()
			$(".zu",this).detach();
			$("#tp_"+weid+" a").show()
			$(this).addClass("beige");
			$(this).removeClass("hellblau");
			$(this).removeClass("offen");
		}
		else{
			$(".teama",this).before("<div id='tp2_"+weid+"' class='t_position tp2'>"+$(".teama",this).text()+"</div>")
			$("#tp_"+weid+" a").hide()
			$(this).append("<a href='javascript:dummy()' class='zu'>Schließen</a>");				
			$(this).animate({height:"390px"},{ queue:false, duration:800, easing:"backEaseOut"});
			$(this).removeClass("beige");	
			$(this).addClass("hellblau");
			$(this).addClass("offen");
		}

		return false;
	});

	$("#home .zeile").click(function(){
		if($("#layerarbeit")){$("#layerarbeit").detach()}
		var was=$(".homea",this).attr("was");
		var weid=$(".homea",this).attr("weid");
		if($(this).hasClass("offen")){
			$(this).animate({height:"58px"},{ queue:false, duration:800, easing:"backEaseOut"});
			$(".homea",this).show();
			$(".zu",this).detach();
			$(this).addClass("beige");
			$(this).removeClass("hellblau");
			$(this).removeClass("offen");
			
		}
		else{
			var homeh=$("."+was+" .homeblanko").height()+100	
			$("."+was+" .wohin").after("<a href='javascript:dummy()' class='zu'>Schließen</a>");
			$("."+was).animate({height:homeh},{ queue:false, duration:800, easing:"backEaseOut"});
			$(this).removeClass("beige");
			$(this).addClass("hellblau");
			$(this).addClass("offen");
			$(".homea",this).hide();
			
				
		}

		return false;
			
	});

		
	if (agentID) {
		$(window).scroll(function () { 
	    	$("#links").css("top",($(window).scrollTop()+80)+"px");
    	});
		if(window.location.hash){
			n=$(window.location.hash).position();
			$("#links").animate({top:n.top+80}, { queue:false, duration:0, easing:"linear"});
		}

	}
	if(window.location.hash){
		n=window.location.hash.replace(/^#/,"#li")
		$("#links li").removeClass("blau_c")
		$(n).addClass("blau_c")
	}


	$(window).scroll(function(){
	     $("#rechts > div").each(function(){
			if($(this).position().top+$(this).height()-80>=$(window).scrollTop()){
				if(!$("#li"+$(this).attr("id")).hasClass("blau_c")){
					$("#links li").removeClass("blau_c")
					$("#li"+$(this).attr("id")).addClass("blau_c")
				}
				return false
			}
		})
	})

});
function dummy(){}

